Java List Merge mergeOperations(List> list1, Set ops2)

Here you can find the source of mergeOperations(List> list1, Set ops2)

Description

Only smallest disjoint sets are retained

License

Open Source License

Parameter

Parameter Description
list1 a parameter
ops2 a parameter

Declaration

public static <T> void mergeOperations(List<Set<T>> list1, Set<T> ops2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Main {
    /**/* w  w w. ja  v a2  s  .c o m*/
     * Only smallest disjoint sets are retained
     * 
     * @param list1
     * @param ops2
     */
    public static <T> void mergeOperations(List<Set<T>> list1, Set<T> ops2) {
        if (list1.size() == 0) {
            list1.add(ops2);
            return;
        }
        if (ops2 == null) {
            return;
        }
        Iterator<Set<T>> it = list1.iterator();
        while (it.hasNext()) {
            Set<T> ops1 = it.next();
            if (ops1 == null) {
                it.remove();
            } else if (contains(ops2, ops1)) {
                return;
            } else if (contains(ops1, ops2)) {
                it.remove();
            }
        }
        list1.add(ops2);
    }

    public static <T> boolean contains(Set<T> set1, Set<T> set2) {
        return set1.containsAll(set2);
    }
}

Related

  1. mergeLists(List baseList, List newItems)
  2. mergeLists(List copyTo, List copyFrom)
  3. mergeLists(List dest, List inserts)
  4. mergeLists(List listA, List listB, List listC)
  5. mergeLists(Object oldValue, Object newValue, Object newValue2)
  6. mergeOrdered( List base, List elems)
  7. mergepath(List pieces, String separator)
  8. mergerList(List sources, List targets)
  9. mergeSpeakerList(List speaker_list)