本文整理匯總了Java中java.util.SortedSet.retainAll方法的典型用法代碼示例。如果您正苦於以下問題:Java SortedSet.retainAll方法的具體用法?Java SortedSet.retainAll怎麽用?Java SortedSet.retainAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.SortedSet
的用法示例。
在下文中一共展示了SortedSet.retainAll方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: retainAll
import java.util.SortedSet; //導入方法依賴的package包/類
@Override
public synchronized boolean retainAll(Collection<?> c) {
SortedSet<E> newSet = new TreeSet<E>(internalSet);
boolean changed = newSet.retainAll(c);
internalSet = newSet;
return changed;
}
示例2: doOperation
import java.util.SortedSet; //導入方法依賴的package包/類
/**
* Utility that could be on SortedSet. Allows faster implementation than
* what is in Java for doing addAll, removeAll, retainAll, (complementAll).
* @param a first set
* @param relation the relation filter, using ANY, CONTAINS, etc.
* @param b second set
* @return the new set
*/
public static <T extends Object & Comparable<? super T>> SortedSet<? extends T> doOperation(SortedSet<T> a, int relation, SortedSet<T> b) {
// TODO: optimize this as above
TreeSet<? extends T> temp;
switch (relation) {
case ADDALL:
a.addAll(b);
return a;
case A:
return a; // no action
case B:
a.clear();
a.addAll(b);
return a;
case REMOVEALL:
a.removeAll(b);
return a;
case RETAINALL:
a.retainAll(b);
return a;
// the following is the only case not really supported by Java
// although all could be optimized
case COMPLEMENTALL:
temp = new TreeSet<T>(b);
temp.removeAll(a);
a.removeAll(b);
a.addAll(temp);
return a;
case B_REMOVEALL:
temp = new TreeSet<T>(b);
temp.removeAll(a);
a.clear();
a.addAll(temp);
return a;
case NONE:
a.clear();
return a;
default:
throw new IllegalArgumentException("Relation " + relation + " out of range");
}
}