public void union(E element1,E element2){
  Set<E> set1=elementToSet.get(element1);
  if (set1 == null) {
    throw new IllegalArgumentException("element 1 is not associated with a disjoint set, call makeSet() first.");
  }
  Set<E> set2=elementToSet.get(element2);
  if (set2 == null) {
    throw new IllegalArgumentException("element 2 is not associated with a disjoint set, call makeSet() first.");
  }
  if (set1 != set2) {
    if (set1.size() < set2.size()) {
      set2.addAll(set1);
      for (      E element : set1) {
        disjointSets.remove(elementToSet.put(element,set2));
      }
    }
 else {
      set1.addAll(set2);
      for (      E element : set2) {
        disjointSets.remove(elementToSet.put(element,set1));
      }
    }
  }
}

public void union ( E element1 , E element2 ) { Set < E > set1 = elementToSet . get ( element1 ) ; if ( set1 == null ) { throw new IllegalArgumentException ( "element 1 is not associated with a disjoint set, call makeSet() first." ) ; } Set < E > set2 = elementToSet . get ( element2 ) ; if ( set2 == null ) { throw new IllegalArgumentException ( "element 2 is not associated with a disjoint set, call makeSet() first." ) ; } if ( set1 != set2 ) { if ( set1 . size ( ) < set2 . size ( ) ) { set2 . addAll ( set1 ) ; for ( E element : set1 ) { disjointSets . remove ( elementToSet . put ( element , set2 ) ) ; } } else { set1 . addAll ( set2 ) ; for ( E element : set2 ) { disjointSets . remove ( elementToSet . put ( element , set1 ) ) ; } } } }
union two disjoint sets together if the arguments currently belong to two different sets .
