@Override public MutableSet<T> clone() { return UnifiedSet.newSet(this.delegate); }
public static <T> MutableSet<MutableSet<T>> powerSet(Set<T> set) { MutableSet<MutableSet<T>> seed = UnifiedSet.newSetWith(UnifiedSet.newSet()); return powerSetWithSeed(set, seed); }
@Override protected MutableSet<V> createCollection() { return new UnifiedSet<>(); }
private void addIfFound(T key, UnifiedSet<T> other) { int index = this.index(key); Object cur = this.table[index]; if (cur == null) { return; } if (cur instanceof ChainedBucket) { this.addIfFoundFromChain((ChainedBucket) cur, key, other); return; } if (this.nonNullTableObjectEquals(cur, key)) { other.add(this.nonSentinel(cur)); } }
protected boolean copySet(UnifiedSet<?> unifiedset) { //todo: optimize for current size == 0 boolean changed = false; for (int i = 0; i < unifiedset.table.length; i++) { Object cur = unifiedset.table[i]; if (cur instanceof ChainedBucket) { changed |= this.copyChain((ChainedBucket) cur); } else if (cur != null) { changed |= this.add(this.nonSentinel(cur)); } } return changed; }
private boolean copyChain(ChainedBucket bucket) { boolean changed = false; do { changed |= this.add(this.nonSentinel(bucket.zero)); if (bucket.one == null) { return changed; } changed |= this.add(this.nonSentinel(bucket.one)); if (bucket.two == null) { return changed; } changed |= this.add(this.nonSentinel(bucket.two)); if (bucket.three == null) { return changed; } if (bucket.three instanceof ChainedBucket) { bucket = (ChainedBucket) bucket.three; continue; } changed |= this.add(this.nonSentinel(bucket.three)); return changed; } while (true); }
@Override public <V> ImmutableSet<V> collect(IntToObjectFunction<? extends V> function) { return UnifiedSet.<V>newSetWith(function.valueOf(this.element)).toImmutable(); }
@Override public <T> MutableSet<T> with(T... items) { return UnifiedSet.newSetWith(items); }
@Override public <V> MutableSet<V> collect(BooleanToObjectFunction<? extends V> function) { UnifiedSet<V> target = UnifiedSet.newSet(this.size()); switch (this.state) { case 0: return target; case 1: return target.with(function.valueOf(false)); case 2: return target.with(function.valueOf(true)); case 3: target.add(function.valueOf(false)); target.add(function.valueOf(true)); return target; default: throw new AssertionError("Invalid state"); } }
@Override public ImmutableSet<Pair<V, Integer>> zipWithIndex() { return this.zipWithIndex(UnifiedSet.<Pair<V, Integer>>newSet()).toImmutable(); }
private boolean isActionContains(String command) { return this.actions != null && UnifiedSet.newSetWith(this.actions).collect(StringFunctions.toLowerCase()).contains(command); }
@Override public boolean addAllIterable(Iterable<? extends T> iterable) { if (iterable instanceof UnifiedSet) { return this.copySet((UnifiedSet<?>) iterable); } int size = Iterate.sizeOf(iterable); this.ensureCapacity(size); int oldSize = this.size(); if (iterable instanceof List && iterable instanceof RandomAccess) { List<T> list = (List<T>) iterable; for (int i = 0; i < size; i++) { this.add(list.get(i)); } } else { Iterate.forEachWith(iterable, Procedures2.addToCollection(), this); } return this.size() != oldSize; }
if (this.nonNullTableObjectEquals(bucket.zero, key)) other.add(this.nonSentinel(bucket.zero)); return; if (this.nonNullTableObjectEquals(bucket.one, key)) other.add(this.nonSentinel(bucket.one)); return; if (this.nonNullTableObjectEquals(bucket.two, key)) other.add(this.nonSentinel(bucket.two)); return; continue; if (this.nonNullTableObjectEquals(bucket.three, key)) other.add(this.nonSentinel(bucket.three)); return;
this.allocate(newCapacity); this.occupied = 0; this.add(this.nonSentinel(bucket.zero)); this.add(this.nonSentinel(bucket.one)); if (bucket.two == null) this.add(this.nonSentinel(bucket.two)); if (bucket.three != null) continue; this.add(this.nonSentinel(bucket.three)); this.add(this.nonSentinel(oldKey));
@Override public UnifiedSet<T> with(T element) { this.add(element); return this; }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { int size = in.readInt(); this.loadFactor = in.readFloat(); this.init(Math.max((int) (size / this.loadFactor) + 1, DEFAULT_INITIAL_CAPACITY)); for (int i = 0; i < size; i++) { this.add((T) in.readObject()); } }
@Override public boolean contains(Object object) { return this.delegate.contains(object); }
public UnifiedSet<T> with(T... elements) { this.addAll(Arrays.asList(elements)); return this; }
@Override public <V> ImmutableSet<V> collect(CharToObjectFunction<? extends V> function) { return UnifiedSet.<V>newSetWith(function.valueOf(this.element)).toImmutable(); }
@Override public <T> MutableSet<T> with(T... items) { return UnifiedSet.newSetWith(items); }