protected final boolean isMutable() { return !isImmutable() && !isReadOnly(); }
protected final boolean isMutable() { return !isImmutable() && !isReadOnly(); }
@Override public C.Set<T> onlyIn(Collection<? extends T> col) { C.Set<T> others = C.newSet(col); others.removeAll(this); if (isImmutable()) { return ImmutableSet.of(others); } return others; }
@Override public C.Set<T> withIn(Collection<? extends T> col) { C.Set<T> others = C.newSet(col); others.retainAll(this); if (isImmutable()) { return ImmutableSet.of(others); } return others; }
@Override public C.Set<T> without(Collection<? super T> col) { C.Set<T> copy = C.newSet(this); copy.removeAll(col); if (isImmutable()) { return ImmutableSet.of(copy); } return copy; }
@Override public C.Set<T> with(Collection<? extends T> col) { C.Set<T> copy = C.newSet(this); copy.addAll(col); if (isImmutable()) { return ImmutableSet.of(copy); } return copy; }
@Override public C.Set<T> onlyIn(Collection<? extends T> col) { C.Set<T> others = C.newSet(col); others.removeAll(this); if (isImmutable()) { return ImmutableSet.of(others); } return others; }
@Override public C.Set<T> without(Collection<? super T> col) { C.Set<T> copy = C.newSet(this); copy.removeAll(col); if (isImmutable()) { return ImmutableSet.of(copy); } return copy; }
@Override public C.Set<T> with(Collection<? extends T> col) { C.Set<T> copy = C.newSet(this); copy.addAll(col); if (isImmutable()) { return ImmutableSet.of(copy); } return copy; }
@Override public C.Set<T> withIn(Collection<? extends T> col) { C.Set<T> others = C.newSet(col); others.retainAll(this); if (isImmutable()) { return ImmutableSet.of(others); } return others; }
@Override public <R> C.Traversable<R> map($.Function<? super T, ? extends R> mapper) { boolean immutable = isImmutable(); int sz = size(); if (immutable) { if (0 == sz) { return Nil.set(); } ListBuilder<R> lb = new ListBuilder<>(sz); forEach($.visitor($.f1(mapper).andThen(C.F.addTo(lb)))); return lb.toList(); } else { if (0 == sz) { return C.newSet(); } C.List<R> l = C.newSizedList(sz); forEach($.visitor($.f1(mapper).andThen(C.F.addTo(l)))); return l; } }
@Override public <R> C.Traversable<R> map($.Function<? super T, ? extends R> mapper) { boolean immutable = isImmutable(); int sz = size(); if (immutable) { if (0 == sz) { return Nil.set(); } ListBuilder<R> lb = new ListBuilder<>(sz); forEach($.visitor($.f1(mapper).andThen(C.F.addTo(lb)))); return lb.toList(); } else { if (0 == sz) { return C.newSet(); } C.List<R> l = C.newSizedList(sz); forEach($.visitor($.f1(mapper).andThen(C.F.addTo(l)))); return l; } }
@Override public C.Set<T> filter($.Function<? super T, Boolean> predicate) { boolean immutable = isImmutable(); int sz = size(); // TODO: handle lazy filter if (immutable) { if (0 == sz) { return Nil.set(); } ListBuilder<T> lb = new ListBuilder<T>(sz); forEach($.visitor($.predicate(predicate).ifThen(C.F.addTo(lb)))); return lb.toSet(); } else { if (0 == sz) { return C.newSet(); } C.Set<T> set = C.newSet(); forEach($.visitor($.predicate(predicate).ifThen(C.F.addTo(set)))); return set; } }
@Override public C.Set<T> filter($.Function<? super T, Boolean> predicate) { boolean immutable = isImmutable(); int sz = size(); // TODO: handle lazy filter if (immutable) { if (0 == sz) { return Nil.set(); } ListBuilder<T> lb = new ListBuilder<T>(sz); forEach($.visitor($.predicate(predicate).ifThen(C.F.addTo(lb)))); return lb.toSet(); } else { if (0 == sz) { return C.newSet(); } C.Set<T> set = C.newSet(); forEach($.visitor($.predicate(predicate).ifThen(C.F.addTo(set)))); return set; } }