Skip to content

Commit

Permalink
[GSCOLLECT-1654] Make sorted sets, bags, and maps implement Reversibl…
Browse files Browse the repository at this point in the history
…eIterable. Add OrderedMap interface to represent a linked hash map.

git-svn-id: svn+ssh://gscollections.svn.services.gs.com/svnroot/gscollections-svn/trunk@906 d5c9223b-1aff-41ac-aadd-f810b4a99ac4
  • Loading branch information
motlin committed Oct 6, 2015
1 parent ff40f82 commit a27c9f4
Show file tree
Hide file tree
Showing 32 changed files with 1,226 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,10 @@ <K, V> ImmutableMap<K, V> aggregateInPlaceBy(
ImmutableSortedSet<Pair<T, Integer>> zipWithIndex();

MutableSortedMap<T, Integer> toMapOfItemToCount();

ImmutableSortedBag<T> toReversed();

ImmutableSortedBag<T> take(int count);

ImmutableSortedBag<T> drop(int count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,10 @@ <K, V> MutableMap<K, V> aggregateInPlaceBy(
<S> MutableList<Pair<T, S>> zip(Iterable<S> that);

MutableSortedSet<Pair<T, Integer>> zipWithIndex();

MutableSortedBag<T> toReversed();

MutableSortedBag<T> take(int count);

MutableSortedBag<T> drop(int count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.gs.collections.api.map.MapIterable;
import com.gs.collections.api.map.sorted.SortedMapIterable;
import com.gs.collections.api.multimap.sortedbag.SortedBagMultimap;
import com.gs.collections.api.ordered.ReversibleIterable;
import com.gs.collections.api.ordered.SortedIterable;
import com.gs.collections.api.partition.bag.sorted.PartitionSortedBag;
import com.gs.collections.api.set.sorted.SortedSetIterable;
Expand All @@ -59,7 +60,7 @@
* @since 4.2
*/
public interface SortedBag<T>
extends Bag<T>, Comparable<SortedBag<T>>, SortedIterable<T>
extends Bag<T>, Comparable<SortedBag<T>>, SortedIterable<T>, ReversibleIterable<T>
{
SortedBag<T> selectByOccurrences(IntPredicate predicate);

Expand Down Expand Up @@ -166,4 +167,10 @@ <K, V> MapIterable<K, V> aggregateInPlaceBy(
Comparator<? super T> comparator();

SortedSetIterable<Pair<T, Integer>> zipWithIndex();

SortedBag<T> toReversed();

SortedBag<T> take(int count);

SortedBag<T> drop(int count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public interface ImmutableMapIterable<K, V> extends MapIterable<K, V>

ImmutableCollection<Pair<V, Integer>> zipWithIndex();

<KK, VV> ImmutableMap<KK, VV> aggregateInPlaceBy(Function<? super V, ? extends KK> groupBy, Function0<? extends VV> zeroValueFactory, Procedure2<? super VV, ? super V> mutatingAggregator);
<KK, VV> ImmutableMapIterable<KK, VV> aggregateInPlaceBy(Function<? super V, ? extends KK> groupBy, Function0<? extends VV> zeroValueFactory, Procedure2<? super VV, ? super V> mutatingAggregator);

<KK, VV> ImmutableMap<KK, VV> aggregateBy(Function<? super V, ? extends KK> groupBy, Function0<? extends VV> zeroValueFactory, Function2<? super VV, ? super V, ? extends VV> nonMutatingAggregator);
<KK, VV> ImmutableMapIterable<KK, VV> aggregateBy(Function<? super V, ? extends KK> groupBy, Function0<? extends VV> zeroValueFactory, Function2<? super VV, ? super V, ? extends VV> nonMutatingAggregator);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright 2015 Goldman Sachs.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.gs.collections.api.map;

import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function0;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.function.primitive.BooleanFunction;
import com.gs.collections.api.block.function.primitive.ByteFunction;
import com.gs.collections.api.block.function.primitive.CharFunction;
import com.gs.collections.api.block.function.primitive.DoubleFunction;
import com.gs.collections.api.block.function.primitive.FloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
import com.gs.collections.api.block.function.primitive.ShortFunction;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.list.ImmutableList;
import com.gs.collections.api.list.primitive.ImmutableBooleanList;
import com.gs.collections.api.list.primitive.ImmutableByteList;
import com.gs.collections.api.list.primitive.ImmutableCharList;
import com.gs.collections.api.list.primitive.ImmutableDoubleList;
import com.gs.collections.api.list.primitive.ImmutableFloatList;
import com.gs.collections.api.list.primitive.ImmutableIntList;
import com.gs.collections.api.list.primitive.ImmutableLongList;
import com.gs.collections.api.list.primitive.ImmutableShortList;
import com.gs.collections.api.multimap.list.ImmutableListMultimap;
import com.gs.collections.api.partition.list.PartitionImmutableList;
import com.gs.collections.api.tuple.Pair;

public interface ImmutableOrderedMap<K, V> extends OrderedMap<K, V>, ImmutableMapIterable<K, V>
{
ImmutableOrderedMap<K, V> tap(Procedure<? super V> procedure);

ImmutableOrderedMap<V, K> flipUniqueValues();

ImmutableListMultimap<V, K> flip();

ImmutableOrderedMap<K, V> select(Predicate2<? super K, ? super V> predicate);

ImmutableOrderedMap<K, V> reject(Predicate2<? super K, ? super V> predicate);

<K2, V2> ImmutableOrderedMap<K2, V2> collect(Function2<? super K, ? super V, Pair<K2, V2>> function);

<R> ImmutableOrderedMap<K, R> collectValues(Function2<? super K, ? super V, ? extends R> function);

ImmutableOrderedMap<K, V> toReversed();

ImmutableOrderedMap<K, V> take(int count);

ImmutableOrderedMap<K, V> takeWhile(Predicate<? super V> predicate);

ImmutableOrderedMap<K, V> drop(int count);

ImmutableOrderedMap<K, V> dropWhile(Predicate<? super V> predicate);

PartitionImmutableList<V> partitionWhile(Predicate<? super V> predicate);

ImmutableList<V> distinct();

ImmutableList<V> select(Predicate<? super V> predicate);

<P> ImmutableList<V> selectWith(Predicate2<? super V, ? super P> predicate, P parameter);

ImmutableList<V> reject(Predicate<? super V> predicate);

<P> ImmutableList<V> rejectWith(Predicate2<? super V, ? super P> predicate, P parameter);

PartitionImmutableList<V> partition(Predicate<? super V> predicate);

<P> PartitionImmutableList<V> partitionWith(Predicate2<? super V, ? super P> predicate, P parameter);

ImmutableBooleanList collectBoolean(BooleanFunction<? super V> booleanFunction);

ImmutableByteList collectByte(ByteFunction<? super V> byteFunction);

ImmutableCharList collectChar(CharFunction<? super V> charFunction);

ImmutableDoubleList collectDouble(DoubleFunction<? super V> doubleFunction);

ImmutableFloatList collectFloat(FloatFunction<? super V> floatFunction);

ImmutableIntList collectInt(IntFunction<? super V> intFunction);

ImmutableLongList collectLong(LongFunction<? super V> longFunction);

ImmutableShortList collectShort(ShortFunction<? super V> shortFunction);

<S> ImmutableList<Pair<V, S>> zip(Iterable<S> that);

ImmutableList<Pair<V, Integer>> zipWithIndex();

<P, V1> ImmutableList<V1> collectWith(Function2<? super V, ? super P, ? extends V1> function, P parameter);

<V1> ImmutableList<V1> collectIf(Predicate<? super V> predicate, Function<? super V, ? extends V1> function);

<S> ImmutableList<S> selectInstancesOf(Class<S> clazz);

<V1> ImmutableList<V1> flatCollect(Function<? super V, ? extends Iterable<V1>> function);

<V1> ImmutableListMultimap<V1, V> groupBy(Function<? super V, ? extends V1> function);

<V1> ImmutableListMultimap<V1, V> groupByEach(Function<? super V, ? extends Iterable<V1>> function);

<V1> ImmutableOrderedMap<V1, V> groupByUniqueKey(Function<? super V, ? extends V1> function);

<KK, VV> ImmutableOrderedMap<KK, VV> aggregateInPlaceBy(Function<? super V, ? extends KK> groupBy, Function0<? extends VV> zeroValueFactory, Procedure2<? super VV, ? super V> mutatingAggregator);

<KK, VV> ImmutableOrderedMap<KK, VV> aggregateBy(Function<? super V, ? extends KK> groupBy, Function0<? extends VV> zeroValueFactory, Function2<? super VV, ? super V, ? extends VV> nonMutatingAggregator);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright 2015 Goldman Sachs.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.gs.collections.api.map;

import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function0;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.function.primitive.BooleanFunction;
import com.gs.collections.api.block.function.primitive.ByteFunction;
import com.gs.collections.api.block.function.primitive.CharFunction;
import com.gs.collections.api.block.function.primitive.DoubleFunction;
import com.gs.collections.api.block.function.primitive.FloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
import com.gs.collections.api.block.function.primitive.ShortFunction;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.list.primitive.MutableBooleanList;
import com.gs.collections.api.list.primitive.MutableByteList;
import com.gs.collections.api.list.primitive.MutableCharList;
import com.gs.collections.api.list.primitive.MutableDoubleList;
import com.gs.collections.api.list.primitive.MutableFloatList;
import com.gs.collections.api.list.primitive.MutableIntList;
import com.gs.collections.api.list.primitive.MutableLongList;
import com.gs.collections.api.list.primitive.MutableShortList;
import com.gs.collections.api.multimap.list.MutableListMultimap;
import com.gs.collections.api.partition.list.PartitionMutableList;
import com.gs.collections.api.tuple.Pair;

public interface MutableOrderedMap<K, V> extends OrderedMap<K, V>, MutableMapIterable<K, V>
{
MutableOrderedMap<K, V> tap(Procedure<? super V> procedure);

MutableOrderedMap<V, K> flipUniqueValues();

MutableListMultimap<V, K> flip();

MutableOrderedMap<K, V> select(Predicate2<? super K, ? super V> predicate);

MutableOrderedMap<K, V> reject(Predicate2<? super K, ? super V> predicate);

<K2, V2> MutableOrderedMap<K2, V2> collect(Function2<? super K, ? super V, Pair<K2, V2>> function);

<R> MutableOrderedMap<K, R> collectValues(Function2<? super K, ? super V, ? extends R> function);

MutableOrderedMap<K, V> toReversed();

MutableOrderedMap<K, V> take(int count);

MutableOrderedMap<K, V> takeWhile(Predicate<? super V> predicate);

MutableOrderedMap<K, V> drop(int count);

MutableOrderedMap<K, V> dropWhile(Predicate<? super V> predicate);

PartitionMutableList<V> partitionWhile(Predicate<? super V> predicate);

MutableList<V> distinct();

MutableList<V> select(Predicate<? super V> predicate);

<P> MutableList<V> selectWith(Predicate2<? super V, ? super P> predicate, P parameter);

MutableList<V> reject(Predicate<? super V> predicate);

<P> MutableList<V> rejectWith(Predicate2<? super V, ? super P> predicate, P parameter);

PartitionMutableList<V> partition(Predicate<? super V> predicate);

<P> PartitionMutableList<V> partitionWith(Predicate2<? super V, ? super P> predicate, P parameter);

MutableBooleanList collectBoolean(BooleanFunction<? super V> booleanFunction);

MutableByteList collectByte(ByteFunction<? super V> byteFunction);

MutableCharList collectChar(CharFunction<? super V> charFunction);

MutableDoubleList collectDouble(DoubleFunction<? super V> doubleFunction);

MutableFloatList collectFloat(FloatFunction<? super V> floatFunction);

MutableIntList collectInt(IntFunction<? super V> intFunction);

MutableLongList collectLong(LongFunction<? super V> longFunction);

MutableShortList collectShort(ShortFunction<? super V> shortFunction);

<S> MutableList<Pair<V, S>> zip(Iterable<S> that);

MutableList<Pair<V, Integer>> zipWithIndex();

<P, V1> MutableList<V1> collectWith(Function2<? super V, ? super P, ? extends V1> function, P parameter);

<V1> MutableList<V1> collectIf(Predicate<? super V> predicate, Function<? super V, ? extends V1> function);

<S> MutableList<S> selectInstancesOf(Class<S> clazz);

<V1> MutableList<V1> flatCollect(Function<? super V, ? extends Iterable<V1>> function);

<V1> MutableListMultimap<V1, V> groupBy(Function<? super V, ? extends V1> function);

<V1> MutableListMultimap<V1, V> groupByEach(Function<? super V, ? extends Iterable<V1>> function);

<V1> MutableOrderedMap<V1, V> groupByUniqueKey(Function<? super V, ? extends V1> function);

<KK, VV> MutableOrderedMap<KK, VV> aggregateInPlaceBy(Function<? super V, ? extends KK> groupBy, Function0<? extends VV> zeroValueFactory, Procedure2<? super VV, ? super V> mutatingAggregator);

<KK, VV> MutableOrderedMap<KK, VV> aggregateBy(Function<? super V, ? extends KK> groupBy, Function0<? extends VV> zeroValueFactory, Function2<? super VV, ? super V, ? extends VV> nonMutatingAggregator);
}
Loading

0 comments on commit a27c9f4

Please sign in to comment.