-
Notifications
You must be signed in to change notification settings - Fork 587
/
MutableSortedMap.java
267 lines (206 loc) · 9.5 KB
/
MutableSortedMap.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
* 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.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.collection.MutableCollection;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.list.primitive.MutableBooleanList;
import org.eclipse.collections.api.list.primitive.MutableByteList;
import org.eclipse.collections.api.list.primitive.MutableCharList;
import org.eclipse.collections.api.list.primitive.MutableDoubleList;
import org.eclipse.collections.api.list.primitive.MutableFloatList;
import org.eclipse.collections.api.list.primitive.MutableIntList;
import org.eclipse.collections.api.list.primitive.MutableLongList;
import org.eclipse.collections.api.list.primitive.MutableShortList;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.MutableMapIterable;
import org.eclipse.collections.api.multimap.list.MutableListMultimap;
import org.eclipse.collections.api.multimap.sortedset.MutableSortedSetMultimap;
import org.eclipse.collections.api.partition.list.PartitionMutableList;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.tuple.Pair;
/**
* A MutableSortedMap is similar to a JCF Map but adds additional useful internal iterator methods.
* The MutableSortedMap interface additionally implements some of the methods in the Smalltalk Dictionary protocol.
*/
public interface MutableSortedMap<K, V>
extends MutableMapIterable<K, V>, SortedMapIterable<K, V>, SortedMap<K, V>, Cloneable
{
/**
* Creates a new instance of the same type with the same internal Comparator.
*/
@Override
MutableSortedMap<K, V> newEmpty();
/**
* Adds all the entries derived from {@code iterable} to {@code this}.
* The key and value for each entry is determined by applying the {@code keyFunction} and {@code valueFunction} to each item in {@code collection}.
* Any entry in {@code map} that has the same key as an entry in {@code this} will have it's value replaced by that in {@code map}.
*/
<E> MutableSortedMap<K, V> collectKeysAndValues(
Iterable<E> iterable,
Function<? super E, ? extends K> keyFunction,
Function<? super E, ? extends V> valueFunction);
/**
* Return the value in the Map that corresponds to the specified key, or if there is no value
* at the key, return the result of evaluating the specified one argument Function
* using the specified parameter, and put that value in the map at the specified key.
*/
@Override
<P> V getIfAbsentPutWith(K key, Function<? super P, ? extends V> function, P parameter);
@Override
MutableSortedMap<K, V> asUnmodifiable();
@Override
MutableSortedMap<K, V> asSynchronized();
// TODO: Keys could be ordered
@Override
MutableSortedSetMultimap<V, K> flip();
@Override
MutableSortedMap<K, V> select(Predicate2<? super K, ? super V> predicate);
@Override
MutableSortedMap<K, V> reject(Predicate2<? super K, ? super V> predicate);
@Override
<K2, V2> MutableMap<K2, V2> collect(Function2<? super K, ? super V, Pair<K2, V2>> function);
@Override
<R> MutableSortedMap<K, R> collectValues(Function2<? super K, ? super V, ? extends R> function);
@Override
<R> MutableList<R> collect(Function<? super V, ? extends R> function);
/**
* @since 9.1.
*/
@Override
default <R> MutableList<R> collectWithIndex(ObjectIntToObjectFunction<? super V, ? extends R> function)
{
int[] index = {0};
return this.collect(each -> function.valueOf(each, index[0]++));
}
@Override
MutableBooleanList collectBoolean(BooleanFunction<? super V> booleanFunction);
@Override
MutableByteList collectByte(ByteFunction<? super V> byteFunction);
@Override
MutableCharList collectChar(CharFunction<? super V> charFunction);
@Override
MutableDoubleList collectDouble(DoubleFunction<? super V> doubleFunction);
@Override
MutableFloatList collectFloat(FloatFunction<? super V> floatFunction);
@Override
MutableIntList collectInt(IntFunction<? super V> intFunction);
@Override
MutableLongList collectLong(LongFunction<? super V> longFunction);
@Override
MutableShortList collectShort(ShortFunction<? super V> shortFunction);
@Override
<P, VV> MutableList<VV> collectWith(Function2<? super V, ? super P, ? extends VV> function, P parameter);
@Override
<R> MutableList<R> collectIf(Predicate<? super V> predicate, Function<? super V, ? extends R> function);
@Override
<R> MutableList<R> flatCollect(Function<? super V, ? extends Iterable<R>> function);
/**
* @since 9.2
*/
@Override
default <P, R> MutableList<R> flatCollectWith(Function2<? super V, ? super P, ? extends Iterable<R>> function, P parameter)
{
return this.flatCollect(each -> function.apply(each, parameter));
}
@Override
MutableSortedMap<K, V> tap(Procedure<? super V> procedure);
@Override
MutableList<V> select(Predicate<? super V> predicate);
@Override
<P> MutableList<V> selectWith(Predicate2<? super V, ? super P> predicate, P parameter);
@Override
MutableList<V> reject(Predicate<? super V> predicate);
@Override
<P> MutableList<V> rejectWith(Predicate2<? super V, ? super P> predicate, P parameter);
@Override
PartitionMutableList<V> partition(Predicate<? super V> predicate);
@Override
<P> PartitionMutableList<V> partitionWith(Predicate2<? super V, ? super P> predicate, P parameter);
@Override
<S> MutableList<S> selectInstancesOf(Class<S> clazz);
@Override
<S> MutableList<Pair<V, S>> zip(Iterable<S> that);
@Override
MutableList<Pair<V, Integer>> zipWithIndex();
@Override
MutableSortedMap<K, V> toReversed();
@Override
MutableSortedMap<K, V> take(int count);
@Override
MutableSortedMap<K, V> takeWhile(Predicate<? super V> predicate);
@Override
MutableSortedMap<K, V> drop(int count);
@Override
MutableSortedMap<K, V> dropWhile(Predicate<? super V> predicate);
@Override
PartitionMutableList<V> partitionWhile(Predicate<? super V> predicate);
@Override
MutableList<V> distinct();
@Override
MutableSet<Entry<K, V>> entrySet();
/**
* The underlying set for the keys is sorted in ascending order according to their natural ordering or a custom comparator.
* However, Java 5 TreeMap returns a keySet that does not inherit from SortedSet therefore we have decided to
* return the keySet simply as a MutableSet to maintain Java 5 compatibility.
*/
//todo: Change return type to MutableSortedSet when we move to Java 6
@Override
MutableSet<K> keySet();
@Override
MutableSortedMap<K, V> headMap(K toKey);
@Override
MutableSortedMap<K, V> tailMap(K fromKey);
@Override
MutableSortedMap<K, V> subMap(K fromKey, K toKey);
@Override
MutableCollection<V> values();
MutableSortedMap<K, V> clone();
@Override
<VV> MutableListMultimap<VV, V> groupBy(Function<? super V, ? extends VV> function);
@Override
<VV> MutableListMultimap<VV, V> groupByEach(Function<? super V, ? extends Iterable<VV>> function);
@Override
<VV> MutableMap<VV, V> groupByUniqueKey(Function<? super V, ? extends VV> function);
// TODO: When we have implementations of linked hash maps
// MutableOrderedMap<V, K> flipUniqueValues();
@Override
MutableSortedMap<K, V> withKeyValue(K key, V value);
@Override
MutableSortedMap<K, V> withAllKeyValues(Iterable<? extends Pair<? extends K, ? extends V>> keyValues);
@Override
MutableSortedMap<K, V> withAllKeyValueArguments(Pair<? extends K, ? extends V>... keyValuePairs);
/**
* @deprecated in 6.0 Use {@link #withAllKeyValueArguments(Pair[])} instead. Inlineable.
*/
@Deprecated
default MutableSortedMap<K, V> with(Pair<K, V>... pairs)
{
return this.withAllKeyValueArguments(pairs);
}
@Override
MutableSortedMap<K, V> withoutKey(K key);
@Override
MutableSortedMap<K, V> withoutAllKeys(Iterable<? extends K> keys);
}