MCPcopy Index your code
hub / github.com/OpenEndedGroup/Field2 / IdempotencyMap

Class IdempotencyMap

src/main/java/field/utility/IdempotencyMap.java:16–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14public class IdempotencyMap<T> extends LinkedHashMapAndArrayList<T> implements Mutable<IdempotencyMap<T>>, fieldlinker.AsMap, HandlesCompletion {
15
16 private final Class<? extends T> t;
17 private Function<String, T> autoConstructor;
18
19 public IdempotencyMap(Class t) {
20 this.t = t;
21 }
22
23 public IdempotencyMap<T> setAutoconstruct(Function<String, T> auto) {
24 this.autoConstructor = auto;
25 return this;
26 }
27
28
29 public IdempotencyMap<T> setAutoconstruct(Class clazz) {
30 this.autoConstructor = (k) -> {
31 try {
32 return (T) clazz.newInstance();
33 } catch (InstantiationException e) {
34 e.printStackTrace();
35 } catch (IllegalAccessException e) {
36 e.printStackTrace();
37 }
38 return null;
39 };
40 return this;
41 }
42
43 @Override
44 protected T massage(Object value) {
45 if (t == null) return (T) value;
46 if (value == null) return null;
47 if (t.isAssignableFrom(value.getClass())) return (T) value;
48
49 Object ovalue = value;
50
51 if (value instanceof ScriptObjectMirror)
52 value = ScriptUtils.unwrap(value);
53
54 value = Conversions.convert(value, t);
55
56 if (value != null && t.isAssignableFrom(value.getClass())) return (T) value;
57
58 if (value == null) {
59 throw new ClassCastException(" couldn't convert " + ovalue + " of class " + ovalue.getClass() + " to " + t);
60 }
61 if (!t.isAssignableFrom(value.getClass()))
62 throw new ClassCastException(" expected " + t + ", got " + value + " / " + value.getClass());
63
64 return (T) value;
65 }
66
67 @Override
68 public IdempotencyMap<T> duplicate() {
69 IdempotencyMap<T> r = new IdempotencyMap<>(t);
70
71 for (Map.Entry<String, T> e : this.entrySet()) {
72 r.put(e.getKey(), e.getValue() instanceof Mutable ? ((Mutable) e.getValue()).duplicate() : e.getValue());
73 }

Callers 13

StandardLinesClass · 0.85
StandardTextClass · 0.85
InMidiClass · 0.85
PhysicsSystemClass · 0.85
ShaderGroupClass · 0.85
StandardClass · 0.85
SimpleButtonsClass · 0.85
RPCClass · 0.85
ButtonsClass · 0.85
SimpleMouseClass · 0.85
FibreClass · 0.85
addAxisMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected