Java Code Examples for java.util.SortedSet#retainAll()
The following examples show how to use
java.util.SortedSet#retainAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SortedSetRelation.java From fitnotifications with Apache License 2.0 | 4 votes |
/** * 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"); } }
Example 2
Source File: SortedSetRelation.java From trekarta with GNU General Public License v3.0 | 4 votes |
/** * 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"); } }
Example 3
Source File: SortedSetRelation.java From j2objc with Apache License 2.0 | 4 votes |
/** * 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"); } }