1 | /* | |
2 | * Copyright 2017 Federico Fissore <federico@fissore.org> | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.fissore.steroids; | |
17 | ||
18 | import java.util.*; | |
19 | import java.util.function.Function; | |
20 | import java.util.stream.Stream; | |
21 | ||
22 | /** | |
23 | * SteroidMap is a {@link Map} on steroids. | |
24 | * It decorates {@link Map} providing a fluent interface and a shorter syntax. It allows you to navigate a map structure without using casts. | |
25 | * It doesn't require any code to work with other frameworks/libraries: if they know how to deal with {@link Map}s, they work with SteroidMap as well. | |
26 | * Custom implementations should implement SteroidMap and delegate the actual storage to a backing map implementation, such as {@link HashMap} or {@link java.util.concurrent.ConcurrentHashMap}. | |
27 | * | |
28 | * @param <K> the type of the keys | |
29 | */ | |
30 | public interface SteroidMap<K> extends Map<K, Object> { | |
31 | ||
32 | /* content manipulation */ | |
33 | ||
34 | /** | |
35 | * {@link #put(Object, Object) Puts} a value if not null. Fluent version of {@link #put(Object, Object)} | |
36 | * | |
37 | * @param key key with which the specified value is to be associated | |
38 | * @param value value to be associated with the specified key | |
39 | * @return this instance | |
40 | */ | |
41 | default SteroidMap<K> add(K key, Object value) { | |
42 |
1
1. add : negated conditional → KILLED |
if (value != null) { |
43 | put(key, value); | |
44 | } | |
45 |
1
1. add : mutated return of Object value for org/fissore/steroids/SteroidMap::add to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this; |
46 | } | |
47 | ||
48 | /** | |
49 | * {@link #put(Object, Object) Puts} all non null values from given maps into this map. Fluent version of {@link #putAll(Map)} | |
50 | * | |
51 | * @param sources mappings to be stored in this map | |
52 | * @return this instance | |
53 | * @see #addAll(Stream) | |
54 | */ | |
55 | default SteroidMap<K> addAll(Map<K, Object>... sources) { | |
56 |
1
1. addAll : mutated return of Object value for org/fissore/steroids/SteroidMap::addAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return addAll(Stream.of(sources)); |
57 | } | |
58 | ||
59 | /** | |
60 | * {@link #put(Object, Object) Puts} all non null values from given maps into this map. Fluent version of {@link #putAll(Map)} | |
61 | * | |
62 | * @param sources mappings to be stored in this map | |
63 | * @return this instance | |
64 | * @see #addAll(Stream) | |
65 | */ | |
66 | default SteroidMap<K> addAll(Collection<Map<K, Object>> sources) { | |
67 |
1
1. addAll : mutated return of Object value for org/fissore/steroids/SteroidMap::addAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return addAll(sources.stream()); |
68 | } | |
69 | ||
70 | /** | |
71 | * {@link #put(Object, Object) Puts} all non null values from given maps into this map. Fluent version of {@link #putAll(Map)} | |
72 | * | |
73 | * @param sources mappings to be stored in this map | |
74 | * @return this instance | |
75 | */ | |
76 | default SteroidMap<K> addAll(Stream<Map<K, Object>> sources) { | |
77 | synchronized (this) { | |
78 |
2
1. addAll : removed call to java/util/stream/Stream::forEach → KILLED 2. lambda$addAll$0 : removed call to java/util/Map::forEach → KILLED |
sources.forEach(source -> source.forEach(this::add)); |
79 | } | |
80 |
1
1. addAll : mutated return of Object value for org/fissore/steroids/SteroidMap::addAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this; |
81 | } | |
82 | ||
83 | /** | |
84 | * {@link #put(Object, Object) Puts} non null keys from source into this map. If keys is not specified, it behaves as {@link #addAll(Map[])} | |
85 | * | |
86 | * @param source the map to add to this map | |
87 | * @param keys if specified, only given keys will be added | |
88 | * @return this instance | |
89 | */ | |
90 | default SteroidMap<K> addFrom(Map<K, Object> source, K... keys) { | |
91 |
1
1. addFrom : mutated return of Object value for org/fissore/steroids/SteroidMap::addFrom to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return addFrom(source, new HashSet<>(Arrays.asList(keys))); |
92 | } | |
93 | ||
94 | /** | |
95 | * {@link #put(Object, Object) Puts} non null keys from source into this map. If keys is not specified, it behaves as {@link #addAll(Map[])} | |
96 | * | |
97 | * @param source the map to add to this map | |
98 | * @param keys if specified, only these keys will be added | |
99 | * @return this instance | |
100 | */ | |
101 | default SteroidMap<K> addFrom(Map<K, Object> source, Collection<K> keys) { | |
102 |
1
1. addFrom : negated conditional → KILLED |
if (source == null) { |
103 |
1
1. addFrom : mutated return of Object value for org/fissore/steroids/SteroidMap::addFrom to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this; |
104 | } | |
105 | ||
106 |
1
1. addFrom : negated conditional → KILLED |
if (keys.size() == 0) { |
107 |
1
1. addFrom : mutated return of Object value for org/fissore/steroids/SteroidMap::addFrom to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return addAll(source); |
108 | } | |
109 | ||
110 | synchronized (this) { | |
111 | source.entrySet().stream() | |
112 |
1
1. lambda$addFrom$1 : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
.filter(e -> keys.contains(e.getKey())) |
113 |
1
1. addFrom : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach(e -> add(e.getKey(), e.getValue())); |
114 | } | |
115 | ||
116 |
1
1. addFrom : mutated return of Object value for org/fissore/steroids/SteroidMap::addFrom to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this; |
117 | } | |
118 | ||
119 | /** | |
120 | * Renames the specified key, if present. It runs a in a synchronized block | |
121 | * | |
122 | * @param oldKey the old key | |
123 | * @param newKey the new key | |
124 | * @return this instance | |
125 | */ | |
126 | default SteroidMap<K> renameKey(K oldKey, K newKey) { | |
127 | synchronized (this) { | |
128 |
1
1. renameKey : negated conditional → KILLED |
if (!containsKey(oldKey)) { |
129 |
1
1. renameKey : mutated return of Object value for org/fissore/steroids/SteroidMap::renameKey to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this; |
130 | } | |
131 | put(newKey, get(oldKey)); | |
132 | remove(oldKey); | |
133 | } | |
134 |
1
1. renameKey : mutated return of Object value for org/fissore/steroids/SteroidMap::renameKey to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this; |
135 | } | |
136 | ||
137 | /** | |
138 | * Removes given keys from this map. Fluent version of {@link #remove(Object)} | |
139 | * | |
140 | * @param keys the keys to remove | |
141 | * @return this instance | |
142 | * @see #del(Stream) | |
143 | */ | |
144 | default SteroidMap<K> del(K... keys) { | |
145 |
1
1. del : mutated return of Object value for org/fissore/steroids/SteroidMap::del to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return del(Stream.of(keys)); |
146 | } | |
147 | ||
148 | /** | |
149 | * Removes given keys from this map. Fluent version of {@link #remove(Object)} | |
150 | * | |
151 | * @param keys the keys to remove | |
152 | * @return this instance | |
153 | * @see #del(Stream) | |
154 | */ | |
155 | default SteroidMap<K> del(Collection<K> keys) { | |
156 |
1
1. del : mutated return of Object value for org/fissore/steroids/SteroidMap::del to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return del(keys.stream()); |
157 | } | |
158 | ||
159 | /** | |
160 | * Removes given keys from this map. Fluent version of {@link #remove(Object)} | |
161 | * | |
162 | * @param keys the keys to remove | |
163 | * @return this instance | |
164 | */ | |
165 | default SteroidMap<K> del(Stream<K> keys) { | |
166 | synchronized (this) { | |
167 |
1
1. del : removed call to java/util/stream/Stream::forEach → KILLED |
keys.forEach(this::remove); |
168 | } | |
169 |
1
1. del : mutated return of Object value for org/fissore/steroids/SteroidMap::del to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this; |
170 | } | |
171 | ||
172 | /* content extraction */ | |
173 | ||
174 | /** | |
175 | * If given key is {@link #valued(Object) valued}, it's applied to provided valueReturner. Otherwise, defaultValue is returned. | |
176 | * Both checking if the key is {@link #valued(Object) valued} and applying valueReturner run in a synchronized block | |
177 | * | |
178 | * @param key the key | |
179 | * @param defaultValue the value to return if key is not {@link #valued(Object) valued} | |
180 | * @param valueReturner the function to apply the key to | |
181 | * @param <V> the return type | |
182 | * @return either value from map or defaultValue | |
183 | */ | |
184 | default <V> V defaultIfMissing(K key, V defaultValue, Function<K, V> valueReturner) { | |
185 | synchronized (this) { | |
186 |
1
1. defaultIfMissing : negated conditional → KILLED |
if (valued(key)) { |
187 |
1
1. defaultIfMissing : mutated return of Object value for org/fissore/steroids/SteroidMap::defaultIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return valueReturner.apply(key); |
188 | } | |
189 | } | |
190 |
1
1. defaultIfMissing : mutated return of Object value for org/fissore/steroids/SteroidMap::defaultIfMissing to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultValue; |
191 | } | |
192 | ||
193 | /** | |
194 | * {@link #get(Object) Gets} given key and cast it to a Long | |
195 | * | |
196 | * @param key the key | |
197 | * @return value associated to key casted to Long | |
198 | */ | |
199 | default long l(K key) { | |
200 |
1
1. l : replaced return of long value with value + 1 for org/fissore/steroids/SteroidMap::l → KILLED |
return (Long) get(key); |
201 | } | |
202 | ||
203 | /** | |
204 | * {@link #get(Object) Gets} given key and cast it to a Long. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
205 | * | |
206 | * @param key the key | |
207 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
208 | * @return value associated to key, casted to Long. defaultValue if key is not {@link #valued(Object) valued} | |
209 | */ | |
210 | default long l(K key, long defaultValue) { | |
211 |
1
1. l : replaced return of long value with value + 1 for org/fissore/steroids/SteroidMap::l → KILLED |
return defaultIfMissing(key, defaultValue, this::l); |
212 | } | |
213 | ||
214 | /** | |
215 | * {@link #get(Object) Gets} given key and cast it to a Integer | |
216 | * | |
217 | * @param key the key | |
218 | * @return value associated to key casted to Integer | |
219 | */ | |
220 | default int i(K key) { | |
221 |
1
1. i : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return (Integer) get(key); |
222 | } | |
223 | ||
224 | /** | |
225 | * {@link #get(Object) Gets} given key and cast it to a Integer. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
226 | * | |
227 | * @param key the key | |
228 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
229 | * @return value associated to key, casted to Integer. defaultValue if key is not {@link #valued(Object) valued} | |
230 | */ | |
231 | default int i(K key, int defaultValue) { | |
232 |
1
1. i : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return defaultIfMissing(key, defaultValue, this::i); |
233 | } | |
234 | ||
235 | /** | |
236 | * {@link #get(Object) Gets} given key and cast it to a Double | |
237 | * | |
238 | * @param key the key | |
239 | * @return value associated to key casted to Double | |
240 | */ | |
241 | default double d(K key) { | |
242 |
1
1. d : replaced return of double value with -(x + 1) for org/fissore/steroids/SteroidMap::d → KILLED |
return (Double) get(key); |
243 | } | |
244 | ||
245 | /** | |
246 | * {@link #get(Object) Gets} given key and cast it to a Double. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
247 | * | |
248 | * @param key the key | |
249 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
250 | * @return value associated to key, casted to Double. defaultValue if key is not {@link #valued(Object) valued} | |
251 | */ | |
252 | default double d(K key, double defaultValue) { | |
253 |
1
1. d : replaced return of double value with -(x + 1) for org/fissore/steroids/SteroidMap::d → KILLED |
return defaultIfMissing(key, defaultValue, this::d); |
254 | } | |
255 | ||
256 | /** | |
257 | * {@link #get(Object) Gets} given key and cast it to a Float | |
258 | * | |
259 | * @param key the key | |
260 | * @return value associated to key casted to Float | |
261 | */ | |
262 | default float f(K key) { | |
263 |
1
1. f : replaced return of float value with -(x + 1) for org/fissore/steroids/SteroidMap::f → KILLED |
return (Float) get(key); |
264 | } | |
265 | ||
266 | /** | |
267 | * {@link #get(Object) Gets} given key and cast it to a Float. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
268 | * | |
269 | * @param key the key | |
270 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
271 | * @return value associated to key, casted to Float. defaultValue if key is not {@link #valued(Object) valued} | |
272 | */ | |
273 | default float f(K key, float defaultValue) { | |
274 |
1
1. f : replaced return of float value with -(x + 1) for org/fissore/steroids/SteroidMap::f → KILLED |
return defaultIfMissing(key, defaultValue, this::f); |
275 | } | |
276 | ||
277 | /** | |
278 | * {@link #get(Object) Gets} given key and cast it to a String | |
279 | * | |
280 | * @param key the key | |
281 | * @return value associated to key casted to String | |
282 | */ | |
283 | default String s(K key) { | |
284 |
1
1. s : mutated return of Object value for org/fissore/steroids/SteroidMap::s to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (String) get(key); |
285 | } | |
286 | ||
287 | /** | |
288 | * {@link #get(Object) Gets} given key and cast it to a String. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
289 | * | |
290 | * @param key the key | |
291 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
292 | * @return value associated to key, casted to String. defaultValue if key is not {@link #valued(Object) valued} | |
293 | */ | |
294 | default String s(K key, String defaultValue) { | |
295 |
1
1. s : mutated return of Object value for org/fissore/steroids/SteroidMap::s to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, defaultValue, this::s); |
296 | } | |
297 | ||
298 | /** | |
299 | * {@link #get(Object) Gets} given key and cast it to a Boolean | |
300 | * | |
301 | * @param key the key | |
302 | * @return value associated to key casted to Boolean | |
303 | */ | |
304 | default boolean b(K key) { | |
305 |
1
1. b : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return (Boolean) get(key); |
306 | } | |
307 | ||
308 | /** | |
309 | * {@link #get(Object) Gets} given key and cast it to a Boolean. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
310 | * | |
311 | * @param key the key | |
312 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
313 | * @return value associated to key, casted to Boolean. defaultValue if key is not {@link #valued(Object) valued} | |
314 | */ | |
315 | default boolean b(K key, boolean defaultValue) { | |
316 |
1
1. b : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return defaultIfMissing(key, defaultValue, this::b); |
317 | } | |
318 | ||
319 | /** | |
320 | * {@link #get(Object) Gets} given key and cast it to type V | |
321 | * | |
322 | * @param key the key | |
323 | * @param <V> the return type | |
324 | * @return value associated to key casted to type V | |
325 | */ | |
326 | default <V> V o(K key) { | |
327 |
1
1. o : mutated return of Object value for org/fissore/steroids/SteroidMap::o to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (V) get(key); |
328 | } | |
329 | ||
330 | /** | |
331 | * {@link #get(Object) Gets} given key and transform it using given function | |
332 | * | |
333 | * @param key the key | |
334 | * @param transformer a function used to change original value | |
335 | * @param <V> the return type | |
336 | * @return value associated to key and transformed using function | |
337 | */ | |
338 | default <V> V o(K key, Function<Object, V> transformer) { | |
339 |
1
1. o : mutated return of Object value for org/fissore/steroids/SteroidMap::o to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return transformer.apply(get(key)); |
340 | } | |
341 | ||
342 | /** | |
343 | * {@link #get(Object) Gets} given key and cast it to type of given Class | |
344 | * | |
345 | * @param key the key | |
346 | * @param clazz the clazz, useful only to make the compiler happy about type V | |
347 | * @param <V> the return type | |
348 | * @return value associated to key casted to type V | |
349 | */ | |
350 | @SuppressWarnings("unchecked") | |
351 | default <V> V o(K key, Class<V> clazz) { | |
352 |
1
1. o : mutated return of Object value for org/fissore/steroids/SteroidMap::o to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (V) get(key); |
353 | } | |
354 | ||
355 | /** | |
356 | * {@link #get(Object) Gets} given key and cast it to a Object. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
357 | * | |
358 | * @param key the key | |
359 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
360 | * @param <V> the return type | |
361 | * @return value associated to key, casted to Object. defaultValue if key is not {@link #valued(Object) valued} | |
362 | */ | |
363 | @SuppressWarnings("unchecked") | |
364 | default <V> V o(K key, V defaultValue) { | |
365 |
1
1. o : mutated return of Object value for org/fissore/steroids/SteroidMap::o to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, defaultValue, this::o); |
366 | } | |
367 | ||
368 | /** | |
369 | * {@link #get(Object) Gets} given key and transform it using given function. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
370 | * | |
371 | * @param key the key | |
372 | * @param transformer a function used to change original value | |
373 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
374 | * @param <V> the return type | |
375 | * @return value associated to key, transformed using function. defaultValue if key is not {@link #valued(Object) valued} | |
376 | */ | |
377 | default <V> V o(K key, Function<Object, V> transformer, V defaultValue) { | |
378 |
2
1. lambda$o$3 : mutated return of Object value for org/fissore/steroids/SteroidMap::lambda$o$3 to ( if (x != null) null else throw new RuntimeException ) → KILLED 2. o : mutated return of Object value for org/fissore/steroids/SteroidMap::o to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, defaultValue, (k) -> o(k, transformer)); |
379 | } | |
380 | ||
381 | /** | |
382 | * {@link #get(Object) Gets} given key and cast it to a Date | |
383 | * | |
384 | * @param key the key | |
385 | * @return value associated to key casted to Date | |
386 | */ | |
387 | default Date date(K key) { | |
388 |
1
1. date : mutated return of Object value for org/fissore/steroids/SteroidMap::date to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (Date) get(key); |
389 | } | |
390 | ||
391 | /** | |
392 | * {@link #get(Object) Gets} given key and cast it to a Date. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
393 | * | |
394 | * @param key the key | |
395 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
396 | * @return value associated to key, casted to Date. defaultValue if key is not {@link #valued(Object) valued} | |
397 | */ | |
398 | default Date date(K key, Date defaultValue) { | |
399 |
1
1. date : mutated return of Object value for org/fissore/steroids/SteroidMap::date to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, defaultValue, this::date); |
400 | } | |
401 | ||
402 | /** | |
403 | * A key is valued if <code>{@link #get(Object) get(key)} != null</code> | |
404 | * | |
405 | * @param key the key | |
406 | * @return true if {@link #get(Object) get(key)} != null | |
407 | */ | |
408 | default boolean valued(K key) { | |
409 |
2
1. valued : negated conditional → KILLED 2. valued : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return get(key) != null; |
410 | } | |
411 | ||
412 | /** | |
413 | * Opposite of {@link #valued(Object)} | |
414 | * | |
415 | * @param key the key | |
416 | * @return true if {@link #get(Object) get(key)} == null | |
417 | */ | |
418 | default boolean notValued(K key) { | |
419 |
2
1. notValued : negated conditional → KILLED 2. notValued : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return !valued(key); |
420 | } | |
421 | ||
422 | /** | |
423 | * {@link #get(Object) Gets} given key and cast it to a Collection<V> | |
424 | * | |
425 | * @param key the key | |
426 | * @param <V> the return type | |
427 | * @return value associated to key casted to Collection<V> | |
428 | */ | |
429 | @SuppressWarnings("unchecked") | |
430 | default <V> Collection<V> collection(K key) { | |
431 |
1
1. collection : mutated return of Object value for org/fissore/steroids/SteroidMap::collection to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (Collection<V>) get(key); |
432 | } | |
433 | ||
434 | /** | |
435 | * {@link #get(Object) Gets} given key and cast it to a Collection<V>. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
436 | * | |
437 | * @param key the key | |
438 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
439 | * @param <V> the return type | |
440 | * @return value associated to key, casted to Collection<V>. defaultValue if key is not {@link #valued(Object) valued} | |
441 | */ | |
442 | default <V> Collection<V> collection(K key, Collection<V> defaultValue) { | |
443 |
1
1. collection : mutated return of Object value for org/fissore/steroids/SteroidMap::collection to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, defaultValue, this::collection); |
444 | } | |
445 | ||
446 | /** | |
447 | * {@link #get(Object) Gets} given key and cast it to a List<V> | |
448 | * | |
449 | * @param key the key | |
450 | * @param <V> the return type | |
451 | * @return value associated to key casted to List<V> | |
452 | */ | |
453 | @SuppressWarnings("unchecked") | |
454 | default <V> List<V> list(K key) { | |
455 |
1
1. list : mutated return of Object value for org/fissore/steroids/SteroidMap::list to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (List<V>) get(key); |
456 | } | |
457 | ||
458 | /** | |
459 | * {@link #get(Object) Gets} given key and cast it to a List<V>. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
460 | * | |
461 | * @param key the key | |
462 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
463 | * @param <V> the return type | |
464 | * @return value associated to key, casted to List<V>. defaultValue if key is not {@link #valued(Object) valued} | |
465 | */ | |
466 | default <V> List<V> list(K key, List<V> defaultValue) { | |
467 |
1
1. list : mutated return of Object value for org/fissore/steroids/SteroidMap::list to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, defaultValue, this::list); |
468 | } | |
469 | ||
470 | /** | |
471 | * {@link #get(Object) Gets} given key, cast it to a Collection<V> and returns its Stream<V> | |
472 | * | |
473 | * @param key the key | |
474 | * @param <V> the return type | |
475 | * @return value associated to key casted to a Collection<V> and converted to a Stream<V> | |
476 | */ | |
477 | @SuppressWarnings("unchecked") | |
478 | default <V> Stream<V> stream(K key) { | |
479 |
1
1. stream : mutated return of Object value for org/fissore/steroids/SteroidMap::stream to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (Stream<V>) collection(key).stream(); |
480 | } | |
481 | ||
482 | /** | |
483 | * {@link #get(Object) Gets} given key, cast it to a Collection<V> and returns its Stream<V>. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
484 | * | |
485 | * @param key the key | |
486 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
487 | * @param <V> the return type | |
488 | * @return value associated to key casted to a Collection<V> and converted to a Stream<V>. defaultValue if key is not {@link #valued(Object) valued} | |
489 | */ | |
490 | default <V> Stream<V> stream(K key, Stream<V> defaultValue) { | |
491 |
1
1. stream : mutated return of Object value for org/fissore/steroids/SteroidMap::stream to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, defaultValue, this::stream); |
492 | } | |
493 | ||
494 | /** | |
495 | * Creates a new SteroidMap made of given keys only. Keys must be {@link #valued(Object) valued} | |
496 | * | |
497 | * @param keys the keys used to create a new, filtered SteroidMap | |
498 | * @return a new, filtered, SteroidMap | |
499 | * @see #subMap(Stream) | |
500 | */ | |
501 | default SteroidMap<K> subMap(K... keys) { | |
502 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SteroidMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return subMap(Stream.of(keys)); |
503 | } | |
504 | ||
505 | /** | |
506 | * Creates a new SteroidMap made of given keys only. Keys must be {@link #valued(Object) valued} | |
507 | * | |
508 | * @param keys the keys used to create a new, filtered SteroidMap | |
509 | * @return a new, filtered, SteroidMap | |
510 | * @see #subMap(Stream) | |
511 | */ | |
512 | default SteroidMap<K> subMap(Collection<K> keys) { | |
513 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SteroidMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return subMap(keys.stream()); |
514 | } | |
515 | ||
516 | /** | |
517 | * Creates a new SteroidMap made of given keys only. Keys must be {@link #valued(Object) valued} | |
518 | * | |
519 | * @param keys the keys used to create a new, filtered SteroidMap | |
520 | * @return a new, filtered, SteroidMap | |
521 | */ | |
522 | SteroidMap<K> subMap(Stream<K> keys); | |
523 | ||
524 | /** | |
525 | * Creates a new SteroidMap, backed by given backingMap and made of given keys only. Keys must be {@link #valued(Object) valued} | |
526 | * | |
527 | * @param backingMap the actual map to use as storage | |
528 | * @param keys the keys used to create a new, filtered SteroidMap | |
529 | * @return a new, filtered, SteroidMap | |
530 | * @see #subMap(Map, Stream) | |
531 | */ | |
532 | default SteroidMap<K> subMap(Map<K, Object> backingMap, K... keys) { | |
533 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SteroidMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return subMap(backingMap, Stream.of(keys)); |
534 | } | |
535 | ||
536 | /** | |
537 | * Creates a new SteroidMap, backed by given backingMap and made of given keys only. Keys must be {@link #valued(Object) valued} | |
538 | * | |
539 | * @param backingMap the actual map to use as storage | |
540 | * @param keys the keys used to create a new, filtered SteroidMap | |
541 | * @return a new, filtered, SteroidMap | |
542 | * @see #subMap(Map, Stream) | |
543 | */ | |
544 | default SteroidMap<K> subMap(Map<K, Object> backingMap, Collection<K> keys) { | |
545 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SteroidMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return subMap(backingMap, keys.stream()); |
546 | } | |
547 | ||
548 | /** | |
549 | * Creates a new SteroidMap, backed by given backingMap and made of given keys only. Keys must be {@link #valued(Object) valued} | |
550 | * | |
551 | * @param backingMap the actual map to use as storage | |
552 | * @param keys the keys used to create a new, filtered SteroidMap | |
553 | * @return a new, filtered, SteroidMap | |
554 | */ | |
555 | SteroidMap<K> subMap(Map<K, Object> backingMap, Stream<K> keys); | |
556 | ||
557 | /** | |
558 | * {@link #get(Object) Gets} given key and, if value is not of type SteroidMap, a new SteroidMap is created using value as backing map. Otherwise value is casted to SteroidMap and returned | |
559 | * | |
560 | * @param key the key | |
561 | * @return value associated to key, either casted to SteroidMap or used as backing map for a new SteroidMap | |
562 | */ | |
563 | SteroidMap<K> map(K key); | |
564 | ||
565 | /** | |
566 | * {@link #get(Object) Gets} given key and, if value is not of type SteroidMap, a new SteroidMap is created using value as backing map. Otherwise value is casted to SteroidMap and returned. If key is not {@link #valued(Object) valued}, it returns defaultValue | |
567 | * | |
568 | * @param key the key | |
569 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
570 | * @return value associated to key, either casted to SteroidMap or used as backing map for a new SteroidMap | |
571 | */ | |
572 | default SteroidMap<K> map(K key, SteroidMap<K> defaultValue) { | |
573 |
1
1. map : mutated return of Object value for org/fissore/steroids/SteroidMap::map to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, defaultValue, this::map); |
574 | } | |
575 | ||
576 | /** | |
577 | * {@link #get(Object) Gets} given key, cast it to a Collection<? extends SteroidMap<K>> and returns its Stream<? extends SteroidMap<K>>. Each entry is evaluated: if it's not of type SteroidMap, a new SteroidMap is created using value as backing map. If the key is not {@link #valued(Object) valued}, an empty Stream is returned | |
578 | * | |
579 | * @param key the key | |
580 | * @return value associated to key casted to a Collection<? extends SteroidMap<K>> and converted to a Stream<? extends SteroidMap<K>>, or an empty Stream if key is not {@link #valued(Object) valued} | |
581 | */ | |
582 | default Stream<? extends SteroidMap<K>> maps(K key) { | |
583 |
2
1. lambda$maps$4 : mutated return of Object value for org/fissore/steroids/SteroidMap::lambda$maps$4 to ( if (x != null) null else throw new RuntimeException ) → KILLED 2. maps : mutated return of Object value for org/fissore/steroids/SteroidMap::maps to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, Stream.empty(), (k) -> stream(k).map(this::ensureMapIsOnSteroid)); |
584 | } | |
585 | ||
586 | /** | |
587 | * {@link #get(Object) Gets} given key, cast it to a Collection<? extends SteroidMap<K>> and returns its Stream<? extends SteroidMap<K>>. Each entry is evaluated: if it's not of type SteroidMap, a new SteroidMap is created using value as backing map. If the key is not {@link #valued(Object) valued}, it returns defaultValue | |
588 | * | |
589 | * @param key the key | |
590 | * @param defaultValue the defaultValue to return if key is not {@link #valued(Object) valued} | |
591 | * @return value associated to key casted to a Collection<? extends SteroidMap<K>> and converted to a Stream<? extends SteroidMap<K>>, defaultValue if key is not {@link #valued(Object) valued} | |
592 | */ | |
593 | default Stream<? extends SteroidMap<K>> maps(K key, Stream<? extends SteroidMap<K>> defaultValue) { | |
594 |
1
1. maps : mutated return of Object value for org/fissore/steroids/SteroidMap::maps to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return defaultIfMissing(key, defaultValue, this::maps); |
595 | } | |
596 | ||
597 | SteroidMap<K> ensureMapIsOnSteroid(Object value); | |
598 | ||
599 | /** | |
600 | * Returns a shallow copy of this map | |
601 | * | |
602 | * @return a shallow copy of this map | |
603 | */ | |
604 | SteroidMap<K> copy(); | |
605 | ||
606 | } | |
Mutations | ||
42 |
1.1 |
|
45 |
1.1 |
|
56 |
1.1 |
|
67 |
1.1 |
|
78 |
1.1 2.2 |
|
80 |
1.1 |
|
91 |
1.1 |
|
102 |
1.1 |
|
103 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
112 |
1.1 |
|
113 |
1.1 |
|
116 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
134 |
1.1 |
|
145 |
1.1 |
|
156 |
1.1 |
|
167 |
1.1 |
|
169 |
1.1 |
|
186 |
1.1 |
|
187 |
1.1 |
|
190 |
1.1 |
|
200 |
1.1 |
|
211 |
1.1 |
|
221 |
1.1 |
|
232 |
1.1 |
|
242 |
1.1 |
|
253 |
1.1 |
|
263 |
1.1 |
|
274 |
1.1 |
|
284 |
1.1 |
|
295 |
1.1 |
|
305 |
1.1 |
|
316 |
1.1 |
|
327 |
1.1 |
|
339 |
1.1 |
|
352 |
1.1 |
|
365 |
1.1 |
|
378 |
1.1 2.2 |
|
388 |
1.1 |
|
399 |
1.1 |
|
409 |
1.1 2.2 |
|
419 |
1.1 2.2 |
|
431 |
1.1 |
|
443 |
1.1 |
|
455 |
1.1 |
|
467 |
1.1 |
|
479 |
1.1 |
|
491 |
1.1 |
|
502 |
1.1 |
|
513 |
1.1 |
|
533 |
1.1 |
|
545 |
1.1 |
|
573 |
1.1 |
|
583 |
1.1 2.2 |
|
594 |
1.1 |