@Nullable public V addx(V val){
  A.notNull(val,"val");
  if (comp == null) {
    for (    V v : vals)     if (v.equals(val))     return v;
    vals.add(val);
    return null;
  }
  if (strict) {
    for (ListIterator<V> it=vals.listIterator(); it.hasNext(); ) {
      V v=it.next();
      if (v.equals(val))       return v;
      int c=comp.compare(v,val);
      if (c == 0)       throw new IllegalStateException("Inconsistent equals and compare methods.");
      if (c > 0) {
        it.previous();
        it.add(val);
        return null;
      }
    }
    vals.add(val);
    return null;
  }
  for (  V v : vals)   if (v.equals(val))   return v;
  for (ListIterator<V> it=vals.listIterator(); it.hasNext(); ) {
    V v=it.next();
    if (comp.compare(v,val) > 0) {
      do {
        v=it.previous();
      }
 while (comp.compare(v,val) == 0);
      it.add(val);
      return null;
    }
  }
  vals.add(val);
  return null;
}

@ Nullable public V addx ( V val ) { A . notNull ( val , "val" ) ; if ( comp == null ) { for ( V v : vals ) if ( v . equals ( val ) ) return v ; vals . add ( val ) ; return null ; } if ( strict ) { for ( ListIterator < V > it = vals . listIterator ( ) ; it . hasNext ( ) ; ) { V v = it . next ( ) ; if ( v . equals ( val ) ) return v ; int c = comp . compare ( v , val ) ; if ( c == 0 ) throw new IllegalStateException ( "Inconsistent equals and compare methods." ) ; if ( c > 0 ) { it . previous ( ) ; it . add ( val ) ; return null ; } } vals . add ( val ) ; return null ; } for ( V v : vals ) if ( v . equals ( val ) ) return v ; for ( ListIterator < V > it = vals . listIterator ( ) ; it . hasNext ( ) ; ) { V v = it . next ( ) ; if ( comp . compare ( v , val ) > 0 ) { do { v = it . previous ( ) ; } while ( comp . compare ( v , val ) == 0 ) ; it . add ( val ) ; return null ; } } vals . add ( val ) ; return null ; }
either adds a value to set or does nothing if value is already present .
