Esempio n. 1
0
 /**
  * Inserts a value into the set, unless it is already present.
  *
  * <p>This function returns the existing value, if present. k
  *
  * @param obj Object to insert or retrieve
  * @return Existing object if already present, or the new object.
  */
 public E addOrGet(E k) {
   if (k == null) {
     return null;
   }
   // Careful, this is VERSION-DEPENDANT on fastutil, unfortunately.
   int pos;
   E curr;
   final E[] key = this.key;
   if (!((curr = key[pos = (HashCommon.mix((k).hashCode())) & mask]) == null)) {
     if (curr.equals(k)) {
       return curr;
     }
     while (!((curr = key[pos = (pos + 1) & mask]) == null)) {
       if (curr.equals(k)) {
         return curr;
       }
     }
   }
   key[pos] = k;
   if (size++ >= maxFill) {
     rehash(HashCommon.arraySize(size + 1, f));
   }
   return k;
 }