| 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.Collection; | |
| 19 | import java.util.HashMap; | |
| 20 | import java.util.Map; | |
| 21 | import java.util.Set; | |
| 22 | import java.util.function.BiConsumer; | |
| 23 | import java.util.function.BiFunction; | |
| 24 | import java.util.function.Function; | |
| 25 | import java.util.stream.Stream; | |
| 26 | ||
| 27 | /** | |
| 28 | * SMap is the default implementation of {@link SteroidMap}. By default it's backed by a {@link HashMap}. | |
| 29 | * It provides some useful constructors as well as implementations to {@link #map(String)}, {@link #subMap(Stream)} and {@link #subMap(Map, Stream)} methods | |
| 30 | */ | |
| 31 | public class SMap implements SteroidMap<String> { | |
| 32 | ||
| 33 | private final Map<String, Object> map; | |
| 34 | ||
| 35 | /** | |
| 36 | * Creates a new SMap, using {@link HashMap} as backing map | |
| 37 | */ | |
| 38 | public SMap() { | |
| 39 | this(new HashMap<>()); | |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * Creates a new SMap, using given map as backing map | |
| 44 | * | |
| 45 | * @param map the map to use as backing map | |
| 46 | */ | |
| 47 | public SMap(Map<String, Object> map) { | |
| 48 |
1
1. |
if (map == null) { |
| 49 | throw new NullPointerException(); | |
| 50 | } | |
| 51 | this.map = map; | |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * Creates a new SMap with one initial key/value mapping | |
| 56 | * | |
| 57 | * @param key the first key | |
| 58 | * @param value the first value | |
| 59 | * @see #SMap() | |
| 60 | */ | |
| 61 | public SMap(String key, Object value) { | |
| 62 | this(); | |
| 63 | add(key, value); | |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * Creates a new SMap with two initial key/value mappings | |
| 68 | * | |
| 69 | * @param key1 the first key | |
| 70 | * @param value1 the first value | |
| 71 | * @param key2 the second key | |
| 72 | * @param value2 the second value | |
| 73 | * @see #SMap() | |
| 74 | */ | |
| 75 | public SMap(String key1, Object value1, String key2, Object value2) { | |
| 76 | this(); | |
| 77 | add(key1, value1); | |
| 78 | add(key2, value2); | |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * Creates a new SMap with three initial key/value mappings | |
| 83 | * | |
| 84 | * @param key1 the first key | |
| 85 | * @param value1 the first value | |
| 86 | * @param key2 the second key | |
| 87 | * @param value2 the second value | |
| 88 | * @param key3 the third key | |
| 89 | * @param value3 the third value | |
| 90 | * @see #SMap() | |
| 91 | */ | |
| 92 | public SMap(String key1, Object value1, String key2, Object value2, String key3, Object value3) { | |
| 93 | this(); | |
| 94 | add(key1, value1); | |
| 95 | add(key2, value2); | |
| 96 | add(key3, value3); | |
| 97 | } | |
| 98 | ||
| 99 | @SuppressWarnings("unchecked") | |
| 100 | @Override | |
| 101 | public SMap subMap(Stream<String> keys) { | |
| 102 | Map<String, Object> map = newInnerMapInstance(); | |
| 103 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return subMap(map, keys); |
| 104 | } | |
| 105 | ||
| 106 | private Map newInnerMapInstance() { | |
| 107 | try { | |
| 108 |
1
1. newInnerMapInstance : mutated return of Object value for org/fissore/steroids/SMap::newInnerMapInstance to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return this.map.getClass().newInstance(); |
| 109 | } catch (Exception e) { | |
| 110 | String error = "Error while using reflection to create a new instance of " + this.map.getClass() + ". Consider using a backing map with a public default constructor or providing backing map on your own and calling subMap(Map, keys...)"; | |
| 111 | throw new RuntimeException(error, e); | |
| 112 | } | |
| 113 | } | |
| 114 | ||
| 115 | @Override | |
| 116 | public SMap subMap(Map<String, Object> backingMap, Stream<String> keys) { | |
| 117 | SMap subMap = new SMap(backingMap); | |
| 118 |
1
1. subMap : removed call to java/util/stream/Stream::forEach → KILLED |
keys.forEach(key -> subMap.add(key, get(key))); |
| 119 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return subMap; |
| 120 | } | |
| 121 | ||
| 122 | @Override | |
| 123 | public SMap map(String key) { | |
| 124 |
1
1. map : mutated return of Object value for org/fissore/steroids/SMap::map to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return ensureMapIsOnSteroid(get(key)); |
| 125 | } | |
| 126 | ||
| 127 | @SuppressWarnings("unchecked") | |
| 128 | @Override | |
| 129 | public SMap ensureMapIsOnSteroid(Object value) { | |
| 130 |
1
1. ensureMapIsOnSteroid : negated conditional → KILLED |
if (value == null) { |
| 131 |
1
1. ensureMapIsOnSteroid : mutated return of Object value for org/fissore/steroids/SMap::ensureMapIsOnSteroid to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
| 132 | } | |
| 133 |
1
1. ensureMapIsOnSteroid : negated conditional → KILLED |
if (value instanceof SMap) { |
| 134 |
1
1. ensureMapIsOnSteroid : mutated return of Object value for org/fissore/steroids/SMap::ensureMapIsOnSteroid to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) value; |
| 135 | } | |
| 136 |
1
1. ensureMapIsOnSteroid : negated conditional → KILLED |
if (value instanceof Map) { |
| 137 |
1
1. ensureMapIsOnSteroid : mutated return of Object value for org/fissore/steroids/SMap::ensureMapIsOnSteroid to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new SMap((Map<String, Object>) value); |
| 138 | } | |
| 139 | throw new IllegalArgumentException(value + " is neither a Map or a SteroidMap"); | |
| 140 | } | |
| 141 | ||
| 142 | @Override | |
| 143 | public SMap add(String key, Object value) { | |
| 144 |
1
1. add : mutated return of Object value for org/fissore/steroids/SMap::add to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.add(key, value); |
| 145 | } | |
| 146 | ||
| 147 | @Override | |
| 148 | public SMap addAll(Map<String, Object>... sources) { | |
| 149 |
1
1. addAll : mutated return of Object value for org/fissore/steroids/SMap::addAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.addAll(sources); |
| 150 | } | |
| 151 | ||
| 152 | @Override | |
| 153 | public SMap addAll(Collection<Map<String, Object>> sources) { | |
| 154 |
1
1. addAll : mutated return of Object value for org/fissore/steroids/SMap::addAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.addAll(sources); |
| 155 | } | |
| 156 | ||
| 157 | @Override | |
| 158 | public SMap addAll(Stream<Map<String, Object>> sources) { | |
| 159 |
1
1. addAll : mutated return of Object value for org/fissore/steroids/SMap::addAll to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.addAll(sources); |
| 160 | } | |
| 161 | ||
| 162 | @Override | |
| 163 | public SMap addFrom(Map<String, Object> source, String... keys) { | |
| 164 |
1
1. addFrom : mutated return of Object value for org/fissore/steroids/SMap::addFrom to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.addFrom(source, keys); |
| 165 | } | |
| 166 | ||
| 167 | @Override | |
| 168 | public SMap addFrom(Map<String, Object> source, Collection<String> keys) { | |
| 169 |
1
1. addFrom : mutated return of Object value for org/fissore/steroids/SMap::addFrom to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.addFrom(source, keys); |
| 170 | } | |
| 171 | ||
| 172 | @Override | |
| 173 | public SMap renameKey(String oldKey, String newKey) { | |
| 174 |
1
1. renameKey : mutated return of Object value for org/fissore/steroids/SMap::renameKey to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.renameKey(oldKey, newKey); |
| 175 | } | |
| 176 | ||
| 177 | @Override | |
| 178 | public SMap del(String... keys) { | |
| 179 |
1
1. del : mutated return of Object value for org/fissore/steroids/SMap::del to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.del(keys); |
| 180 | } | |
| 181 | ||
| 182 | @Override | |
| 183 | public SMap del(Collection<String> keys) { | |
| 184 |
1
1. del : mutated return of Object value for org/fissore/steroids/SMap::del to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.del(keys); |
| 185 | } | |
| 186 | ||
| 187 | @Override | |
| 188 | public SMap del(Stream<String> keys) { | |
| 189 |
1
1. del : mutated return of Object value for org/fissore/steroids/SMap::del to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.del(keys); |
| 190 | } | |
| 191 | ||
| 192 | @Override | |
| 193 | public SMap subMap(String... keys) { | |
| 194 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.subMap(keys); |
| 195 | } | |
| 196 | ||
| 197 | @Override | |
| 198 | public SMap subMap(Collection<String> keys) { | |
| 199 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.subMap(keys); |
| 200 | } | |
| 201 | ||
| 202 | @Override | |
| 203 | public SMap subMap(Map<String, Object> backingMap, String... keys) { | |
| 204 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.subMap(backingMap, keys); |
| 205 | } | |
| 206 | ||
| 207 | @Override | |
| 208 | public SMap subMap(Map<String, Object> backingMap, Collection<String> keys) { | |
| 209 |
1
1. subMap : mutated return of Object value for org/fissore/steroids/SMap::subMap to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.subMap(backingMap, keys); |
| 210 | } | |
| 211 | ||
| 212 | @Override | |
| 213 | public SMap map(String key, SteroidMap<String> defaultValue) { | |
| 214 |
1
1. map : mutated return of Object value for org/fissore/steroids/SMap::map to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (SMap) SteroidMap.super.map(key, defaultValue); |
| 215 | } | |
| 216 | ||
| 217 | @Override | |
| 218 | public Stream<SMap> maps(String key) { | |
| 219 |
2
1. lambda$maps$1 : mutated return of Object value for org/fissore/steroids/SMap::lambda$maps$1 to ( if (x != null) null else throw new RuntimeException ) → KILLED 2. maps : mutated return of Object value for org/fissore/steroids/SMap::maps to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return SteroidMap.super.maps(key).map(s -> (SMap) s); |
| 220 | } | |
| 221 | ||
| 222 | @Override | |
| 223 | public Stream<SMap> maps(String key, Stream<? extends SteroidMap<String>> defaultValue) { | |
| 224 |
2
1. lambda$maps$2 : mutated return of Object value for org/fissore/steroids/SMap::lambda$maps$2 to ( if (x != null) null else throw new RuntimeException ) → KILLED 2. maps : mutated return of Object value for org/fissore/steroids/SMap::maps to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return SteroidMap.super.maps(key, defaultValue).map(s -> (SMap) s); |
| 225 | } | |
| 226 | ||
| 227 | @Override | |
| 228 | public SMap copy() { | |
| 229 |
1
1. copy : mutated return of Object value for org/fissore/steroids/SMap::copy to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new SMap().addAll(this); |
| 230 | } | |
| 231 | ||
| 232 | /* GENERATED DELEGATE METHODS */ | |
| 233 | ||
| 234 | @Override | |
| 235 | public void clear() { | |
| 236 |
1
1. clear : removed call to java/util/Map::clear → NO_COVERAGE |
map.clear(); |
| 237 | } | |
| 238 | ||
| 239 | @Override | |
| 240 | public Object compute(String key, BiFunction<? super String, ? super Object, ?> remappingFunction) { | |
| 241 |
1
1. compute : mutated return of Object value for org/fissore/steroids/SMap::compute to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.compute(key, remappingFunction); |
| 242 | } | |
| 243 | ||
| 244 | @Override | |
| 245 | public Object computeIfAbsent(String key, Function<? super String, ?> mappingFunction) { | |
| 246 |
1
1. computeIfAbsent : mutated return of Object value for org/fissore/steroids/SMap::computeIfAbsent to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.computeIfAbsent(key, mappingFunction); |
| 247 | } | |
| 248 | ||
| 249 | @Override | |
| 250 | public Object computeIfPresent(String key, BiFunction<? super String, ? super Object, ?> remappingFunction) { | |
| 251 |
1
1. computeIfPresent : mutated return of Object value for org/fissore/steroids/SMap::computeIfPresent to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.computeIfPresent(key, remappingFunction); |
| 252 | } | |
| 253 | ||
| 254 | @Override | |
| 255 | public boolean containsKey(Object key) { | |
| 256 |
1
1. containsKey : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return map.containsKey(key); |
| 257 | } | |
| 258 | ||
| 259 | @Override | |
| 260 | public boolean containsValue(Object value) { | |
| 261 |
1
1. containsValue : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return map.containsValue(value); |
| 262 | } | |
| 263 | ||
| 264 | @Override | |
| 265 | public Set<Entry<String, Object>> entrySet() { | |
| 266 |
1
1. entrySet : mutated return of Object value for org/fissore/steroids/SMap::entrySet to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.entrySet(); |
| 267 | } | |
| 268 | ||
| 269 | @Override | |
| 270 | public boolean equals(Object o) { | |
| 271 |
1
1. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return map.equals(o); |
| 272 | } | |
| 273 | ||
| 274 | @Override | |
| 275 | public void forEach(BiConsumer<? super String, ? super Object> action) { | |
| 276 |
1
1. forEach : removed call to java/util/Map::forEach → KILLED |
map.forEach(action); |
| 277 | } | |
| 278 | ||
| 279 | @Override | |
| 280 | public Object get(Object key) { | |
| 281 |
1
1. get : mutated return of Object value for org/fissore/steroids/SMap::get to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return map.get(key); |
| 282 | } | |
| 283 | ||
| 284 | @Override | |
| 285 | public Object getOrDefault(Object key, Object defaultValue) { | |
| 286 |
1
1. getOrDefault : mutated return of Object value for org/fissore/steroids/SMap::getOrDefault to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.getOrDefault(key, defaultValue); |
| 287 | } | |
| 288 | ||
| 289 | @Override | |
| 290 | public int hashCode() { | |
| 291 |
1
1. hashCode : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return map.hashCode(); |
| 292 | } | |
| 293 | ||
| 294 | @Override | |
| 295 | public boolean isEmpty() { | |
| 296 |
1
1. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return map.isEmpty(); |
| 297 | } | |
| 298 | ||
| 299 | @Override | |
| 300 | public Set<String> keySet() { | |
| 301 |
1
1. keySet : mutated return of Object value for org/fissore/steroids/SMap::keySet to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return map.keySet(); |
| 302 | } | |
| 303 | ||
| 304 | @Override | |
| 305 | public Object merge(String key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction) { | |
| 306 |
1
1. merge : mutated return of Object value for org/fissore/steroids/SMap::merge to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.merge(key, value, remappingFunction); |
| 307 | } | |
| 308 | ||
| 309 | @Override | |
| 310 | public Object put(String key, Object value) { | |
| 311 |
1
1. put : mutated return of Object value for org/fissore/steroids/SMap::put to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return map.put(key, value); |
| 312 | } | |
| 313 | ||
| 314 | @Override | |
| 315 | public void putAll(Map<? extends String, ?> m) { | |
| 316 |
1
1. putAll : removed call to java/util/Map::putAll → NO_COVERAGE |
map.putAll(m); |
| 317 | } | |
| 318 | ||
| 319 | @Override | |
| 320 | public Object putIfAbsent(String key, Object value) { | |
| 321 |
1
1. putIfAbsent : mutated return of Object value for org/fissore/steroids/SMap::putIfAbsent to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.putIfAbsent(key, value); |
| 322 | } | |
| 323 | ||
| 324 | @Override | |
| 325 | public Object remove(Object key) { | |
| 326 |
1
1. remove : mutated return of Object value for org/fissore/steroids/SMap::remove to ( if (x != null) null else throw new RuntimeException ) → SURVIVED |
return map.remove(key); |
| 327 | } | |
| 328 | ||
| 329 | @Override | |
| 330 | public boolean remove(Object key, Object value) { | |
| 331 |
1
1. remove : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return map.remove(key, value); |
| 332 | } | |
| 333 | ||
| 334 | @Override | |
| 335 | public boolean replace(String key, Object oldValue, Object newValue) { | |
| 336 |
1
1. replace : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return map.replace(key, oldValue, newValue); |
| 337 | } | |
| 338 | ||
| 339 | @Override | |
| 340 | public Object replace(String key, Object value) { | |
| 341 |
1
1. replace : mutated return of Object value for org/fissore/steroids/SMap::replace to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.replace(key, value); |
| 342 | } | |
| 343 | ||
| 344 | @Override | |
| 345 | public void replaceAll(BiFunction<? super String, ? super Object, ?> function) { | |
| 346 |
1
1. replaceAll : removed call to java/util/Map::replaceAll → NO_COVERAGE |
map.replaceAll(function); |
| 347 | } | |
| 348 | ||
| 349 | @Override | |
| 350 | public int size() { | |
| 351 |
1
1. size : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return map.size(); |
| 352 | } | |
| 353 | ||
| 354 | @Override | |
| 355 | public Collection<Object> values() { | |
| 356 |
1
1. values : mutated return of Object value for org/fissore/steroids/SMap::values to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.values(); |
| 357 | } | |
| 358 | ||
| 359 | @Override | |
| 360 | public String toString() { | |
| 361 |
1
1. toString : mutated return of Object value for org/fissore/steroids/SMap::toString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return map.toString(); |
| 362 | } | |
| 363 | ||
| 364 | } | |
Mutations | ||
| 48 |
1.1 |
|
| 103 |
1.1 |
|
| 108 |
1.1 |
|
| 118 |
1.1 |
|
| 119 |
1.1 |
|
| 124 |
1.1 |
|
| 130 |
1.1 |
|
| 131 |
1.1 |
|
| 133 |
1.1 |
|
| 134 |
1.1 |
|
| 136 |
1.1 |
|
| 137 |
1.1 |
|
| 144 |
1.1 |
|
| 149 |
1.1 |
|
| 154 |
1.1 |
|
| 159 |
1.1 |
|
| 164 |
1.1 |
|
| 169 |
1.1 |
|
| 174 |
1.1 |
|
| 179 |
1.1 |
|
| 184 |
1.1 |
|
| 189 |
1.1 |
|
| 194 |
1.1 |
|
| 199 |
1.1 |
|
| 204 |
1.1 |
|
| 209 |
1.1 |
|
| 214 |
1.1 |
|
| 219 |
1.1 2.2 |
|
| 224 |
1.1 2.2 |
|
| 229 |
1.1 |
|
| 236 |
1.1 |
|
| 241 |
1.1 |
|
| 246 |
1.1 |
|
| 251 |
1.1 |
|
| 256 |
1.1 |
|
| 261 |
1.1 |
|
| 266 |
1.1 |
|
| 271 |
1.1 |
|
| 276 |
1.1 |
|
| 281 |
1.1 |
|
| 286 |
1.1 |
|
| 291 |
1.1 |
|
| 296 |
1.1 |
|
| 301 |
1.1 |
|
| 306 |
1.1 |
|
| 311 |
1.1 |
|
| 316 |
1.1 |
|
| 321 |
1.1 |
|
| 326 |
1.1 |
|
| 331 |
1.1 |
|
| 336 |
1.1 |
|
| 341 |
1.1 |
|
| 346 |
1.1 |
|
| 351 |
1.1 |
|
| 356 |
1.1 |
|
| 361 |
1.1 |