|
@@ -2,13 +2,15 @@ package net.ranides.assira.collection.prototype;
|
|
|
|
|
|
|
|
import net.ranides.assira.collection.iterators.RemoveIterator;
|
|
import net.ranides.assira.collection.iterators.RemoveIterator;
|
|
|
import net.ranides.assira.collection.maps.AEntry;
|
|
import net.ranides.assira.collection.maps.AEntry;
|
|
|
|
|
+import net.ranides.assira.collection.maps.AMap;
|
|
|
|
|
+import net.ranides.assira.collection.maps.GenericKey;
|
|
|
import net.ranides.assira.collection.sets.SetUtils;
|
|
import net.ranides.assira.collection.sets.SetUtils;
|
|
|
import net.ranides.assira.reflection.*;
|
|
import net.ranides.assira.reflection.*;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
-public class PrototypeMap implements Map<Object, Object> {
|
|
|
|
|
|
|
+public class PrototypeMap extends AMap<Object, Object> implements Map<Object, Object> {
|
|
|
|
|
|
|
|
public static final PrototypeMap EMPTY = new PrototypeMap(true);
|
|
public static final PrototypeMap EMPTY = new PrototypeMap(true);
|
|
|
|
|
|
|
@@ -135,8 +137,8 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
|
|
|
|
|
public final Optional<PrototypeEntry<?>> getProperty(Object key) {
|
|
public final Optional<PrototypeEntry<?>> getProperty(Object key) {
|
|
|
if(containsKey(key)) {
|
|
if(containsKey(key)) {
|
|
|
- if(key instanceof PrototypeKey<?>) {
|
|
|
|
|
- return Optional.of(new FieldEntry<>((PrototypeKey<?>)key));
|
|
|
|
|
|
|
+ if(key instanceof GenericKey<?,?>) {
|
|
|
|
|
+ return Optional.of(new FieldEntry<>((GenericKey<?,?>)key));
|
|
|
}
|
|
}
|
|
|
if(key instanceof String) {
|
|
if(key instanceof String) {
|
|
|
return Optional.of(new NameEntry((String)key));
|
|
return Optional.of(new NameEntry((String)key));
|
|
@@ -152,7 +154,7 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
return Optional.empty();
|
|
return Optional.empty();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public final <V> Optional<PrototypeEntry<V>> getProperty(PrototypeKey<V> key) {
|
|
|
|
|
|
|
+ public final <V> Optional<PrototypeEntry<V>> getProperty(GenericKey<?,V> key) {
|
|
|
if(containsKey(key)) {
|
|
if(containsKey(key)) {
|
|
|
return Optional.of(new FieldEntry<>(key));
|
|
return Optional.of(new FieldEntry<>(key));
|
|
|
}
|
|
}
|
|
@@ -167,7 +169,7 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
return containsKey((Object)key);
|
|
return containsKey((Object)key);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public final boolean containsKey(PrototypeKey<?> key) {
|
|
|
|
|
|
|
+ public final boolean containsKey(GenericKey<?,?> key) {
|
|
|
return containsKey((Object)key);
|
|
return containsKey((Object)key);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -175,22 +177,22 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
return put((Object)key, value);
|
|
return put((Object)key, value);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public final <V> V put(PrototypeKey<V> key, V value) {
|
|
|
|
|
|
|
+ public final <V> V put(GenericKey<?,V> key, V value) {
|
|
|
if(key == null) {
|
|
if(key == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- return key.type().cast(put((Object)key, value));
|
|
|
|
|
|
|
+ return key.cast(put((Object)key, value));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public final Object get(String key) {
|
|
public final Object get(String key) {
|
|
|
return get((Object)key);
|
|
return get((Object)key);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public final <V> V get(PrototypeKey<V> key) {
|
|
|
|
|
|
|
+ public final <V> V get(GenericKey<?,V> key) {
|
|
|
if(key == null) {
|
|
if(key == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- return key.type().cast(get((Object)key));
|
|
|
|
|
|
|
+ return key.cast(get((Object)key));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public final Optional<Object> getOptional(Object key) {
|
|
public final Optional<Object> getOptional(Object key) {
|
|
@@ -201,7 +203,7 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
return Optional.ofNullable(get(key));
|
|
return Optional.ofNullable(get(key));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public final <V> Optional<V> getOptional(PrototypeKey<V> key) {
|
|
|
|
|
|
|
+ public final <V> Optional<V> getOptional(GenericKey<?,V> key) {
|
|
|
return Optional.ofNullable(get(key));
|
|
return Optional.ofNullable(get(key));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -209,11 +211,11 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
return remove((Object)key);
|
|
return remove((Object)key);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public final <V> V remove(PrototypeKey<V> key) {
|
|
|
|
|
|
|
+ public final <V> V remove(GenericKey<?,V> key) {
|
|
|
if(key == null) {
|
|
if(key == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- return key.type().cast(remove((Object)key));
|
|
|
|
|
|
|
+ return key.cast(remove((Object)key));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected void forEachScope(Consumer<Map<Object, Object>> consumer) {
|
|
protected void forEachScope(Consumer<Map<Object, Object>> consumer) {
|
|
@@ -226,7 +228,7 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
if(key instanceof String) {
|
|
if(key instanceof String) {
|
|
|
return new NameEntry((String) key);
|
|
return new NameEntry((String) key);
|
|
|
} else {
|
|
} else {
|
|
|
- return new FieldEntry<>((PrototypeKey<?>)key);
|
|
|
|
|
|
|
+ return new FieldEntry<>((GenericKey<?,?>)key);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -245,8 +247,8 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
Object key = entry.getKey();
|
|
Object key = entry.getKey();
|
|
|
Object val = entry.getValue();
|
|
Object val = entry.getValue();
|
|
|
|
|
|
|
|
- if(key instanceof PrototypeKey<?>) {
|
|
|
|
|
- PrototypeKey<?> field = (PrototypeKey<?>) key;
|
|
|
|
|
|
|
+ if(key instanceof GenericKey<?,?>) {
|
|
|
|
|
+ GenericKey<?,?> field = (GenericKey<?,?>) key;
|
|
|
if(!field.type().isInstance(val)) {
|
|
if(!field.type().isInstance(val)) {
|
|
|
throw new ClassCastException(val + " can't be cast to " + field.type());
|
|
throw new ClassCastException(val + " can't be cast to " + field.type());
|
|
|
}
|
|
}
|
|
@@ -370,11 +372,6 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
return IClass.OBJECT;
|
|
return IClass.OBJECT;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public String getName() {
|
|
|
|
|
- return name;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Object getKey() {
|
|
public Object getKey() {
|
|
|
return name;
|
|
return name;
|
|
@@ -392,9 +389,9 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private final class FieldEntry<V> extends AEntry<Object, V> implements PrototypeEntry<V> {
|
|
private final class FieldEntry<V> extends AEntry<Object, V> implements PrototypeEntry<V> {
|
|
|
- private final PrototypeKey<V> field;
|
|
|
|
|
|
|
+ private final GenericKey<?,V> field;
|
|
|
|
|
|
|
|
- public FieldEntry(PrototypeKey<V> field) {
|
|
|
|
|
|
|
+ public FieldEntry(GenericKey<?,V> field) {
|
|
|
this.field = field;
|
|
this.field = field;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -403,11 +400,6 @@ public class PrototypeMap implements Map<Object, Object> {
|
|
|
return field.type();
|
|
return field.type();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public String getName() {
|
|
|
|
|
- return field.name();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Object getKey() {
|
|
public Object getKey() {
|
|
|
return field;
|
|
return field;
|