forked from Speiger/Primitive-Collections
Latest changes.
-Added: Maps -Added: UnaryOperator -Changed: Variables for better naming. -Upgraded: Simple CodeGenerator bugs with recursion were fixed.
This commit is contained in:
parent
42458bc4a3
commit
f006c19db6
Binary file not shown.
Binary file not shown.
|
@ -130,15 +130,6 @@ public enum ClassType
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean hasBiFunction(ClassType other)
|
||||
{
|
||||
if(this == other && this != BOOLEAN && !needsCustomJDKType() && !other.needsCustomJDKType()) return true;
|
||||
if(this == BOOLEAN) return false;
|
||||
if(other == BOOLEAN && this == OBJECT) return true;
|
||||
if(!other.needsCustomJDKType() && this == OBJECT) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getFunctionClass(ClassType other)
|
||||
{
|
||||
if(!hasFunction(other)) return "";
|
||||
|
@ -149,15 +140,6 @@ public enum ClassType
|
|||
return "";
|
||||
}
|
||||
|
||||
public String getBiFunctionClass(ClassType other)
|
||||
{
|
||||
if(!hasBiFunction(other)) return "";
|
||||
if(this == other && this != BOOLEAN) return this == OBJECT ? "java.util.function.BiFunction" : "java.util.function."+getJavaFileType()+"BinaryOperator";
|
||||
if(other == BOOLEAN && this == OBJECT) return "java.util.function.BiPredicate";
|
||||
if(!other.needsCustomJDKType() && this == OBJECT) return "java.util.function.To"+other.getJavaFileType()+"BiFunction";
|
||||
return "";
|
||||
}
|
||||
|
||||
public ClassType getCustomJDKType()
|
||||
{
|
||||
switch(this)
|
||||
|
|
|
@ -29,6 +29,7 @@ public class GlobalVariables
|
|||
|
||||
public GlobalVariables createVariables()
|
||||
{
|
||||
addSimpleMapper("VALUE_PACKAGE", valueType.getPathType());
|
||||
addSimpleMapper("PACKAGE", type.getPathType());
|
||||
addSimpleMapper("CLASS_TYPE", type.getClassType());
|
||||
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
|
||||
|
@ -39,15 +40,18 @@ public class GlobalVariables
|
|||
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
|
||||
|
||||
addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" KEY_KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+", "+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""));
|
||||
addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "<?>" : "");
|
||||
addSimpleMapper(" KEY_COMPAREABLE_TYPE", type.isObject() ? "<"+type.getKeyType()+" extends Comparable<T>>" : "");
|
||||
addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "<? super "+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "<? super "+valueType.getKeyType()+">" : "");
|
||||
addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? super "+type.getKeyType()+", ? super "+valueType.getValueType()+">" : "<? super "+type.getKeyType()+">") : (valueType.isObject() ? "<? super "+valueType.getValueType()+">" : ""));
|
||||
|
||||
|
||||
addSimpleMapper(" GENERIC_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : "");
|
||||
addSimpleMapper(" GENERIC_VALUE_BRACES", type.isObject() ? " <"+valueType.getValueType()+">" : "");
|
||||
addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+", "+valueType.getValueType()+">" : " <"+type.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
||||
|
@ -71,6 +75,8 @@ public class GlobalVariables
|
|||
addInjectMapper("KEY_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces();
|
||||
addArgumentMapper("KEY_EQUALS_NOT", type.getEquals(true)).removeBraces();
|
||||
addArgumentMapper("KEY_EQUALS", type.getEquals(false)).removeBraces();
|
||||
addArgumentMapper("VALUE_EQUALS_NOT", valueType.getEquals(true)).removeBraces();
|
||||
addArgumentMapper("VALUE_EQUALS", valueType.getEquals(false)).removeBraces();
|
||||
|
||||
addArgumentMapper("COMPARE_TO_KEY", type.isObject() ? "((Comparable<T>)%1$s).compareTo((T)%2$s)" : type.getClassType()+".compare(%1$s, %2$s)").removeBraces();
|
||||
addArgumentMapper("COMPARE_TO", type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType()+".compare(%1$s, %2$s)").removeBraces();
|
||||
|
@ -81,7 +87,7 @@ public class GlobalVariables
|
|||
|
||||
addInjectMapper("VALUE_TO_OBJ", valueType.isObject() ? "%s" : valueType.getClassType()+".valueOf(%s)").removeBraces();
|
||||
addInjectMapper("OBJ_TO_VALUE", valueType.isObject() ? "%s" : "%s."+valueType.getKeyType()+"Value()").removeBraces();
|
||||
addInjectMapper("CLASS_TO_VALUE", "(("+valueType.getClassType()+")%s)."+valueType.getKeyType()+"Value()").removeBraces();
|
||||
addInjectMapper("CLASS_TO_VALUE", "(("+valueType.getClassValueType()+")%s)."+valueType.getValueType()+"Value()").removeBraces();
|
||||
|
||||
addInjectMapper("KEY_TO_HASH", type.isObject() ? "%s.hashCode()" : type.getClassType()+".hashCode(%s)").removeBraces();
|
||||
|
||||
|
@ -97,13 +103,19 @@ public class GlobalVariables
|
|||
return this;
|
||||
}
|
||||
|
||||
public GlobalVariables createPreFunctions()
|
||||
{
|
||||
addSimpleMapper("ENTRY_SET", type.getFileType().toLowerCase()+"2"+valueType.getFileType()+"EntrySet");
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalVariables createClassTypes()
|
||||
{
|
||||
addSimpleMapper("JAVA_PREDICATE", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Predicate");
|
||||
addSimpleMapper("JAVA_CONSUMER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Consumer");
|
||||
addSimpleMapper("JAVA_FUNCTION", type.getFunctionClass(valueType));
|
||||
addSimpleMapper("JAVA_BI_FUNCTION", type.getBiFunctionClass(valueType));
|
||||
addSimpleMapper("UNARY_OPERATOR", type.isObject() ? "" : type == ClassType.BOOLEAN ? "BinaryOperator" : type.getCustomJDKType().getFileType()+"UnaryOperator");
|
||||
addSimpleMapper("JAVA_BINARY_OPERATOR", type == ClassType.BOOLEAN ? "" : (type.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+type.getCustomJDKType().getFileType()+"BinaryOperator"));
|
||||
addSimpleMapper("JAVA_UNARY_OPERATOR", type.isObject() ? "BinaryOperator" : type == ClassType.BOOLEAN ? "" : type.getCustomJDKType().getFileType()+"UnaryOperator");
|
||||
|
||||
//Final Classes
|
||||
addClassMapper("ARRAY_LIST", "ArrayList");
|
||||
|
@ -130,18 +142,19 @@ public class GlobalVariables
|
|||
addClassMapper("COLLECTIONS", "Collections");
|
||||
addClassMapper("ARRAYS", "Arrays");
|
||||
addClassMapper("ITERATORS", "Iterators");
|
||||
addBiClassMapper("MAPS", "Maps", "2");
|
||||
|
||||
//Interfaces
|
||||
addClassMapper("LIST_ITERATOR", "ListIterator");
|
||||
addClassMapper("BI_ITERATOR", "BidirectionalIterator");
|
||||
addBiClassMapper("BI_CONSUMER", "Consumer", "");
|
||||
addBiClassMapper("BI_FUNCTION", "BiFunction", "2");
|
||||
addClassMapper("ITERATOR", "Iterator");
|
||||
addClassMapper("ITERABLE", "Iterable");
|
||||
addClassMapper("COLLECTION", "Collection");
|
||||
addBiClassMapper("FUNCTION", "Function", "2");
|
||||
addClassMapper("LIST_ITER", "ListIter");
|
||||
addClassMapper("LIST", "List");
|
||||
addBiClassMapper("MAP", "Map", "2");
|
||||
addClassMapper("NAVIGABLE_SET", "NavigableSet");
|
||||
addClassMapper("PRIORITY_QUEUE", "PriorityQueue");
|
||||
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
|
||||
|
@ -149,6 +162,7 @@ public class GlobalVariables
|
|||
addClassMapper("SET", "Set");
|
||||
addClassMapper("STRATEGY", "Strategy");
|
||||
addClassMapper("STACK", "Stack");
|
||||
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
||||
if(type.isObject())
|
||||
{
|
||||
addSimpleMapper("CONSUMER", "Consumer");
|
||||
|
@ -166,30 +180,38 @@ public class GlobalVariables
|
|||
|
||||
public GlobalVariables createFunctions()
|
||||
{
|
||||
addSimpleMapper("APPLY_VALUE", "applyAs"+valueType.getCustomJDKType().getNonFileType());
|
||||
addSimpleMapper("APPLY", "applyAs"+type.getCustomJDKType().getNonFileType());
|
||||
addFunctionMapper("NEXT", "next");
|
||||
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
|
||||
addFunctionMapper("GET_KEY", "get");
|
||||
addFunctionValueMapper("GET_VALUE", "get");
|
||||
addSimpleMapper("APPLY_VALUE", "applyAs"+valueType.getNonFileType());
|
||||
addSimpleMapper("APPLY_CAST", "applyAs"+type.getCustomJDKType().getNonFileType());
|
||||
addSimpleMapper("APPLY", "applyAs"+type.getNonFileType());
|
||||
addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent");
|
||||
addFunctionValueMappers("COMPUTE_IF_PRESENT", "compute%sIfPresent");
|
||||
addFunctionValueMapper("COMPUTE", "compute");
|
||||
addFunctionMapper("ENQUEUE_FIRST", "enqueueFirst");
|
||||
addFunctionMapper("ENQUEUE", "enqueue");
|
||||
addFunctionMapper("DEQUEUE_LAST", "dequeueLast");
|
||||
addFunctionMapper("DEQUEUE", "dequeue");
|
||||
addFunctionMapper("REMOVE_KEY", "rem");
|
||||
addFunctionMapper("REMOVE_LAST", "removeLast");
|
||||
addFunctionMapper("REMOVE", "remove");
|
||||
addFunctionMappers("ENTRY_KEY", "get%sKey");
|
||||
addFunctionValueMappers("ENTRY_VALUE", "get%sValue");
|
||||
addFunctionMapper("POLL_FIRST_KEY", "pollFirst");
|
||||
addFunctionMapper("POLL_LAST_KEY", "pollLast");
|
||||
addFunctionMapper("FIRST_KEY", "first");
|
||||
addFunctionMapper("GET_KEY", "get");
|
||||
addFunctionValueMapper("GET_VALUE", "get");
|
||||
addFunctionMapper("LAST_KEY", "last");
|
||||
addFunctionValueMapper("MERGE", "merge");
|
||||
addFunctionMapper("NEXT", "next");
|
||||
addFunctionMapper("PREVIOUS", "previous");
|
||||
addFunctionMapper("PEEK", "peek");
|
||||
addFunctionMapper("POP", "pop");
|
||||
addFunctionMapper("PUSH", "push");
|
||||
addFunctionMapper("TOP", "top");
|
||||
addFunctionMappers("REPLACE", "replace%ss");
|
||||
addFunctionMapper("REMOVE_KEY", "rem");
|
||||
addFunctionMapper("REMOVE_LAST", "removeLast");
|
||||
addFunctionMapper("REMOVE", "remove");
|
||||
addFunctionValueMappers("REPLACE_VALUES", valueType.isObject() ? "replaceObjects" : "replace%ss");
|
||||
addFunctionMappers("REPLACE", type.isObject() ? "replaceObjects" : "replace%ss");
|
||||
addFunctionMappers("SORT", "sort%ss");
|
||||
addFunctionMapper("POLL_FIRST_KEY", "pollFirst");
|
||||
addFunctionMapper("FIRST_KEY", "first");
|
||||
addFunctionMapper("POLL_LAST_KEY", "pollLast");
|
||||
addFunctionMapper("LAST_KEY", "last");
|
||||
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
|
||||
addFunctionMapper("TOP", "top");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -199,10 +221,9 @@ public class GlobalVariables
|
|||
flags.add("VALUE_"+valueType.getCapType());
|
||||
if(type == valueType) flags.add("SAME_TYPE");
|
||||
if(type.hasFunction(valueType)) flags.add("JDK_FUNCTION");
|
||||
if(type.hasBiFunction(valueType)) flags.add("JDK_BI_FUNCTION");
|
||||
if(!type.needsCustomJDKType()) flags.add("JDK_TYPE");
|
||||
if(!type.isPrimitiveBlocking()) flags.add("PRIMITIVES");
|
||||
if(valueType.isPrimitiveBlocking()) flags.add("VALUE_PRIMITIVES");
|
||||
if(!valueType.isPrimitiveBlocking()) flags.add("VALUE_PRIMITIVES");
|
||||
if(valueType.needsCustomJDKType()) flags.add("JDK_VALUE");
|
||||
return this;
|
||||
}
|
||||
|
@ -232,14 +253,15 @@ public class GlobalVariables
|
|||
|
||||
private void addClassMapper(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+replacement));
|
||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+replacement));
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+replacement));
|
||||
}
|
||||
|
||||
private void addBiClassMapper(String pattern, String replacement, String splitter)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"[KEY_"+pattern+"]", "KEY_"+pattern, type.getFileType()+splitter+type.getFileType()+replacement));
|
||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+splitter+valueType.getFileType()+replacement));
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+splitter+valueType.getFileType()+replacement));
|
||||
|
||||
}
|
||||
|
||||
private void addAbstractMapper(String pattern, String replacement)
|
||||
|
@ -262,6 +284,11 @@ public class GlobalVariables
|
|||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getNonFileType())));
|
||||
}
|
||||
|
||||
private void addFunctionValueMappers(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, valueType.getNonFileType())));
|
||||
}
|
||||
|
||||
private void addSimpleMapper(String pattern, String replacement)
|
||||
{
|
||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement));
|
||||
|
|
|
@ -27,6 +27,11 @@ public class TestBuilder extends TemplateProcessor
|
|||
super(Paths.get("src/main/resources/speiger/assets/collections/templates/"), Paths.get("src/main/java/speiger/src/collections/"), Paths.get("src/main/resources/speiger/assets/collections/"));
|
||||
}
|
||||
|
||||
public TestBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
|
||||
{
|
||||
super(sourceFolder, outputFolder, dataFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFileValid(Path fileName)
|
||||
{
|
||||
|
@ -58,7 +63,9 @@ public class TestBuilder extends TemplateProcessor
|
|||
}
|
||||
biRequired.put("BiConsumer", "");
|
||||
biRequired.put("Function", "2");
|
||||
biRequired.put("BiFunction", "2");
|
||||
biRequired.put("UnaryOperator", "");
|
||||
biRequired.put("Map", "2");
|
||||
biRequired.put("Maps", "2");
|
||||
nameRemapper.put("BiConsumer", "%sConsumer");
|
||||
nameRemapper.put("IArray", "I%sArray");
|
||||
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
|
||||
|
@ -74,6 +81,7 @@ public class TestBuilder extends TemplateProcessor
|
|||
type.createFlags();
|
||||
type.createHelperVariables();
|
||||
type.createVariables();
|
||||
type.createPreFunctions();
|
||||
type.createClassTypes();
|
||||
type.createFunctions();
|
||||
if(mainType == subType) variables.add(type);
|
||||
|
@ -122,7 +130,14 @@ public class TestBuilder extends TemplateProcessor
|
|||
{
|
||||
try
|
||||
{
|
||||
new TestBuilder().process(false);
|
||||
if(args.length == 0) {
|
||||
new TestBuilder().process(false);
|
||||
} else if(args.length == 3) {
|
||||
new TestBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(false);
|
||||
} else {
|
||||
System.out.println("Invalid argument count passed in");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
catch(InterruptedException e)
|
||||
{
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package speiger.src.collections.PACKAGE.functions.function;
|
||||
|
||||
@FunctionalInterface
|
||||
#if JDK_BI_FUNCTION
|
||||
public interface BI_FUNCTION KEY_VALUE_GENERIC_TYPE extends JAVA_BI_FUNCTION KEY_KEY_VALUE_GENERIC_TYPE
|
||||
#else
|
||||
public interface BI_FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE k, KEY_TYPE v);
|
||||
#if JDK_BI_FUNCTION
|
||||
#if VALUE_BOOLEAN
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE test(KEY_TYPE k, KEY_TYPE v) { return GET_VALUE(k, v); }
|
||||
#else if VALUE_OBJECT
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE apply(KEY_TYPE k, KEY_TYPE v) { return GET_VALUE(k, v); }
|
||||
#else
|
||||
|
||||
@Override
|
||||
public default VALUE_TYPE APPLY_VALUE(KEY_TYPE k, KEY_TYPE v) { return GET_VALUE(k, v); }
|
||||
#endif
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package speiger.src.collections.PACKAGE.functions.function;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
#if !SAME_TYPE || TYPE_BOOLEAN || !JDK_TYPE
|
||||
public interface UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE extends BiFunction<CLASS_TYPE, CLASS_VALUE_TYPE, CLASS_VALUE_TYPE>
|
||||
#else
|
||||
#if SAME_TYPE && TYPE_OBJECT
|
||||
public interface UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE extends BiFunction<CLASS_TYPE, CLASS_VALUE_TYPE, CLASS_VALUE_TYPE>
|
||||
#else
|
||||
public interface UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE extends BiFunction<CLASS_TYPE, CLASS_VALUE_TYPE, CLASS_VALUE_TYPE>, JAVA_BINARY_OPERATOR
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
#else if SAME_TYPE && !TYPE_OBJECT && JDK_TYPE && !TYPE_BOOLEAN
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE apply(CLASS_TYPE k, CLASS_VALUE_TYPE v) { return VALUE_TO_OBJ(APPLY_VALUE(OBJ_TO_KEY(k), OBJ_TO_VALUE(v))); }
|
||||
#else
|
||||
public VALUE_TYPE APPLY_VALUE(KEY_TYPE k, VALUE_TYPE v);
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE apply(CLASS_TYPE k, CLASS_VALUE_TYPE v) { return VALUE_TO_OBJ(APPLY_VALUE(OBJ_TO_KEY(k), OBJ_TO_VALUE(v))); }
|
||||
#endif
|
||||
}
|
|
@ -14,7 +14,7 @@ import java.util.function.Predicate;
|
|||
import java.util.function.UnaryOperator;
|
||||
#if PRIMITIVES
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
import java.util.function.UNARY_OPERATOR;
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
|
@ -595,10 +595,10 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||
* @throws NullPointerException if o is null
|
||||
*/
|
||||
@Override
|
||||
public void REPLACE(UNARY_OPERATOR o) {
|
||||
public void REPLACE(JAVA_UNARY_OPERATOR o) {
|
||||
for(int i = 0;i<size;i++)
|
||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||
data[i] = SanityChecks.SANITY_CAST(o.APPLY(data[i]));
|
||||
data[i] = SanityChecks.SANITY_CAST(o.APPLY_CAST(data[i]));
|
||||
#else
|
||||
data[i] = o.APPLY(data[i]);
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,7 @@ package speiger.src.collections.PACKAGE.lists;
|
|||
import java.util.List;
|
||||
#if !TYPE_OBJECT && !TYPE_BOOLEAN
|
||||
import java.util.Objects;
|
||||
import java.util.function.UNARY_OPERATOR;
|
||||
import java.util.function.JAVA_UNARY_OPERATOR;
|
||||
import java.util.function.UnaryOperator;
|
||||
#else if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
|
@ -115,12 +115,12 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||
* @param o the action to replace the values
|
||||
* @throws NullPointerException if o is null
|
||||
*/
|
||||
public default void REPLACE(UNARY_OPERATOR o) {
|
||||
public default void REPLACE(JAVA_UNARY_OPERATOR o) {
|
||||
Objects.requireNonNull(o);
|
||||
LIST_ITERATOR iter = listIterator();
|
||||
while (iter.hasNext())
|
||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||
iter.set(SanityChecks.SANITY_CAST(o.APPLY(iter.NEXT())));
|
||||
iter.set(SanityChecks.SANITY_CAST(o.APPLY_CAST(iter.NEXT())));
|
||||
#else
|
||||
iter.set(o.APPLY(iter.NEXT()));
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,196 @@
|
|||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
import java.util.Map;
|
||||
#if VALUE_OBJECT && !TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
|
||||
public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_TYPE>, FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
public VALUE_TYPE getDefaultReturnValue();
|
||||
public MAP KEY_VALUE_GENERIC_TYPE setDefaultReturnValue(VALUE_TYPE v);
|
||||
|
||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value);
|
||||
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value);
|
||||
#if VALUE_PRIMITIVES
|
||||
public boolean addTo(KEY_TYPE key, VALUE_TYPE value);
|
||||
#endif
|
||||
|
||||
public void putAll(MAP KEY_VALUE_GENERIC_TYPE m);
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
public boolean containsKey(KEY_TYPE key);
|
||||
|
||||
@Override
|
||||
public default boolean containsKey(Object key) {
|
||||
return key instanceof CLASS_TYPE && containsKey(CLASS_TO_KEY(key));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if !VALUE_OBJECT
|
||||
public boolean containsValue(VALUE_TYPE value);
|
||||
|
||||
@Override
|
||||
public default boolean containsValue(Object value) {
|
||||
return value instanceof CLASS_VALUE_TYPE && containsValue(CLASS_TO_VALUE(value));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
public VALUE_TYPE remove(KEY_TYPE key);
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE remove(Object key) {
|
||||
return key instanceof CLASS_TYPE ? VALUE_TO_OBJ(remove(CLASS_TO_KEY(key))) : VALUE_TO_OBJ(getDefaultReturnValue());
|
||||
}
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
public boolean remove(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
@Override
|
||||
public default boolean remove(Object key, Object value) {
|
||||
#if TYPE_OBJECT
|
||||
return value instanceof CLASS_VALUE_TYPE && remove((KEY_TYPE)key, CLASS_TO_VALUE(value));
|
||||
#else if VALUE_OBJECT
|
||||
return key instanceof CLASS_TYPE && remove(CLASS_TO_KEY(key), (VALUE_TYPE)value);
|
||||
#else
|
||||
return key instanceof CLASS_TYPE && value instanceof CLASS_VALUE_TYPE && remove(CLASS_TO_KEY(key), CLASS_TO_VALUE(value));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
public boolean replace(KEY_TYPE key, VALUE_TYPE oldValue, VALUE_TYPE newValue);
|
||||
public VALUE_TYPE replace(KEY_TYPE key, VALUE_TYPE value);
|
||||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction);
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public default boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue) {
|
||||
return replace(OBJ_TO_KEY(key), OBJ_TO_VALUE(oldValue), OBJ_TO_VALUE(newValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||
return VALUE_TO_OBJ(replace(OBJ_TO_KEY(key), OBJ_TO_VALUE(value)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key);
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue);
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE get(Object key) {
|
||||
#if TYPE_OBJECT
|
||||
return VALUE_TO_OBJ(GET_VALUE((CLASS_TYPE)key));
|
||||
#else
|
||||
return VALUE_TO_OBJ(key instanceof CLASS_TYPE ? GET_VALUE(CLASS_TO_KEY(key)) : getDefaultReturnValue());
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
|
||||
#if TYPE_OBJECT
|
||||
CLASS_VALUE_TYPE value = VALUE_TO_OBJ(GET_VALUE((CLASS_TYPE)key));
|
||||
#else
|
||||
CLASS_VALUE_TYPE value = VALUE_TO_OBJ(key instanceof CLASS_TYPE ? GET_VALUE(CLASS_TO_KEY(key)) : getDefaultReturnValue());
|
||||
#endif
|
||||
return VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key) ? value : defaultValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public default void replaceAll(BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
REPLACE_VALUES(mappingFunction instanceof UNARY_OPERATOR ? (UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE)mappingFunction : (K, V) -> OBJ_TO_VALUE(mappingFunction.apply(KEY_TO_OBJ(K), VALUE_TO_OBJ(V))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE compute(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return VALUE_TO_OBJ(COMPUTE(OBJ_TO_KEY(key), mappingFunction instanceof UNARY_OPERATOR ? (UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE)mappingFunction : (K, V) -> OBJ_TO_VALUE(mappingFunction.apply(KEY_TO_OBJ(K), VALUE_TO_OBJ(V)))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE computeIfAbsent(CLASS_TYPE key, Function<? super CLASS_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return VALUE_TO_OBJ(COMPUTE_IF_ABSENT(OBJ_TO_KEY(key), mappingFunction instanceof FUNCTION ? (FUNCTION KEY_VALUE_GENERIC_TYPE)mappingFunction : K -> OBJ_TO_VALUE(mappingFunction.apply(KEY_TO_OBJ(K)))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE computeIfPresent(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return VALUE_TO_OBJ(COMPUTE_IF_PRESENT(OBJ_TO_KEY(key), mappingFunction instanceof UNARY_OPERATOR ? (UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE)mappingFunction : (K, V) -> OBJ_TO_VALUE(mappingFunction.apply(KEY_TO_OBJ(K), VALUE_TO_OBJ(V)))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE merge(CLASS_TYPE key, CLASS_VALUE_TYPE value, BiFunction<? super CLASS_VALUE_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return VALUE_TO_OBJ(MERGE(OBJ_TO_KEY(key), OBJ_TO_VALUE(value), mappingFunction instanceof VALUE_UNARY_OPERATOR ? (VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE)mappingFunction : (K, V) -> OBJ_TO_VALUE(mappingFunction.apply(VALUE_TO_OBJ(K), VALUE_TO_OBJ(V)))));
|
||||
}
|
||||
|
||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action);
|
||||
|
||||
@Override
|
||||
public default void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) {
|
||||
forEach(action instanceof BI_CONSUMER ? (BI_CONSUMER KEY_VALUE_GENERIC_TYPE)action : (K, V) -> action.accept(KEY_TO_OBJ(K), VALUE_TO_OBJ(V)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet();
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values();
|
||||
@Override
|
||||
public ObjectSet<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> entrySet();
|
||||
public ObjectSet<Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE put(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||
return VALUE_TO_OBJ(put(OBJ_TO_KEY(key), OBJ_TO_VALUE(value)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||
return VALUE_TO_OBJ(put(OBJ_TO_KEY(key), OBJ_TO_VALUE(value)));
|
||||
}
|
||||
#endif
|
||||
public interface FastEntrySet KEY_VALUE_GENERIC_TYPE extends ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||
{
|
||||
public ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
|
||||
public default void fastForEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
forEach(action);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Entry KEY_VALUE_GENERIC_TYPE extends Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
public KEY_TYPE ENTRY_KEY();
|
||||
public default CLASS_TYPE getKey() { return KEY_TO_OBJ(ENTRY_KEY()); }
|
||||
#endif
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
public VALUE_TYPE ENTRY_VALUE();
|
||||
public VALUE_TYPE setValue(VALUE_TYPE value);
|
||||
public default CLASS_VALUE_TYPE getValue() { return VALUE_TO_OBJ(ENTRY_VALUE()); }
|
||||
public default CLASS_VALUE_TYPE setValue(CLASS_VALUE_TYPE value) { return VALUE_TO_OBJ(setValue(OBJ_TO_VALUE(value))); }
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package speiger.src.collections.PACKAGE.utils.maps;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
|
||||
public class MAPS
|
||||
{
|
||||
public static GENERIC_KEY_VALUE_BRACES ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entries = map.ENTRY_SET();
|
||||
return entries instanceof MAP.FastEntrySet ? ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastIterator() : entries.iterator();
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_VALUE_BRACES ObjectIterable<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterable(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entries = map.ENTRY_SET();
|
||||
return map instanceof MAP.FastEntrySet ? new ObjectIterable<MAP.Entry KEY_VALUE_GENERIC_TYPE>(){
|
||||
@Override
|
||||
public ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() { return ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastIterator(); }
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastForEach(action); }
|
||||
} : entries;
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_VALUE_BRACES void fastForEach(MAP KEY_VALUE_GENERIC_TYPE map, Consumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entries = map.ENTRY_SET();
|
||||
if(entries instanceof MAP.FastEntrySet) ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastForEach(action);
|
||||
else entries.forEach(action);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue