Here you can find the source of mergeOperations(List
Parameter | Description |
---|---|
list1 | a parameter |
ops2 | a parameter |
public static <T> void mergeOperations(List<Set<T>> list1, Set<T> ops2)
//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); } }