-
Notifications
You must be signed in to change notification settings - Fork 584
/
ImmutableSortedMap.java
208 lines (162 loc) · 7.72 KB
/
ImmutableSortedMap.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Copyright (c) 2018 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.api.map.sorted;
import java.util.SortedMap;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.primitive.BooleanFunction;
import org.eclipse.collections.api.block.function.primitive.ByteFunction;
import org.eclipse.collections.api.block.function.primitive.CharFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.ObjectIntToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.ShortFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.list.primitive.ImmutableBooleanList;
import org.eclipse.collections.api.list.primitive.ImmutableByteList;
import org.eclipse.collections.api.list.primitive.ImmutableCharList;
import org.eclipse.collections.api.list.primitive.ImmutableDoubleList;
import org.eclipse.collections.api.list.primitive.ImmutableFloatList;
import org.eclipse.collections.api.list.primitive.ImmutableIntList;
import org.eclipse.collections.api.list.primitive.ImmutableLongList;
import org.eclipse.collections.api.list.primitive.ImmutableShortList;
import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.ImmutableMapIterable;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.multimap.list.ImmutableListMultimap;
import org.eclipse.collections.api.multimap.sortedset.ImmutableSortedSetMultimap;
import org.eclipse.collections.api.partition.list.PartitionImmutableList;
import org.eclipse.collections.api.tuple.Pair;
/**
* An ImmutableSortedMap is different than a JCF SortedMap in that it has no mutating methods, but it shares
* the read-only protocol of a SortedMap.
*/
public interface ImmutableSortedMap<K, V>
extends SortedMapIterable<K, V>, ImmutableMapIterable<K, V>
{
@Override
SortedMap<K, V> castToMap();
SortedMap<K, V> castToSortedMap();
// TODO: Keys could be ordered
@Override
ImmutableSortedSetMultimap<V, K> flip();
@Override
ImmutableSortedMap<K, V> newWithKeyValue(K key, V value);
@Override
ImmutableSortedMap<K, V> newWithAllKeyValues(Iterable<? extends Pair<? extends K, ? extends V>> keyValues);
@Override
ImmutableSortedMap<K, V> newWithAllKeyValueArguments(Pair<? extends K, ? extends V>... keyValuePairs);
@Override
ImmutableSortedMap<K, V> newWithoutKey(K key);
@Override
ImmutableSortedMap<K, V> newWithoutAllKeys(Iterable<? extends K> keys);
MutableSortedMap<K, V> toSortedMap();
// TODO: When we have implementations of linked hash maps
// ImmutableOrderedMap<V, K> flipUniqueValues();
@Override
ImmutableSortedMap<K, V> select(Predicate2<? super K, ? super V> predicate);
@Override
ImmutableSortedMap<K, V> reject(Predicate2<? super K, ? super V> predicate);
@Override
ImmutableSortedMap<K, V> tap(Procedure<? super V> procedure);
@Override
ImmutableList<V> select(Predicate<? super V> predicate);
@Override
<P> ImmutableList<V> selectWith(Predicate2<? super V, ? super P> predicate, P parameter);
@Override
ImmutableList<V> reject(Predicate<? super V> predicate);
@Override
<P> ImmutableList<V> rejectWith(Predicate2<? super V, ? super P> predicate, P parameter);
@Override
<S> ImmutableList<S> selectInstancesOf(Class<S> clazz);
@Override
PartitionImmutableList<V> partition(Predicate<? super V> predicate);
@Override
<P> PartitionImmutableList<V> partitionWith(Predicate2<? super V, ? super P> predicate, P parameter);
@Override
<R> ImmutableList<R> collect(Function<? super V, ? extends R> function);
/**
* @since 9.1.
*/
@Override
default <R> ImmutableList<R> collectWithIndex(ObjectIntToObjectFunction<? super V, ? extends R> function)
{
int[] index = {0};
return this.collect(each -> function.valueOf(each, index[0]++));
}
@Override
<P, VV> ImmutableList<VV> collectWith(Function2<? super V, ? super P, ? extends VV> function, P parameter);
@Override
<K2, V2> ImmutableMap<K2, V2> collect(Function2<? super K, ? super V, Pair<K2, V2>> function);
@Override
<R> ImmutableSortedMap<K, R> collectValues(Function2<? super K, ? super V, ? extends R> function);
@Override
<R> ImmutableList<R> collectIf(
Predicate<? super V> predicate,
Function<? super V, ? extends R> function);
@Override
<R> ImmutableList<R> flatCollect(Function<? super V, ? extends Iterable<R>> function);
/**
* @since 9.2
*/
@Override
default <P, R> ImmutableList<R> flatCollectWith(Function2<? super V, ? super P, ? extends Iterable<R>> function, P parameter)
{
return this.flatCollect(each -> function.apply(each, parameter));
}
@Override
ImmutableBooleanList collectBoolean(BooleanFunction<? super V> booleanFunction);
@Override
ImmutableByteList collectByte(ByteFunction<? super V> byteFunction);
@Override
ImmutableCharList collectChar(CharFunction<? super V> charFunction);
@Override
ImmutableDoubleList collectDouble(DoubleFunction<? super V> doubleFunction);
@Override
ImmutableFloatList collectFloat(FloatFunction<? super V> floatFunction);
@Override
ImmutableIntList collectInt(IntFunction<? super V> intFunction);
@Override
ImmutableLongList collectLong(LongFunction<? super V> longFunction);
@Override
ImmutableShortList collectShort(ShortFunction<? super V> shortFunction);
@Override
<S> ImmutableList<Pair<V, S>> zip(Iterable<S> that);
@Override
ImmutableList<Pair<V, Integer>> zipWithIndex();
@Override
<VV> ImmutableListMultimap<VV, V> groupBy(Function<? super V, ? extends VV> function);
@Override
<VV> ImmutableListMultimap<VV, V> groupByEach(Function<? super V, ? extends Iterable<VV>> function);
@Override
default <VV> ImmutableMap<VV, V> groupByUniqueKey(Function<? super V, ? extends VV> function)
{
MutableMap<VV, V> target = Maps.mutable.withInitialCapacity(this.size());
return this.groupByUniqueKey(function, target).toImmutable();
}
@Override
<K2, V2> ImmutableMap<K2, V2> aggregateInPlaceBy(
Function<? super V, ? extends K2> groupBy,
Function0<? extends V2> zeroValueFactory,
Procedure2<? super V2, ? super V> mutatingAggregator);
@Override
<K2, V2> ImmutableMap<K2, V2> aggregateBy(
Function<? super V, ? extends K2> groupBy,
Function0<? extends V2> zeroValueFactory,
Function2<? super V2, ? super V, ? extends V2> nonMutatingAggregator);
}