Skip to content

Commit

Permalink
Close #822: Implement with(), without(), withAll(), withoutAll() as d…
Browse files Browse the repository at this point in the history
…efault methods

Signed-off-by: Mohammed Aboullaite <aboullaite.mohammed@gmail.com>
  • Loading branch information
aboullaite committed May 12, 2020
1 parent a7589cb commit 1adf6f4
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,32 @@ default MutableSet<T> selectUnique()
}

@Override
MutableBag<T> with(T element);
default MutableBag<T> with(T element)
{
this.add(element);
return this;
}

@Override
MutableBag<T> without(T element);
default MutableBag<T> without(T element)
{
this.remove(element);
return this;
}

@Override
MutableBag<T> withAll(Iterable<? extends T> elements);
default MutableBag<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
MutableBag<T> withoutAll(Iterable<? extends T> elements);
default MutableBag<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}

@Override
MutableBag<T> newEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,32 @@ default MutableBagIterable<T> selectDuplicates()
MutableList<ObjectIntPair<T>> bottomOccurrences(int count);

@Override
MutableBagIterable<T> with(T element);
default MutableBagIterable<T> with(T element)
{
this.add(element);
return this;
}

@Override
MutableBagIterable<T> without(T element);
default MutableBagIterable<T> without(T element)
{
this.remove(element);
return this;
}

@Override
MutableBagIterable<T> withAll(Iterable<? extends T> elements);
default MutableBagIterable<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
MutableBagIterable<T> withoutAll(Iterable<? extends T> elements);
default MutableBagIterable<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}

@Override
<V> RichIterable<V> collectWithOccurrences(ObjectIntToObjectFunction<? super T, ? extends V> function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,32 @@ default MutableSortedSet<T> selectUnique()
MutableSortedMap<T, Integer> toMapOfItemToCount();

@Override
MutableSortedBag<T> with(T element);
default MutableSortedBag<T> with(T element)
{
this.add(element);
return this;
}

@Override
MutableSortedBag<T> without(T element);
default MutableSortedBag<T> without(T element)
{
this.remove(element);
return this;
}

@Override
MutableSortedBag<T> withAll(Iterable<? extends T> elements);
default MutableSortedBag<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
MutableSortedBag<T> withoutAll(Iterable<? extends T> elements);
default MutableSortedBag<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}

@Override
MutableSortedBag<T> newEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
public interface FixedSizeList<T>
extends MutableList<T>, FixedSizeCollection<T>
{
@Override
MutableList<T> with(T element);

@Override
MutableList<T> without(T element);

@Override
MutableList<T> withAll(Iterable<? extends T> elements);

@Override
MutableList<T> withoutAll(Iterable<? extends T> elements);

@Override
FixedSizeList<T> toReversed();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,32 @@ public interface MutableList<T>
extends MutableCollection<T>, List<T>, Cloneable, ListIterable<T>
{
@Override
MutableList<T> with(T element);
default MutableList<T> with(T element)
{
this.add(element);
return this;
}

@Override
MutableList<T> without(T element);
default MutableList<T> without(T element)
{
this.remove(element);
return this;
}

@Override
MutableList<T> withAll(Iterable<? extends T> elements);
default MutableList<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
MutableList<T> withoutAll(Iterable<? extends T> elements);
default MutableList<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}

@Override
MutableList<T> newEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
public interface FixedSizeSet<T>
extends MutableSet<T>, FixedSizeCollection<T>
{
@Override
MutableSet<T> with(T element);

@Override
MutableSet<T> without(T element);

@Override
MutableSet<T> withAll(Iterable<? extends T> elements);

@Override
MutableSet<T> withoutAll(Iterable<? extends T> elements);

@Override
FixedSizeSet<T> tap(Procedure<? super T> procedure);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,32 @@ public interface MutableSet<T>
extends UnsortedSetIterable<T>, MutableSetIterable<T>, Cloneable
{
@Override
MutableSet<T> with(T element);
default MutableSet<T> with(T element)
{
this.add(element);
return this;
}

@Override
MutableSet<T> without(T element);
default MutableSet<T> without(T element)
{
this.remove(element);
return this;
}

@Override
MutableSet<T> withAll(Iterable<? extends T> elements);
default MutableSet<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
MutableSet<T> withoutAll(Iterable<? extends T> elements);
default MutableSet<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}

@Override
MutableSet<T> newEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,32 @@ public interface MutableSetIterable<T> extends SetIterable<T>, MutableCollection
@Override
@Deprecated
MutableSetIterable<Pair<T, Integer>> zipWithIndex();

@Override
default MutableSetIterable<T> with(T element)
{
this.add(element);
return this;
}

@Override
default MutableSetIterable<T> without(T element)
{
this.remove(element);
return this;
}

@Override
default MutableSetIterable<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
default MutableSetIterable<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,32 @@ public interface MutableSortedSet<T>
extends MutableSetIterable<T>, SortedSetIterable<T>, SortedSet<T>, Cloneable
{
@Override
MutableSortedSet<T> with(T element);
default MutableSortedSet<T> with(T element)
{
this.add(element);
return this;
}

@Override
MutableSortedSet<T> without(T element);
default MutableSortedSet<T> without(T element)
{
this.remove(element);
return this;
}

@Override
MutableSortedSet<T> withAll(Iterable<? extends T> elements);
default MutableSortedSet<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
MutableSortedSet<T> withoutAll(Iterable<? extends T> elements);
default MutableSortedSet<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}

@Override
MutableSortedSet<T> newEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,34 +481,6 @@ public <P> PartitionMutableBag<T> partitionWith(Predicate2<? super T, ? super P>
}
}

@Override
public MutableBag<T> with(T element)
{
this.add(element);
return this;
}

@Override
public MutableBag<T> without(T element)
{
this.remove(element);
return this;
}

@Override
public MutableBag<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
public MutableBag<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}

@Override
public MutableMap<T, Integer> toMapOfItemToCount()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,34 +98,6 @@ protected MutableBag<T> getDelegate()
return (MutableBag<T>) super.getDelegate();
}

@Override
public MutableBag<T> with(T element)
{
this.add(element);
return this;
}

@Override
public MutableBag<T> without(T element)
{
this.remove(element);
return this;
}

@Override
public MutableBag<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
public MutableBag<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}

@Override
public MutableBag<T> newEmpty()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,6 @@ protected MutableSortedBag<T> getDelegate()
return (MutableSortedBag<T>) super.getDelegate();
}

@Override
public MutableSortedBag<T> with(T element)
{
this.add(element);
return this;
}

@Override
public MutableSortedBag<T> without(T element)
{
this.remove(element);
return this;
}

@Override
public MutableSortedBag<T> withAll(Iterable<? extends T> elements)
{
this.addAllIterable(elements);
return this;
}

@Override
public MutableSortedBag<T> withoutAll(Iterable<? extends T> elements)
{
this.removeAllIterable(elements);
return this;
}

@Override
public MutableSortedBag<T> newEmpty()
{
Expand Down
Loading

0 comments on commit 1adf6f4

Please sign in to comment.