code: 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");
          }
      }
docs: 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