diff --git a/libs/Simple Code Generator-1.0.1-sources.jar b/libs/Simple Code Generator-1.0.1-sources.jar index 3033ef5d..ed45e488 100644 Binary files a/libs/Simple Code Generator-1.0.1-sources.jar and b/libs/Simple Code Generator-1.0.1-sources.jar differ diff --git a/libs/Simple Code Generator-1.0.1.jar b/libs/Simple Code Generator-1.0.1.jar index e21ac446..72d45d18 100644 Binary files a/libs/Simple Code Generator-1.0.1.jar and b/libs/Simple Code Generator-1.0.1.jar differ diff --git a/src/main/java/speiger/src/builder/example/ClassType.java b/src/main/java/speiger/src/builder/example/ClassType.java index fa9a265c..e6ff4c94 100644 --- a/src/main/java/speiger/src/builder/example/ClassType.java +++ b/src/main/java/speiger/src/builder/example/ClassType.java @@ -34,11 +34,21 @@ public enum ClassType return keyType; } + public String getValueType() + { + return this == OBJECT ? "V" : keyType; + } + public String getClassType() { return classType; } + public String getClassValueType() + { + return this == OBJECT ? "V" : classType; + } + public String getNonFileType() { return this == OBJECT ? "" : fileType; @@ -49,6 +59,11 @@ public enum ClassType return fileType; } + public String getJavaFileType() + { + return this == OBJECT ? "Obj" : fileType; + } + public String getPathType() { return pathType; @@ -106,6 +121,43 @@ public enum ClassType } } + public boolean hasFunction(ClassType other) + { + if(this == other && this != BOOLEAN && !needsCustomJDKType() && !other.needsCustomJDKType()) return true; + if(this == BOOLEAN) return false; + if(other == BOOLEAN && !needsCustomJDKType()) return true; + if(!needsCustomJDKType() && !other.needsCustomJDKType()) return true; + 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 ""; + if(this == other && this != BOOLEAN) return this == OBJECT ? "java.util.function.Function" : "java.util.function."+getJavaFileType()+"UnaryOperator"; + if(other == BOOLEAN) return this == OBJECT ? "java.util.function.Predicate" : "java.util.function."+getJavaFileType()+"Predicate"; + if(!needsCustomJDKType()) return other == OBJECT ? "java.util.function."+getJavaFileType()+"Function" : (this == OBJECT ? "java.util.function.To"+other.getJavaFileType()+"Function" : "java.util.function."+getJavaFileType()+"To"+other.getJavaFileType()+"Function"); + if(!other.needsCustomJDKType()) return this == OBJECT ? "java.util.function.To"+other.getJavaFileType()+"Function" : "java.util.function."+getJavaFileType()+"To"+other.getJavaFileType()+"Function"; + 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) diff --git a/src/main/java/speiger/src/builder/example/GlobalVariables.java b/src/main/java/speiger/src/builder/example/GlobalVariables.java index 05fc9249..cb26cfba 100644 --- a/src/main/java/speiger/src/builder/example/GlobalVariables.java +++ b/src/main/java/speiger/src/builder/example/GlobalVariables.java @@ -19,24 +19,39 @@ public class GlobalVariables List operators = new ArrayList<>(); Set flags = new LinkedHashSet<>(); ClassType type; + ClassType valueType; - public GlobalVariables(ClassType type) + public GlobalVariables(ClassType type, ClassType subType) { this.type = type; + valueType = subType; } public GlobalVariables createVariables() { addSimpleMapper("PACKAGE", type.getPathType()); addSimpleMapper("CLASS_TYPE", type.getClassType()); + addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType()); addSimpleMapper("KEY_TYPE", type.getKeyType()); - addSimpleMapper("EMPTY_VALUE", type.getEmptyValue()); + addSimpleMapper("VALUE_TYPE", valueType.getValueType()); + + addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue()); + addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue()); + addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : ""); + addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+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(" NO_GENERIC_TYPE", type.isObject() ? "" : ""); addSimpleMapper(" KEY_COMPAREABLE_TYPE", type.isObject() ? "<"+type.getKeyType()+" extends Comparable>" : ""); addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "" : ""); - addSimpleMapper(" GENERIC_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : ""); - addSimpleMapper(" COMPAREABLE_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable>" : ""); + addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "" : ""); + addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); + + 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()+">" : "")); + addSimpleMapper(" COMPAREABLE_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable>" : ""); addSimpleMapper("BRACES", type.isObject() ? "<>" : ""); if(type.needsCustomJDKType()) { @@ -52,21 +67,33 @@ public class GlobalVariables public GlobalVariables createHelperVariables() { addArgumentMapper("EQUALS_KEY_TYPE", type.isObject() ? "Objects.equals(%2$s, %1$s)" : "Objects.equals(%2$s, KEY_TO_OBJ(%1$s))").removeBraces(); - addInjectMapper("EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces(); - addInjectMapper("EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces(); - addArgumentMapper("EQUALS_NOT", type.getEquals(true)).removeBraces(); - addArgumentMapper("EQUALS", type.getEquals(false)).removeBraces(); + addInjectMapper("KEY_EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces(); + 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("COMPARE_TO_KEY", type.isObject() ? "((Comparable)%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(); + addInjectMapper("KEY_TO_OBJ", type.isObject() ? "%s" : type.getClassType()+".valueOf(%s)").removeBraces(); addInjectMapper("OBJ_TO_KEY", type.isObject() ? "%s" : "%s."+type.getKeyType()+"Value()").removeBraces(); addInjectMapper("CLASS_TO_KEY", "(("+type.getClassType()+")%s)."+type.getKeyType()+"Value()").removeBraces(); - addSimpleMapper("APPLY", "applyAs"+type.getCustomJDKType().getNonFileType()); - addInjectMapper("TO_HASH", type.isObject() ? "%s.hashCode()" : type.getClassType()+".hashCode(%s)").removeBraces(); + + 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("KEY_TO_HASH", type.isObject() ? "%s.hashCode()" : type.getClassType()+".hashCode(%s)").removeBraces(); + addSimpleMapper("CAST_KEY_ARRAY ", type.isObject() ? "(KEY_TYPE[])" : ""); addSimpleMapper("EMPTY_KEY_ARRAY", type.isObject() ? "(KEY_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY"); addInjectMapper("NEW_KEY_ARRAY", type.isObject() ? "(KEY_TYPE[])new Object[%s]" : "new KEY_TYPE[%s]").removeBraces(); addInjectMapper("NEW_CLASS_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces(); + + addSimpleMapper("CAST_VALUE_ARRAY ", valueType.isObject() ? "(VALUE_TYPE[])" : ""); + addSimpleMapper("EMPTY_VALUE_ARRAY", valueType.isObject() ? "(VALUE_TYPE[])VALUE_ARRAYS.EMPTY_ARRAY" : "VALUE_ARRAYS.EMPTY_ARRAY"); + addInjectMapper("NEW_VALUE_ARRAY", valueType.isObject() ? "(VALUE_TYPE[])new Object[%s]" : "new VALUE_TYPE[%s]").removeBraces(); + addInjectMapper("NEW_CLASS_VALUE_ARRAY", valueType.isObject() ? "(CLASS_VALUE_TYPE[])new Object[%s]" : "new CLASS_VALUE_TYPE[%s]").removeBraces(); return this; } @@ -74,6 +101,8 @@ public class GlobalVariables { 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"); //Final Classes @@ -105,9 +134,12 @@ public class GlobalVariables //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"); addClassMapper("NAVIGABLE_SET", "NavigableSet"); @@ -134,9 +166,12 @@ 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"); addFunctionMapper("ENQUEUE_FIRST", "enqueueFirst"); addFunctionMapper("ENQUEUE", "enqueue"); addFunctionMapper("DEQUEUE_LAST", "dequeueLast"); @@ -161,14 +196,14 @@ public class GlobalVariables public GlobalVariables createFlags() { flags.add("TYPE_"+type.getCapType()); - if(!type.needsCustomJDKType()) - { - flags.add("JDK_CONSUMER"); - } - if(!type.isPrimitiveBlocking()) - { - flags.add("PRIMITIVES"); - } + 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.needsCustomJDKType()) flags.add("JDK_VALUE"); return this; } @@ -181,6 +216,15 @@ public class GlobalVariables return process; } + public TemplateProcess createBi(String fileName, String splitter) + { + TemplateProcess process = new TemplateProcess(String.format(fileName+".java", type.getFileType()+splitter+valueType.getFileType())); + process.setPathBuilder(new PathBuilder(type.getPathType())); + process.addFlags(flags); + process.addMappers(operators); + return process; + } + public ClassType getType() { return type; @@ -188,7 +232,14 @@ 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()+"["+pattern+"]", pattern, type.getFileType()+replacement)); + operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+replacement)); + } + + private void addBiClassMapper(String pattern, String replacement, String splitter) + { + operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+splitter+valueType.getFileType()+replacement)); + } private void addAbstractMapper(String pattern, String replacement) @@ -201,6 +252,11 @@ public class GlobalVariables operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+type.getNonFileType())); } + private void addFunctionValueMapper(String pattern, String replacement) + { + operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+valueType.getNonFileType())); + } + private void addFunctionMappers(String pattern, String replacement) { operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getNonFileType()))); diff --git a/src/main/java/speiger/src/builder/example/TestBuilder.java b/src/main/java/speiger/src/builder/example/TestBuilder.java index 433a8828..38dcf088 100644 --- a/src/main/java/speiger/src/builder/example/TestBuilder.java +++ b/src/main/java/speiger/src/builder/example/TestBuilder.java @@ -17,8 +17,10 @@ public class TestBuilder extends TemplateProcessor { Map> blocked = new HashMap>(); Map nameRemapper = new HashMap(); + Map biRequired = new HashMap(); public static final ClassType[] TYPE = ClassType.values(); - List varibles = new ArrayList(); + List variables = new ArrayList(); + List biVariables = new ArrayList<>(); public TestBuilder() { @@ -46,17 +48,18 @@ public class TestBuilder extends TemplateProcessor @Override protected void init() { - varibles.clear(); + variables.clear(); for(ClassType clzType : TYPE) { - GlobalVariables type = new GlobalVariables(clzType); - type.createFlags(); - type.createHelperVariables(); - type.createVariables(); - type.createClassTypes(); - type.createFunctions(); - varibles.add(type); + for(ClassType subType : TYPE) + { + create(clzType, subType); + } } + biRequired.put("BiConsumer", ""); + biRequired.put("Function", "2"); + biRequired.put("BiFunction", "2"); + nameRemapper.put("BiConsumer", "%sConsumer"); nameRemapper.put("IArray", "I%sArray"); nameRemapper.put("AbstractCollection", "Abstract%sCollection"); nameRemapper.put("AbstractSet", "Abstract%sSet"); @@ -65,6 +68,18 @@ public class TestBuilder extends TemplateProcessor addBlockage(ClassType.BOOLEAN, "Sets", "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet"); } + protected void create(ClassType mainType, ClassType subType) + { + GlobalVariables type = new GlobalVariables(mainType, subType); + type.createFlags(); + type.createHelperVariables(); + type.createVariables(); + type.createClassTypes(); + type.createFunctions(); + if(mainType == subType) variables.add(type); + biVariables.add(type); + } + protected void addBlockage(ClassType type, String...args) { for(String s : args) { EnumSet set = blocked.get(s); @@ -80,9 +95,22 @@ public class TestBuilder extends TemplateProcessor public void createProcesses(String name, Consumer acceptor) { EnumSet types = blocked.get(name); - for(int i = 0,m=varibles.size();i, JAVA_CONSUMER #else - -/** - * Type-Specific Consumer interface that reduces (un)boxing and allows to merge other consumer types into this interface - */ public interface CONSUMER extends Consumer #endif { @@ -28,16 +20,6 @@ public interface CONSUMER extends Consumer */ void accept(KEY_TYPE t); -#if !JDK_CONSUMER - /** {@inheritDoc} - *

This default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - default void accept(JAVA_TYPE t) { accept(SanityChecks.SANITY_CAST(t)); } - -#endif public default CONSUMER andThen(CONSUMER after) { Objects.requireNonNull(after); return T -> {accept(T); after.accept(T);}; @@ -61,8 +43,8 @@ public interface CONSUMER extends Consumer Objects.requireNonNull(after); return T -> {accept(T); after.accept(KEY_TO_OBJ(T));}; } +#if JDK_TYPE && PRIMITIVES -#if PRIMITIVES /** {@inheritDoc} *

This default implementation delegates to the corresponding type-specific function. * @deprecated Please use the corresponding type-specific function instead. diff --git a/src/main/resources/speiger/assets/collections/templates/functions/consumer/BiConsumer.template b/src/main/resources/speiger/assets/collections/templates/functions/consumer/BiConsumer.template new file mode 100644 index 00000000..bd0bdfd0 --- /dev/null +++ b/src/main/resources/speiger/assets/collections/templates/functions/consumer/BiConsumer.template @@ -0,0 +1,35 @@ +package speiger.src.collections.PACKAGE.functions.consumer; + +import java.util.Objects; +import java.util.function.BiConsumer; + +public interface BI_CONSUMER KEY_VALUE_GENERIC_TYPE extends BiConsumer +{ + void accept(KEY_TYPE k, VALUE_TYPE v); + + public default BI_CONSUMER KEY_VALUE_GENERIC_TYPE andThen(BI_CONSUMER KEY_VALUE_GENERIC_TYPE after) { + Objects.requireNonNull(after); + return (K, V) -> {accept(K, V); after.accept(K, V);}; + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + default void accept(CLASS_TYPE k, CLASS_VALUE_TYPE v) { accept(OBJ_TO_KEY(k), OBJ_TO_VALUE(v)); } + + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + default BI_CONSUMER KEY_VALUE_GENERIC_TYPE andThen(BiConsumer after) { + Objects.requireNonNull(after); + return (K, V) -> {accept(K, V); after.accept(KEY_TO_OBJ(K), VALUE_TO_OBJ(V));}; + } +#endif +} \ No newline at end of file diff --git a/src/main/resources/speiger/assets/collections/templates/functions/function/BiFunction.template b/src/main/resources/speiger/assets/collections/templates/functions/function/BiFunction.template new file mode 100644 index 00000000..21217246 --- /dev/null +++ b/src/main/resources/speiger/assets/collections/templates/functions/function/BiFunction.template @@ -0,0 +1,26 @@ +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 +} \ No newline at end of file diff --git a/src/main/resources/speiger/assets/collections/templates/functions/function/Function.template b/src/main/resources/speiger/assets/collections/templates/functions/function/Function.template new file mode 100644 index 00000000..e7388a72 --- /dev/null +++ b/src/main/resources/speiger/assets/collections/templates/functions/function/Function.template @@ -0,0 +1,59 @@ +package speiger.src.collections.PACKAGE.functions.function; + +#if JDK_FUNCTION && VALUE_BOOLEAN +import java.util.Objects; +#endif + +@FunctionalInterface +#if JDK_FUNCTION +public interface FUNCTION KEY_VALUE_GENERIC_TYPE extends JAVA_FUNCTION KEY_VALUE_GENERIC_TYPE +#else +public interface FUNCTION KEY_VALUE_GENERIC_TYPE +#endif +{ + public VALUE_TYPE GET_VALUE(KEY_TYPE k); +#if JDK_FUNCTION +#if VALUE_BOOLEAN + + @Override + public default VALUE_TYPE test(KEY_TYPE k) { return GET_VALUE(k); } + + public default FUNCTION KEY_VALUE_GENERIC_TYPE andType(FUNCTION KEY_VALUE_GENERIC_TYPE other) { + Objects.requireNonNull(other); + return T -> GET_VALUE(T) && other.GET_VALUE(T); + } + + @Override + @Deprecated + public default FUNCTION KEY_VALUE_GENERIC_TYPE and(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) { + Objects.requireNonNull(other); + return T -> GET_VALUE(T) && other.test(T); + } + + @Override + public default FUNCTION KEY_VALUE_GENERIC_TYPE negate() { + return T -> !GET_VALUE(T); + } + + public default FUNCTION KEY_VALUE_GENERIC_TYPE orType(FUNCTION KEY_VALUE_GENERIC_TYPE other) { + Objects.requireNonNull(other); + return T -> GET_VALUE(T) || other.GET_VALUE(T); + } + + @Override + @Deprecated + public default FUNCTION KEY_VALUE_GENERIC_TYPE or(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) { + Objects.requireNonNull(other); + return T -> GET_VALUE(T) || other.test(T); + } +#else if VALUE_OBJECT + + @Override + public default VALUE_TYPE apply(KEY_TYPE k) { return GET_VALUE(k); } +#else + + @Override + public default VALUE_TYPE APPLY_VALUE(KEY_TYPE k) { return GET_VALUE(k); } +#endif +#endif +} \ No newline at end of file diff --git a/src/main/resources/speiger/assets/collections/templates/lists/AbstractList.template b/src/main/resources/speiger/assets/collections/templates/lists/AbstractList.template index 956b1203..8fd18a02 100644 --- a/src/main/resources/speiger/assets/collections/templates/lists/AbstractList.template +++ b/src/main/resources/speiger/assets/collections/templates/lists/AbstractList.template @@ -125,7 +125,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION public int indexOf(KEY_TYPE e) { LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); while(iter.hasNext()) { - if(EQUALS(iter.NEXT(), e)) + if(KEY_EQUALS(iter.NEXT(), e)) return iter.previousIndex(); } return -1; @@ -140,7 +140,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION public int lastIndexOf(KEY_TYPE e) { LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(size()); while(iter.hasPrevious()) { - if(EQUALS(iter.PREVIOUS(), e)) + if(KEY_EQUALS(iter.PREVIOUS(), e)) return iter.nextIndex(); } return -1; @@ -164,7 +164,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION LIST_ITERATOR e1 = listIterator(); LIST_ITERATOR e2 = ((LIST)l).listIterator(); while (e1.hasNext() && e2.hasNext()) { - if(!(EQUALS(e1.NEXT(), e2.NEXT()))) + if(!(KEY_EQUALS(e1.NEXT(), e2.NEXT()))) return false; } return !(e1.hasNext() || e2.hasNext()); @@ -190,7 +190,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION #if TYPE_OBJECT hashCode = 31 * hashCode + i.next().hashCode(); #else - hashCode = 31 * hashCode + TO_HASH(i.NEXT()); + hashCode = 31 * hashCode + KEY_TO_HASH(i.NEXT()); #endif return hashCode; } @@ -217,7 +217,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION @Override public void size(int size) { - while(size > size()) add(EMPTY_VALUE); + while(size > size()) add(EMPTY_KEY_VALUE); while(size < size()) REMOVE(size() - 1); } diff --git a/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template b/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template index 5e7a3d07..bd4159eb 100644 --- a/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template +++ b/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template @@ -127,14 +127,14 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE /** * Creates a wrapped arraylist that uses the array as backing array */ - public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) { + public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) { return wrap(a, a.length); } /** * Creates a wrapped arraylist that uses the array as backing array and a custom fillsize */ - public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int length) { + public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int length) { SanityChecks.checkArrayCapacity(a.length, 0, length); ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); list.data = a; @@ -146,7 +146,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE /** * Creates a new ArrayList with a EmptyObject array of the Type requested */ - public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class c) { + public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class c) { ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); list.data = (KEY_TYPE[])ObjectArrays.newArray(c.getClass().getComponentType(), 0); return list; @@ -453,7 +453,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE @Override public int indexOf(KEY_TYPE e) { for(int i = 0;i=0;i--) { - if(EQUALS(data[i], e)) return i; + if(KEY_EQUALS(data[i], e)) return i; } return -1; } @@ -853,7 +853,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE if(size > data.length) data = Arrays.copyOf(data, size); else if(size < size() && size >= 0) - Arrays.fill(data, size, size(), EMPTY_VALUE); + Arrays.fill(data, size, size(), EMPTY_KEY_VALUE); this.size = size; } diff --git a/src/main/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template b/src/main/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template index a7b9c74e..0016e00c 100644 --- a/src/main/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template +++ b/src/main/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template @@ -65,22 +65,22 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY comparator = comp; } - public static GENERIC_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) { + public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) { return wrap(array, array.length); } - public static GENERIC_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) { + public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) { ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES(); queue.array = array; queue.size = size; return queue; } - public static GENERIC_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { return wrap(array, array.length, comp); } - public static GENERIC_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES(comp); queue.array = array; queue.size = size; @@ -120,14 +120,14 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY @Override public boolean REMOVE(KEY_TYPE e) { for(int i = 0;i=0;i--) - if(EQUALS(e, array[i])) return removeIndex(i); + if(KEY_EQUALS(e, array[i])) return removeIndex(i); return false; } @@ -137,7 +137,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY array[size] = null; #endif if(index == firstIndex) firstIndex = -1; - else if(index >= firstIndex) firstIndex--; + else if(firstIndex != -1 && index >= firstIndex) firstIndex--; return true; } @@ -190,13 +190,13 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY int index = size-1; KEY_TYPE value = array[index]; if(comparator == null) { - for(int i = index;firstIndex == -1 && i>=0;i--) { + for(int i = index;i>=0;i--) { if(COMPARE_TO_KEY(array[i], value) < 0) value = array[index = i]; } } else { - for(int i = index;firstIndex == -1 && i>=0;i--) { + for(int i = index;i>=0;i--) { if(comparator.compare(array[i], value) < 0) value = array[index = i]; } diff --git a/src/main/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template b/src/main/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template index 41fbb903..569dd0d5 100644 --- a/src/main/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template +++ b/src/main/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template @@ -68,11 +68,11 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_ ARRAYS.heapify(array, size, comp); } - public static GENERIC_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) { + public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array) { return wrap(array, array.length); } - public static GENERIC_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) { + public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size) { HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES(); queue.array = array; queue.size = size; @@ -80,11 +80,11 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_ return queue; } - public static GENERIC_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { return wrap(array, array.length, comp); } - public static GENERIC_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE wrap(KEY_TYPE[] array, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES(comp); queue.array = array; queue.size = size; @@ -138,14 +138,14 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_ @Override public boolean REMOVE(KEY_TYPE e) { for(int i = 0;i=0;i--) - if(EQUALS(e, array[i])) return removeIndex(i); + if(KEY_EQUALS(e, array[i])) return removeIndex(i); return false; } diff --git a/src/main/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template b/src/main/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template index 1aff3f7b..9c77015d 100644 --- a/src/main/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template +++ b/src/main/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template @@ -4,9 +4,11 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE { public void ENQUEUE_FIRST(KEY_TYPE e); public KEY_TYPE DEQUEUE_LAST(); + public default KEY_TYPE LAST_KEY() { return PEEK(size()-1); } #if !TYPE_OBJECT public default void enqueueFirst(CLASS_TYPE e) { ENQUEUE_FIRST(OBJ_TO_KEY(e)); } public default CLASS_TYPE dequeueLast() { return KEY_TO_OBJ(DEQUEUE_LAST()); } + public default CLASS_TYPE last() { return peek(size()-1); } #endif } \ No newline at end of file diff --git a/src/main/resources/speiger/assets/collections/templates/queues/PriorityQueue.template b/src/main/resources/speiger/assets/collections/templates/queues/PriorityQueue.template index 4ea46e83..a29c5531 100644 --- a/src/main/resources/speiger/assets/collections/templates/queues/PriorityQueue.template +++ b/src/main/resources/speiger/assets/collections/templates/queues/PriorityQueue.template @@ -24,8 +24,7 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue=0;i--) - if(EQUALS(data[i], o)) return i; + if(KEY_EQUALS(data[i], o)) return i; return -1; } @@ -407,7 +407,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im length--; if(index != size) System.arraycopy(data, index+1, data, index, size - index); #if TYPE_OBJECT - data[size] = EMPTY_VALUE; + data[size] = EMPTY_KEY_VALUE; #endif return true; } @@ -422,7 +422,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im KEY_TYPE result = data[offset]; System.arraycopy(data, offset+1, data, offset, size-offset); #if TYPE_OBJECT - data[size] = EMPTY_VALUE; + data[size] = EMPTY_KEY_VALUE; #endif return result; } @@ -435,7 +435,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im length--; System.arraycopy(data, end()+1, data, end(), size-end()); #if TYPE_OBJECT - data[size] = EMPTY_VALUE; + data[size] = EMPTY_KEY_VALUE; #endif return result; } @@ -487,7 +487,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im #if !TYPE_OBJECT protected int findIndex(KEY_TYPE o) { for(int i = length-1;i>=0;i--) - if(EQUALS(data[offset+i], o)) return i + offset; + if(KEY_EQUALS(data[offset+i], o)) return i + offset; return -1; } diff --git a/src/main/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template b/src/main/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template index e35d63d6..afecbf1f 100644 --- a/src/main/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template +++ b/src/main/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template @@ -106,7 +106,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY #endif @Override public boolean addAndMoveToFirst(KEY_TYPE o) { - if(strategy.equals(o, EMPTY_VALUE)) { + if(strategy.equals(o, EMPTY_KEY_VALUE)) { if(containsNull) { moveToFirstIndex(nullIndex); return false; @@ -116,7 +116,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY } else { int pos = HashUtil.mix(strategy.hashCode(o)) & mask; - while(!strategy.equals(keys[pos], EMPTY_VALUE)) { + while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) { if(strategy.equals(keys[pos], o)) { moveToFirstIndex(pos); return false; @@ -132,7 +132,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY @Override public boolean addAndMoveToLast(KEY_TYPE o) { - if(strategy.equals(o, EMPTY_VALUE)) { + if(strategy.equals(o, EMPTY_KEY_VALUE)) { if(containsNull) { moveToLastIndex(nullIndex); return false; @@ -142,7 +142,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY } else { int pos = HashUtil.mix(strategy.hashCode(o)) & mask; - while(!strategy.equals(keys[pos], EMPTY_VALUE)) { + while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) { if(strategy.equals(keys[pos], o)) { moveToLastIndex(pos); return false; @@ -159,7 +159,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY @Override public boolean moveToFirst(KEY_TYPE o) { if(strategy.equals(FIRST_KEY(), o)) return false; - if(strategy.equals(o, EMPTY_VALUE)) { + if(strategy.equals(o, EMPTY_KEY_VALUE)) { if(containsNull) { moveToFirstIndex(nullIndex); return true; @@ -167,7 +167,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY } else { int pos = HashUtil.mix(strategy.hashCode(o)) & mask; - while(!strategy.equals(keys[pos], EMPTY_VALUE)) { + while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) { if(strategy.equals(keys[pos], o)) { moveToFirstIndex(pos); return true; @@ -182,7 +182,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY @Override public boolean moveToLast(KEY_TYPE o) { if(strategy.equals(LAST_KEY(), o)) return false; - if(strategy.equals(o, EMPTY_VALUE)) { + if(strategy.equals(o, EMPTY_KEY_VALUE)) { if(containsNull) { moveToLastIndex(nullIndex); return true; @@ -190,7 +190,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY } else { int pos = HashUtil.mix(strategy.hashCode(o)) & mask; - while(!strategy.equals(keys[pos], EMPTY_VALUE)) { + while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) { if(strategy.equals(keys[pos], o)) { moveToLastIndex(pos); return true; @@ -252,9 +252,9 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L; KEY_TYPE result = keys[pos]; size--; - if(strategy.equals(result, EMPTY_VALUE)) { + if(strategy.equals(result, EMPTY_KEY_VALUE)) { containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; } else shiftKeys(pos); if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2); @@ -275,9 +275,9 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL; KEY_TYPE result = keys[pos]; size--; - if(strategy.equals(result, EMPTY_VALUE)) { + if(strategy.equals(result, EMPTY_KEY_VALUE)) { containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; } else shiftKeys(pos); if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2); @@ -350,10 +350,10 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY long[] newLinks = new long[newSize + 1]; int newPrev = -1; for(int j = size, i = firstIndex, pos = 0, prev = -1;j != 0;) { - if(strategy.equals(keys[i], EMPTY_VALUE)) pos = newSize; + if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) pos = newSize; else { pos = HashUtil.mix(strategy.hashCode(keys[i])) & newMask; - while(!strategy.equals(newKeys[pos], EMPTY_VALUE)) pos = ++pos & newMask; + while(!strategy.equals(newKeys[pos], EMPTY_KEY_VALUE)) pos = ++pos & newMask; } newKeys[pos] = keys[i]; if(prev != -1) { @@ -415,7 +415,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY } SetIterator(KEY_TYPE from) { - if(strategy.equals(from, EMPTY_VALUE)) { + if(strategy.equals(from, EMPTY_KEY_VALUE)) { if(containsNull) { next = (int) links[nullIndex]; previous = nullIndex; @@ -428,7 +428,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY } else { int pos = HashUtil.mix(strategy.hashCode(from)) & mask; - while(!strategy.equals(keys[pos], EMPTY_VALUE)) { + while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) { if(strategy.equals(keys[pos], from)) { next = (int)links[pos]; previous = pos; @@ -481,7 +481,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY if(current == nullIndex) { current = -1; containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; } else { int slot, last, startPos = current; @@ -490,8 +490,8 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY while(true) { startPos = ((last = startPos) + 1) & mask; while(true){ - if(strategy.equals((current = keys[startPos]), EMPTY_VALUE)) { - keys[last] = EMPTY_VALUE; + if(strategy.equals((current = keys[startPos]), EMPTY_KEY_VALUE)) { + keys[last] = EMPTY_KEY_VALUE; return; } slot = HashUtil.mix(strategy.hashCode(current)) & mask; diff --git a/src/main/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template b/src/main/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template index fd3df0f0..141b836b 100644 --- a/src/main/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template +++ b/src/main/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template @@ -108,7 +108,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE #endif @Override public boolean addAndMoveToFirst(KEY_TYPE o) { - if(EQUALS_NULL(o)) { + if(KEY_EQUALS_NULL(o)) { if(containsNull) { moveToFirstIndex(nullIndex); return false; @@ -117,9 +117,9 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE onNodeAdded(nullIndex); } else { - int pos = HashUtil.mix(TO_HASH(o)) & mask; - while(EQUALS_NOT_NULL(keys[pos])) { - if(EQUALS(keys[pos], o)) { + int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask; + while(KEY_EQUALS_NOT_NULL(keys[pos])) { + if(KEY_EQUALS(keys[pos], o)) { moveToFirstIndex(pos); return false; } @@ -134,7 +134,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE @Override public boolean addAndMoveToLast(KEY_TYPE o) { - if(EQUALS_NULL(o)) { + if(KEY_EQUALS_NULL(o)) { if(containsNull) { moveToLastIndex(nullIndex); return false; @@ -143,9 +143,9 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE onNodeAdded(nullIndex); } else { - int pos = HashUtil.mix(TO_HASH(o)) & mask; - while(EQUALS_NOT_NULL(keys[pos])) { - if(EQUALS(keys[pos], o)) { + int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask; + while(KEY_EQUALS_NOT_NULL(keys[pos])) { + if(KEY_EQUALS(keys[pos], o)) { moveToLastIndex(pos); return false; } @@ -160,17 +160,17 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE @Override public boolean moveToFirst(KEY_TYPE o) { - if(EQUALS(FIRST_KEY(), o)) return false; - if(EQUALS_NULL(o)) { + if(KEY_EQUALS(FIRST_KEY(), o)) return false; + if(KEY_EQUALS_NULL(o)) { if(containsNull) { moveToFirstIndex(nullIndex); return true; } } else { - int pos = HashUtil.mix(TO_HASH(o)) & mask; - while(EQUALS_NOT_NULL(keys[pos])) { - if(EQUALS(keys[pos], o)) { + int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask; + while(KEY_EQUALS_NOT_NULL(keys[pos])) { + if(KEY_EQUALS(keys[pos], o)) { moveToFirstIndex(pos); return true; } @@ -183,17 +183,17 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE @Override public boolean moveToLast(KEY_TYPE o) { - if(EQUALS(LAST_KEY(), o)) return false; - if(EQUALS_NULL(o)) { + if(KEY_EQUALS(LAST_KEY(), o)) return false; + if(KEY_EQUALS_NULL(o)) { if(containsNull) { moveToLastIndex(nullIndex); return true; } } else { - int pos = HashUtil.mix(TO_HASH(o)) & mask; - while(EQUALS_NOT_NULL(keys[pos])) { - if(EQUALS(keys[pos], o)) { + int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask; + while(KEY_EQUALS_NOT_NULL(keys[pos])) { + if(KEY_EQUALS(keys[pos], o)) { moveToLastIndex(pos); return true; } @@ -254,9 +254,9 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L; KEY_TYPE result = keys[pos]; size--; - if(EQUALS_NULL(result)) { + if(KEY_EQUALS_NULL(result)) { containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; } else shiftKeys(pos); if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2); @@ -277,9 +277,9 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL; KEY_TYPE result = keys[pos]; size--; - if(EQUALS_NULL(result)) { + if(KEY_EQUALS_NULL(result)) { containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; } else shiftKeys(pos); if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2); @@ -352,10 +352,10 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE long[] newLinks = new long[newSize + 1]; int newPrev = -1; for(int j = size, i = firstIndex, pos = 0, prev = -1;j != 0;) { - if(EQUALS_NULL(keys[i])) pos = newSize; + if(KEY_EQUALS_NULL(keys[i])) pos = newSize; else { - pos = HashUtil.mix(TO_HASH(keys[i])) & newMask; - while(EQUALS_NOT_NULL(newKeys[pos])) pos = ++pos & newMask; + pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask; + while(KEY_EQUALS_NOT_NULL(newKeys[pos])) pos = ++pos & newMask; } newKeys[pos] = keys[i]; if(prev != -1) { @@ -417,21 +417,21 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE } SetIterator(KEY_TYPE from) { - if(EQUALS_NULL(from)) { + if(KEY_EQUALS_NULL(from)) { if(containsNull) { next = (int) links[nullIndex]; previous = nullIndex; } else throw new NoSuchElementException("The null element is not in the set"); } - else if(EQUALS(keys[lastIndex], from)) { + else if(KEY_EQUALS(keys[lastIndex], from)) { previous = lastIndex; index = size; } else { - int pos = HashUtil.mix(TO_HASH(from)) & mask; - while(EQUALS_NOT_NULL(keys[pos])) { - if(EQUALS(keys[pos], from)) { + int pos = HashUtil.mix(KEY_TO_HASH(from)) & mask; + while(KEY_EQUALS_NOT_NULL(keys[pos])) { + if(KEY_EQUALS(keys[pos], from)) { next = (int)links[pos]; previous = pos; break; @@ -483,7 +483,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE if(current == nullIndex) { current = -1; containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; } else { int slot, last, startPos = current; @@ -492,11 +492,11 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE while(true) { startPos = ((last = startPos) + 1) & mask; while(true){ - if(EQUALS_NULL((current = keys[startPos]))) { - keys[last] = EMPTY_VALUE; + if(KEY_EQUALS_NULL((current = keys[startPos]))) { + keys[last] = EMPTY_KEY_VALUE; return; } - slot = HashUtil.mix(TO_HASH(current)) & mask; + slot = HashUtil.mix(KEY_TO_HASH(current)) & mask; if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break; startPos = ++startPos & mask; } diff --git a/src/main/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template b/src/main/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template index 9c20c5bb..6db35905 100644 --- a/src/main/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template +++ b/src/main/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template @@ -118,7 +118,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T @Override public boolean add(KEY_TYPE o) { - if(strategy.equals(o, EMPTY_VALUE)) { + if(strategy.equals(o, EMPTY_KEY_VALUE)) { if(containsNull) return false; containsNull = true; onNodeAdded(nullIndex); @@ -126,9 +126,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T else { int pos = HashUtil.mix(strategy.hashCode(o)) & mask; KEY_TYPE current = keys[pos]; - if(!strategy.equals(current, EMPTY_VALUE)) { + if(!strategy.equals(current, EMPTY_KEY_VALUE)) { if(strategy.equals(current, o)) return false; - while(!strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE)) + while(!strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE)) if(strategy.equals(current, o)) return false; } keys[pos] = o; @@ -156,26 +156,26 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T #if TYPE_OBJECT @Override public boolean contains(Object o) { - if(strategy.equals((KEY_TYPE)o, EMPTY_VALUE)) return containsNull; + if(strategy.equals((KEY_TYPE)o, EMPTY_KEY_VALUE)) return containsNull; int pos = HashUtil.mix(strategy.hashCode((KEY_TYPE)o)) & mask; KEY_TYPE current = keys[pos]; - if(strategy.equals(current, EMPTY_VALUE)) return false; + if(strategy.equals(current, EMPTY_KEY_VALUE)) return false; if(strategy.equals(current, (KEY_TYPE)o)) return true; while(true) { - if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE)) return false; + if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE)) return false; else if(strategy.equals(current, (KEY_TYPE)o)) return true; } } @Override public boolean remove(Object o) { - if(strategy.equals((KEY_TYPE)o, EMPTY_VALUE)) return (containsNull ? removeNullIndex() : false); + if(strategy.equals((KEY_TYPE)o, EMPTY_KEY_VALUE)) return (containsNull ? removeNullIndex() : false); int pos = HashUtil.mix(strategy.hashCode((KEY_TYPE)o)) & mask; KEY_TYPE current = keys[pos]; - if(strategy.equals(current, EMPTY_VALUE)) return false; + if(strategy.equals(current, EMPTY_KEY_VALUE)) return false; if(strategy.equals(current, (KEY_TYPE)o)) return removeIndex(pos); while(true) { - if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE)) return false; + if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE)) return false; else if(strategy.equals(current, (KEY_TYPE)o)) return removeIndex(pos); } } @@ -183,26 +183,26 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T #else @Override public boolean contains(KEY_TYPE o) { - if(strategy.equals(o, EMPTY_VALUE)) return containsNull; + if(strategy.equals(o, EMPTY_KEY_VALUE)) return containsNull; int pos = HashUtil.mix(strategy.hashCode(o)) & mask; KEY_TYPE current = keys[pos]; - if(strategy.equals(current, EMPTY_VALUE)) return false; + if(strategy.equals(current, EMPTY_KEY_VALUE)) return false; if(strategy.equals(current, o)) return true; while(true) { - if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE)) return false; + if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE)) return false; else if(strategy.equals(current, o)) return true; } } @Override public boolean remove(KEY_TYPE o) { - if(strategy.equals(o, EMPTY_VALUE)) return (containsNull ? removeNullIndex() : false); + if(strategy.equals(o, EMPTY_KEY_VALUE)) return (containsNull ? removeNullIndex() : false); int pos = HashUtil.mix(strategy.hashCode(o)) & mask; KEY_TYPE current = keys[pos]; - if(strategy.equals(current, EMPTY_VALUE)) return false; + if(strategy.equals(current, EMPTY_KEY_VALUE)) return false; if(strategy.equals(current, o)) return removeIndex(pos); while(true) { - if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_VALUE)) return false; + if(strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE)) return false; else if(strategy.equals(current, o)) return removeIndex(pos); } } @@ -234,7 +234,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T protected boolean removeNullIndex() { containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; size--; onNodeRemoved(nullIndex); if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2); @@ -259,8 +259,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T while(true) { startPos = ((last = startPos) + 1) & mask; while(true){ - if(strategy.equals((current = keys[startPos]), EMPTY_VALUE)) { - keys[last] = EMPTY_VALUE; + if(strategy.equals((current = keys[startPos]), EMPTY_KEY_VALUE)) { + keys[last] = EMPTY_KEY_VALUE; return; } slot = HashUtil.mix(strategy.hashCode(current)) & mask; @@ -276,9 +276,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T int newMask = newSize - 1; KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1); for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) { - while(strategy.equals(keys[--i], EMPTY_VALUE)); - if(!strategy.equals(newKeys[pos = HashUtil.mix(TO_HASH(keys[i])) & newMask], EMPTY_VALUE)) - while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_VALUE)); + while(strategy.equals(keys[--i], EMPTY_KEY_VALUE)); + if(!strategy.equals(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask], EMPTY_KEY_VALUE)) + while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_KEY_VALUE)); newKeys[pos] = keys[i]; } nullIndex = newSize; @@ -297,7 +297,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T if(size == 0) return; size = 0; containsNull = false; - Arrays.fill(keys, EMPTY_VALUE); + Arrays.fill(keys, EMPTY_KEY_VALUE); } @Override @@ -326,7 +326,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T nextIndex = -pos - 1; break; } - if(EQUALS_NOT_NULL(keys[pos])){ + if(KEY_EQUALS_NOT_NULL(keys[pos])){ nextIndex = pos; break; } @@ -355,7 +355,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T if(lastReturned == -1) throw new IllegalStateException(); if(lastReturned == nullIndex) { containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; } else if(pos >= 0) shiftKeys(pos); else { @@ -372,8 +372,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T while(true) { startPos = ((last = startPos) + 1) & mask; while(true){ - if(strategy.equals((current = keys[startPos]), EMPTY_VALUE)) { - keys[last] = EMPTY_VALUE; + if(strategy.equals((current = keys[startPos]), EMPTY_KEY_VALUE)) { + keys[last] = EMPTY_KEY_VALUE; return; } slot = HashUtil.mix(strategy.hashCode(current)) & mask; diff --git a/src/main/resources/speiger/assets/collections/templates/sets/OpenHashSet.template b/src/main/resources/speiger/assets/collections/templates/sets/OpenHashSet.template index 9d53a9d2..8d17ae50 100644 --- a/src/main/resources/speiger/assets/collections/templates/sets/OpenHashSet.template +++ b/src/main/resources/speiger/assets/collections/templates/sets/OpenHashSet.template @@ -111,18 +111,18 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp #endif @Override public boolean add(KEY_TYPE o) { - if(EQUALS_NULL(o)) { + if(KEY_EQUALS_NULL(o)) { if(containsNull) return false; containsNull = true; onNodeAdded(nullIndex); } else { - int pos = HashUtil.mix(TO_HASH(o)) & mask; + int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask; KEY_TYPE current = keys[pos]; - if(EQUALS_NOT_NULL(current)) { - if(EQUALS(current, o)) return false; - while(EQUALS_NOT_NULL((current = keys[pos = (++pos & mask)]))) - if(EQUALS(current, o)) return false; + if(KEY_EQUALS_NOT_NULL(current)) { + if(KEY_EQUALS(current, o)) return false; + while(KEY_EQUALS_NOT_NULL((current = keys[pos = (++pos & mask)]))) + if(KEY_EQUALS(current, o)) return false; } keys[pos] = o; onNodeAdded(pos); @@ -151,10 +151,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp if(o == null) return containsNull; int pos = HashUtil.mix(o.hashCode()) & mask; KEY_TYPE current = keys[pos]; - if(EQUALS_NULL(current)) return false; + if(KEY_EQUALS_NULL(current)) return false; if(EQUALS_KEY_TYPE(current, o)) return true; while(true) { - if(EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false; + if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false; else if(EQUALS_KEY_TYPE(current, o)) return true; } } @@ -164,10 +164,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp if(o == null) return (containsNull ? removeNullIndex() : false); int pos = HashUtil.mix(o.hashCode()) & mask; KEY_TYPE current = keys[pos]; - if(EQUALS_NULL(current)) return false; + if(KEY_EQUALS_NULL(current)) return false; if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos); while(true) { - if(EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false; + if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false; else if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos); } } @@ -175,27 +175,27 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp #if !TYPE_OBJECT @Override public boolean contains(KEY_TYPE o) { - if(EQUALS_NULL(o)) return containsNull; - int pos = HashUtil.mix(TO_HASH(o)) & mask; + if(KEY_EQUALS_NULL(o)) return containsNull; + int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask; KEY_TYPE current = keys[pos]; - if(EQUALS_NULL(current)) return false; - if(EQUALS(current, o)) return true; + if(KEY_EQUALS_NULL(current)) return false; + if(KEY_EQUALS(current, o)) return true; while(true) { - if(EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false; - else if(EQUALS(current, o)) return true; + if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false; + else if(KEY_EQUALS(current, o)) return true; } } @Override public boolean remove(KEY_TYPE o) { - if(EQUALS_NULL(o)) return (containsNull ? removeNullIndex() : false); - int pos = HashUtil.mix(TO_HASH(o)) & mask; + if(KEY_EQUALS_NULL(o)) return (containsNull ? removeNullIndex() : false); + int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask; KEY_TYPE current = keys[pos]; - if(EQUALS_NULL(current)) return false; - if(EQUALS(current, o)) return removeIndex(pos); + if(KEY_EQUALS_NULL(current)) return false; + if(KEY_EQUALS(current, o)) return removeIndex(pos); while(true) { - if(EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false; - else if(EQUALS(current, o)) return removeIndex(pos); + if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false; + else if(KEY_EQUALS(current, o)) return removeIndex(pos); } } @@ -226,7 +226,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp protected boolean removeNullIndex() { containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; size--; onNodeRemoved(nullIndex); if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2); @@ -251,11 +251,11 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp while(true) { startPos = ((last = startPos) + 1) & mask; while(true){ - if(EQUALS_NULL((current = keys[startPos]))) { - keys[last] = EMPTY_VALUE; + if(KEY_EQUALS_NULL((current = keys[startPos]))) { + keys[last] = EMPTY_KEY_VALUE; return; } - slot = HashUtil.mix(TO_HASH(current)) & mask; + slot = HashUtil.mix(KEY_TO_HASH(current)) & mask; if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break; startPos = ++startPos & mask; } @@ -268,9 +268,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp int newMask = newSize - 1; KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1); for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) { - while(EQUALS_NULL(keys[--i])); - if(EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(TO_HASH(keys[i])) & newMask])) - while(EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)])); + while(KEY_EQUALS_NULL(keys[--i])); + if(KEY_EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask])) + while(KEY_EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)])); newKeys[pos] = keys[i]; } nullIndex = newSize; @@ -289,7 +289,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp if(size == 0) return; size = 0; containsNull = false; - Arrays.fill(keys, EMPTY_VALUE); + Arrays.fill(keys, EMPTY_KEY_VALUE); } @Override @@ -319,7 +319,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp nextIndex = -pos - 1; break; } - if(EQUALS_NOT_NULL(keys[pos])){ + if(KEY_EQUALS_NOT_NULL(keys[pos])){ nextIndex = pos; break; } @@ -348,7 +348,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp if(lastReturned == -1) throw new IllegalStateException(); if(lastReturned == nullIndex) { containsNull = false; - keys[nullIndex] = EMPTY_VALUE; + keys[nullIndex] = EMPTY_KEY_VALUE; } else if(pos >= 0) shiftKeys(pos); else { @@ -365,11 +365,11 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp while(true) { startPos = ((last = startPos) + 1) & mask; while(true){ - if(EQUALS_NULL((current = keys[startPos]))) { - keys[last] = EMPTY_VALUE; + if(KEY_EQUALS_NULL((current = keys[startPos]))) { + keys[last] = EMPTY_KEY_VALUE; return; } - slot = HashUtil.mix(TO_HASH(current)) & mask; + slot = HashUtil.mix(KEY_TO_HASH(current)) & mask; if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break; startPos = ++startPos & mask; } diff --git a/src/main/resources/speiger/assets/collections/templates/sets/RBTreeSet.template b/src/main/resources/speiger/assets/collections/templates/sets/RBTreeSet.template index a3aca053..4e7b3ed4 100644 --- a/src/main/resources/speiger/assets/collections/templates/sets/RBTreeSet.template +++ b/src/main/resources/speiger/assets/collections/templates/sets/RBTreeSet.template @@ -363,17 +363,17 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE @Override public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { - return new AscendingSubSetBRACES(this, true, EMPTY_VALUE, true, false, toElement, inclusive); + return new AscendingSubSetBRACES(this, true, EMPTY_KEY_VALUE, true, false, toElement, inclusive); } @Override public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { - return new AscendingSubSetBRACES(this, false, fromElement, inclusive, true, EMPTY_VALUE, true); + return new AscendingSubSetBRACES(this, false, fromElement, inclusive, true, EMPTY_KEY_VALUE, true); } @Override public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { - return new DescendingSubSetBRACES(this, true, EMPTY_VALUE, true, true, EMPTY_VALUE, true); + return new DescendingSubSetBRACES(this, true, EMPTY_KEY_VALUE, true, true, EMPTY_KEY_VALUE, true); } protected void removeNode(Entry KEY_GENERIC_TYPE entry) { @@ -406,11 +406,11 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE } protected int compare(KEY_TYPE k, KEY_TYPE v) { return comparator != null ? comparator.compare(k, v) : COMPARE_TO_KEY(k, v);} - protected static GENERIC_BRACES boolean isBlack(Entry KEY_GENERIC_TYPE p) { return p == null || p.isBlack(); } - protected static GENERIC_BRACES Entry KEY_GENERIC_TYPE parentOf(Entry KEY_GENERIC_TYPE p) { return (p == null ? null : p.parent); } - protected static GENERIC_BRACES void setBlack(Entry KEY_GENERIC_TYPE p, boolean c) { if(p != null) p.setBlack(c); } - protected static GENERIC_BRACES Entry KEY_GENERIC_TYPE leftOf(Entry KEY_GENERIC_TYPE p) { return p == null ? null : p.left; } - protected static GENERIC_BRACES Entry KEY_GENERIC_TYPE rightOf(Entry KEY_GENERIC_TYPE p) { return (p == null) ? null : p.right; } + protected static GENERIC_KEY_BRACES boolean isBlack(Entry KEY_GENERIC_TYPE p) { return p == null || p.isBlack(); } + protected static GENERIC_KEY_BRACES Entry KEY_GENERIC_TYPE parentOf(Entry KEY_GENERIC_TYPE p) { return (p == null ? null : p.parent); } + protected static GENERIC_KEY_BRACES void setBlack(Entry KEY_GENERIC_TYPE p, boolean c) { if(p != null) p.setBlack(c); } + protected static GENERIC_KEY_BRACES Entry KEY_GENERIC_TYPE leftOf(Entry KEY_GENERIC_TYPE p) { return p == null ? null : p.left; } + protected static GENERIC_KEY_BRACES Entry KEY_GENERIC_TYPE rightOf(Entry KEY_GENERIC_TYPE p) { return (p == null) ? null : p.right; } /** From CLR */ protected void rotateLeft(Entry KEY_GENERIC_TYPE entry) { diff --git a/src/main/resources/speiger/assets/collections/templates/utils/Arrays.template b/src/main/resources/speiger/assets/collections/templates/utils/Arrays.template index 208a56b1..65b639d4 100644 --- a/src/main/resources/speiger/assets/collections/templates/utils/Arrays.template +++ b/src/main/resources/speiger/assets/collections/templates/utils/Arrays.template @@ -100,13 +100,13 @@ public class ARRAYS * @param length the lenght the array should be. * @return a Array with the requested type and length */ - public static GENERIC_BRACES KEY_TYPE[] newArray(Class clz, int length) { + public static GENERIC_KEY_BRACES KEY_TYPE[] newArray(Class clz, int length) { if(clz == Object.class) return (KEY_TYPE[])new Object[length]; return (KEY_TYPE[]) java.lang.reflect.Array.newInstance(clz, length); } #endif - public static GENERIC_BRACES int shiftDown(KEY_TYPE[] data, int size, int index, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES int shiftDown(KEY_TYPE[] data, int size, int index, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { int half = size >>> 1; KEY_TYPE value = data[index]; if(comp != null) { @@ -135,7 +135,7 @@ public class ARRAYS return index; } - public static GENERIC_BRACES int shiftUp(KEY_TYPE[] data, int index, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES int shiftUp(KEY_TYPE[] data, int index, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { KEY_TYPE value = data[index]; if(comp != null) { while(index > 0) { @@ -159,16 +159,16 @@ public class ARRAYS return index; } - public static GENERIC_BRACES KEY_TYPE[] heapify(KEY_TYPE[] data, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES KEY_TYPE[] heapify(KEY_TYPE[] data, int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { for(int i = (size >>> 1) - 1;i>=0;shiftDown(data, size, i--, comp)); return data; } - public static GENERIC_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array) { + public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array) { return shuffle(array, SanityChecks.getRandom()); } - public static GENERIC_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, Random random) { + public static GENERIC_KEY_BRACES KEY_TYPE[] shuffle(KEY_TYPE[] array, Random random) { for(int i = array.length-1; i>=0;i--) { int p = random.nextInt(i + 1); KEY_TYPE t = array[i]; @@ -185,7 +185,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void stableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { stableSort(array, 0, array.length, comp); } @@ -197,7 +197,7 @@ public class ARRAYS * @param length the maxmium size of the array to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void stableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { stableSort(array, 0, length, comp); } @@ -210,7 +210,7 @@ public class ARRAYS * @param to where the array should be sorted to * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void stableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { mergeSort(array, null, from, to, comp); } @@ -220,7 +220,7 @@ public class ARRAYS * Stable sort referres to Mergesort or Insertionsort * @param array the array that needs to be sorted */ - public static COMPAREABLE_BRACES void stableSort(KEY_TYPE[] array) { + public static COMPAREABLE_KEY_BRACES void stableSort(KEY_TYPE[] array) { stableSort(array, 0, array.length); } @@ -231,7 +231,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param length the maxmium size of the array to be sorted */ - public static COMPAREABLE_BRACES void stableSort(KEY_TYPE[] array, int length) { + public static COMPAREABLE_KEY_BRACES void stableSort(KEY_TYPE[] array, int length) { stableSort(array, 0, length); } @@ -243,7 +243,7 @@ public class ARRAYS * @param from where the array should be sorted from * @param to where the array should be sorted to */ - public static COMPAREABLE_BRACES void stableSort(KEY_TYPE[] array, int from, int to) { + public static COMPAREABLE_KEY_BRACES void stableSort(KEY_TYPE[] array, int from, int to) { mergeSort(array, null, from, to); } @@ -254,7 +254,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void unstableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { unstableSort(array, 0, array.length, comp); } @@ -266,7 +266,7 @@ public class ARRAYS * @param length the maxmium size of the array to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void unstableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { unstableSort(array, 0, length, comp); } @@ -279,7 +279,7 @@ public class ARRAYS * @param to where the array should be sorted to * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void unstableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { quickSort(array, from, to, comp); } @@ -289,7 +289,7 @@ public class ARRAYS * Unstable sort referres to QuickSort or SelectionSort * @param array the array that needs to be sorted */ - public static COMPAREABLE_BRACES void unstableSort(KEY_TYPE[] array) { + public static COMPAREABLE_KEY_BRACES void unstableSort(KEY_TYPE[] array) { unstableSort(array, 0, array.length); } @@ -300,7 +300,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param length the maxmium size of the array to be sorted */ - public static COMPAREABLE_BRACES void unstableSort(KEY_TYPE[] array, int length) { + public static COMPAREABLE_KEY_BRACES void unstableSort(KEY_TYPE[] array, int length) { unstableSort(array, 0, length); } @@ -312,7 +312,7 @@ public class ARRAYS * @param from where the array should be sorted from * @param to where the array should be sorted to */ - public static COMPAREABLE_BRACES void unstableSort(KEY_TYPE[] array, int from, int to) { + public static COMPAREABLE_KEY_BRACES void unstableSort(KEY_TYPE[] array, int from, int to) { quickSort(array, from, to); } @@ -321,7 +321,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void insertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { insertionSort(array, 0, array.length, comp); } @@ -331,7 +331,7 @@ public class ARRAYS * @param length the maxmium size of the array to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void insertionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { insertionSort(array, 0, length, comp); } @@ -342,7 +342,7 @@ public class ARRAYS * @param to where the array should be sorted to * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void insertionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { for (int i = from+1;iFastUtil with a couple custom optimizations * @param array the array that needs to be sorted */ - public static COMPAREABLE_BRACES void mergeSort(KEY_TYPE[] array) { + public static COMPAREABLE_KEY_BRACES void mergeSort(KEY_TYPE[] array) { mergeSort(array, null, 0, array.length); } @@ -530,7 +530,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param length the maxmium size of the array to be sorted */ - public static COMPAREABLE_BRACES void mergeSort(KEY_TYPE[] array, int length) { + public static COMPAREABLE_KEY_BRACES void mergeSort(KEY_TYPE[] array, int length) { mergeSort(array, null, 0, length); } @@ -541,7 +541,7 @@ public class ARRAYS * @param from where the array should be sorted from * @param to where the array should be sorted to */ - public static COMPAREABLE_BRACES void mergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) { + public static COMPAREABLE_KEY_BRACES void mergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) { if(to - from < BASE_THRESHOLD) { insertionSort(array, from, to); return; @@ -568,7 +568,7 @@ public class ARRAYS * @param comp the Comparator that decides the sorting order * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static GENERIC_BRACES void parallelMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { parallelMergeSort(array, null, 0, array.length, comp); } @@ -580,7 +580,7 @@ public class ARRAYS * @param comp the Comparator that decides the sorting order * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static GENERIC_BRACES void parallelMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { parallelMergeSort(array, null, 0, length, comp); } @@ -593,7 +593,7 @@ public class ARRAYS * @param comp the Comparator that decides the sorting order * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static GENERIC_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) { SanityChecks.invokeTask(new MergeSortActionCompBRACES(array, supp, from, to, comp)); return; @@ -607,7 +607,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static COMPAREABLE_BRACES void parallelMergeSort(KEY_TYPE[] array) { + public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array) { parallelMergeSort(array, null, 0, array.length); } @@ -618,7 +618,7 @@ public class ARRAYS * @param length the maxmium size of the array to be sorted * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static COMPAREABLE_BRACES void parallelMergeSort(KEY_TYPE[] array, int length) { + public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, int length) { parallelMergeSort(array, null, 0, length); } @@ -630,7 +630,7 @@ public class ARRAYS * @param to where the array should be sorted to * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static COMPAREABLE_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) { + public static COMPAREABLE_KEY_BRACES void parallelMergeSort(KEY_TYPE[] array, KEY_TYPE[] supp, int from, int to) { if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) { SanityChecks.invokeTask(new MergeSortActionBRACES(array, supp, from, to)); return; @@ -644,7 +644,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void memFreeMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { memFreeMergeSort(array, 0, array.length, comp); } @@ -655,7 +655,7 @@ public class ARRAYS * @param length the maxmium size of the array to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { memFreeMergeSort(array, 0, length, comp); } @@ -667,7 +667,7 @@ public class ARRAYS * @param to where the array should be sorted to * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { if(to - from < BASE_THRESHOLD) { insertionSort(array, from, to, comp); return; @@ -714,7 +714,7 @@ public class ARRAYS * @author Speiger * @param array the array that needs to be sorted */ - public static COMPAREABLE_BRACES void memFreeMergeSort(KEY_TYPE[] array) { + public static COMPAREABLE_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array) { memFreeMergeSort(array, 0, array.length); } @@ -727,7 +727,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param length the maxmium size of the array to be sorted */ - public static COMPAREABLE_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length) { + public static COMPAREABLE_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int length) { memFreeMergeSort(array, 0, length); } @@ -741,7 +741,7 @@ public class ARRAYS * @param from where the array should be sorted from * @param to where the array should be sorted to */ - public static COMPAREABLE_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to) { + public static COMPAREABLE_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array, int from, int to) { if(to - from < BASE_THRESHOLD) { insertionSort(array, from, to); return; @@ -790,7 +790,7 @@ public class ARRAYS * @param comp the Comparator that decides the sorting order * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static GENERIC_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { parallelMemFreeMergeSort(array, 0, array.length, comp); } @@ -805,7 +805,7 @@ public class ARRAYS * @param comp the Comparator that decides the sorting order * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static GENERIC_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { parallelMemFreeMergeSort(array, 0, length, comp); } @@ -821,7 +821,7 @@ public class ARRAYS * @param comp the Comparator that decides the sorting order * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static GENERIC_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) { SanityChecks.invokeTask(new MemFreeMergeSortActionCompBRACES(array, from, to, comp)); return; @@ -838,7 +838,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static COMPAREABLE_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array) { + public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array) { parallelMemFreeMergeSort(array, 0, array.length); } @@ -852,7 +852,7 @@ public class ARRAYS * @param length the maxmium size of the array to be sorted * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static COMPAREABLE_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length) { + public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int length) { parallelMemFreeMergeSort(array, 0, length); } @@ -867,7 +867,7 @@ public class ARRAYS * @param to where the array should be sorted to * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static COMPAREABLE_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to) { + public static COMPAREABLE_KEY_BRACES void parallelMemFreeMergeSort(KEY_TYPE[] array, int from, int to) { if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) { SanityChecks.invokeTask(new MemFreeMergeSortActionBRACES(array, from, to)); return; @@ -882,7 +882,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void quickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { quickSort(array, 0, array.length, comp); } @@ -894,7 +894,7 @@ public class ARRAYS * @param length the maxmium size of the array to be sorted * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void quickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { quickSort(array, 0, length, comp); } @@ -907,7 +907,7 @@ public class ARRAYS * @param to where the array should be sorted to * @param comp the Comparator that decides the sorting order */ - public static GENERIC_BRACES void quickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { int length = to - from; if(length <= 0) return; if(length < BASE_THRESHOLD) { @@ -937,7 +937,7 @@ public class ARRAYS * and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages1249−1265, 1993. * @param array the array that needs to be sorted */ - public static COMPAREABLE_BRACES void quickSort(KEY_TYPE[] array) { + public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array) { quickSort(array, 0, array.length); } @@ -948,7 +948,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @param length the maxmium size of the array to be sorted */ - public static COMPAREABLE_BRACES void quickSort(KEY_TYPE[] array, int length) { + public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array, int length) { quickSort(array, 0, length); } @@ -960,7 +960,7 @@ public class ARRAYS * @param from where the array should be sorted from * @param to where the array should be sorted to */ - public static COMPAREABLE_BRACES void quickSort(KEY_TYPE[] array, int from, int to) { + public static COMPAREABLE_KEY_BRACES void quickSort(KEY_TYPE[] array, int from, int to) { int length = to - from; if(length <= 0) return; if(length < BASE_THRESHOLD) { @@ -992,7 +992,7 @@ public class ARRAYS * @param comp the Comparator that decides the sorting order * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static GENERIC_BRACES void parallelQuickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) { parallelQuickSort(array, 0, array.length, comp); } @@ -1005,7 +1005,7 @@ public class ARRAYS * @param comp the Comparator that decides the sorting order * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static GENERIC_BRACES void parallelQuickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) { parallelQuickSort(array, 0, length, comp); } @@ -1019,7 +1019,7 @@ public class ARRAYS * @param comp the Comparator that decides the sorting order * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static GENERIC_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { + public static GENERIC_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) { if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) { SanityChecks.invokeTask(new QuickSortActionCompBRACES(array, from, to, comp)); return; @@ -1034,7 +1034,7 @@ public class ARRAYS * @param array the array that needs to be sorted * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static COMPAREABLE_BRACES void parallelQuickSort(KEY_TYPE[] array) { + public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array) { parallelQuickSort(array, 0, array.length); } @@ -1046,7 +1046,7 @@ public class ARRAYS * @param length the maxmium size of the array to be sorted * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static COMPAREABLE_BRACES void parallelQuickSort(KEY_TYPE[] array, int length) { + public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int length) { parallelQuickSort(array, 0, length); } @@ -1059,7 +1059,7 @@ public class ARRAYS * @param to where the array should be sorted to * @Note This parallelization is invoked through {@link SanityChecks#invokeTask} which the threadpool can be changed as needed */ - public static COMPAREABLE_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to) { + public static COMPAREABLE_KEY_BRACES void parallelQuickSort(KEY_TYPE[] array, int from, int to) { if(SanityChecks.canParallelTask() && to - from >= PARALLEL_THRESHOLD) { SanityChecks.invokeTask(new QuickSortActionBRACES(array, from, to)); return; @@ -1067,30 +1067,30 @@ public class ARRAYS quickSort(array, from, to); } - static GENERIC_BRACES void swap(KEY_TYPE[] a, int from, int to) { + static GENERIC_KEY_BRACES void swap(KEY_TYPE[] a, int from, int to) { KEY_TYPE t = a[from]; a[from] = a[to]; a[to] = t; } - static GENERIC_BRACES void swap(KEY_TYPE[] a, int from, int to, int length) { + static GENERIC_KEY_BRACES void swap(KEY_TYPE[] a, int from, int to, int length) { to -= length; for(int i = 0;i 0 ? b : comp.compare(data[a], data[c]) > 0 ? c : a); } - static COMPAREABLE_BRACES int subMedium(KEY_TYPE[] data, int a, int b, int c, int length) { + static COMPAREABLE_KEY_BRACES int subMedium(KEY_TYPE[] data, int a, int b, int c, int length) { return medium(data, medium(data, a, a + length, a + (length * 2)), medium(data, b - length, b, b + length), medium(data, c - (length * 2), c - length, c)); } - static COMPAREABLE_BRACES int medium(KEY_TYPE[] data, int a, int b, int c) { + static COMPAREABLE_KEY_BRACES int medium(KEY_TYPE[] data, int a, int b, int c) { return COMPARE_TO(data[a], data[b]) < 0 ? (COMPARE_TO(data[b], data[c]) < 0 ? b : COMPARE_TO(data[a], data[c]) < 0 ? c : a) : (COMPARE_TO(data[b], data[c]) > 0 ? b : COMPARE_TO(data[a], data[c]) > 0 ? c : a); } diff --git a/src/main/resources/speiger/assets/collections/templates/utils/Collections.template b/src/main/resources/speiger/assets/collections/templates/utils/Collections.template index 0a1638bb..f5d94806 100644 --- a/src/main/resources/speiger/assets/collections/templates/utils/Collections.template +++ b/src/main/resources/speiger/assets/collections/templates/utils/Collections.template @@ -25,7 +25,7 @@ public class COLLECTIONS * Returns a Immutable EmptyCollection instance that is automatically casted. * @return an empty collection */ - public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE emptyCollection() { + public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE emptyCollection() { #if TYPE_OBJECT return (COLLECTION)EMPTY; #else @@ -38,7 +38,7 @@ public class COLLECTIONS * @param l that should be made immutable/unmodifyable * @return a unmodifiable collection wrapper. If the Collection already a unmodifyable wrapper then it just returns itself. */ - public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE unmodifiableCollection(COLLECTION KEY_GENERIC_TYPE c) { + public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE unmodifiableCollection(COLLECTION KEY_GENERIC_TYPE c) { return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollectionBRACES(c); } @@ -47,7 +47,7 @@ public class COLLECTIONS * @param l that should be synchronized * @return a synchronized collection wrapper. If the Collection already a synchronized wrapper then it just returns itself. */ - public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c) { + public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c) { return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c); } @@ -57,7 +57,7 @@ public class COLLECTIONS * @param mutex is the controller of the synchronization block. * @return a synchronized collection wrapper. If the Collection already a synchronized wrapper then it just returns itself. */ - public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c, Object mutex) { + public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c, Object mutex) { return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c, mutex); } diff --git a/src/main/resources/speiger/assets/collections/templates/utils/Iterators.template b/src/main/resources/speiger/assets/collections/templates/utils/Iterators.template index 11483957..964e952c 100644 --- a/src/main/resources/speiger/assets/collections/templates/utils/Iterators.template +++ b/src/main/resources/speiger/assets/collections/templates/utils/Iterators.template @@ -16,7 +16,7 @@ public class ITERATORS * Returns a Immutable EmptyIterator instance that is automatically casted. * @return an empty iterator */ - public static GENERIC_BRACES EmptyIterator KEY_GENERIC_TYPE emptyIterator() { + public static GENERIC_KEY_BRACES EmptyIterator KEY_GENERIC_TYPE emptyIterator() { #if TYPE_OBJECT return (EmptyIterator)EMPTY; #else @@ -29,11 +29,11 @@ public class ITERATORS * @param l that should be made immutable/unmodifyable * @return a unmodifiable iterator wrapper. If the Iterator already a unmodifyable wrapper then it just returns itself. */ - public static GENERIC_BRACES ITERATOR KEY_GENERIC_TYPE unmodifiable(ITERATOR KEY_GENERIC_TYPE iterator) { + public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE unmodifiable(ITERATOR KEY_GENERIC_TYPE iterator) { return iterator instanceof UnmodifiableIterator ? iterator : new UnmodifiableIteratorBRACES(iterator); } - public static GENERIC_BRACES BI_ITERATOR KEY_GENERIC_TYPE unmodifiable(BI_ITERATOR KEY_GENERIC_TYPE iterator) { + public static GENERIC_KEY_BRACES BI_ITERATOR KEY_GENERIC_TYPE unmodifiable(BI_ITERATOR KEY_GENERIC_TYPE iterator) { return iterator instanceof UnmodifiableBiIterator ? iterator : new UnmodifiableBiIteratorBRACES(iterator); } @@ -42,7 +42,7 @@ public class ITERATORS * @param l that should be made immutable/unmodifyable * @return a unmodifiable listiterator wrapper. If the ListIterator already a unmodifyable wrapper then it just returns itself. */ - public static GENERIC_BRACES LIST_ITERATOR KEY_GENERIC_TYPE unmodifiable(LIST_ITERATOR KEY_GENERIC_TYPE iterator) { + public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE unmodifiable(LIST_ITERATOR KEY_GENERIC_TYPE iterator) { return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator); } @@ -57,7 +57,7 @@ public class ITERATORS * @param a the array that should be wrapped * @return a Iterator that is wrapping a array. */ - public static GENERIC_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) { + public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) { return wrap(a, 0, a.length); } @@ -68,7 +68,7 @@ public class ITERATORS * @param end the index that should be ended. * @return a Iterator that is wrapping a array. */ - public static GENERIC_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) { + public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) { return new ArrayIteratorBRACES(a, start, end); } @@ -78,7 +78,7 @@ public class ITERATORS * @param i the source iterator * @return the amount of elements that were inserted into the array. */ - public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, Iterator i) { + public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator i) { return unwrap(a, i, 0, a.length); } @@ -89,7 +89,7 @@ public class ITERATORS * @param offset the array offset where the start should be * @return the amount of elements that were inserted into the array. */ - public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, Iterator i, int offset) { + public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator i, int offset) { return unwrap(a, i, offset, a.length - offset); } @@ -102,7 +102,7 @@ public class ITERATORS * @return the amount of elements that were inserted into the array. * @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array */ - public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, Iterator i, int offset, int max) { + public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator i, int offset, int max) { if(max < 0) throw new IllegalStateException("The max size is smaller then 0"); if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size"); int index = 0; @@ -117,7 +117,7 @@ public class ITERATORS * @param i the source iterator * @return the amount of elements that were inserted into the array. */ - public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) { + public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) { return unwrap(a, i, 0, a.length); } @@ -129,7 +129,7 @@ public class ITERATORS * @param offset the array offset where the start should be * @return the amount of elements that were inserted into the array. */ - public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) { + public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) { return unwrap(a, i, offset, a.length - offset); } @@ -143,7 +143,7 @@ public class ITERATORS * @return the amount of elements that were inserted into the array. * @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array */ - public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) { + public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) { if(max < 0) throw new IllegalStateException("The max size is smaller then 0"); if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size"); int index = 0; @@ -159,7 +159,7 @@ public class ITERATORS * @param i the source iterator * @return the amount of elements that were inserted into the array. */ - public static GENERIC_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) { + public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) { return unwrap(a, i, 0, a.length); } @@ -171,7 +171,7 @@ public class ITERATORS * @param offset the array offset where the start should be * @return the amount of elements that were inserted into the array. */ - public static GENERIC_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) { + public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) { return unwrap(a, i, offset, a.length - offset); } @@ -185,7 +185,7 @@ public class ITERATORS * @return the amount of elements that were inserted into the array. * @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array */ - public static GENERIC_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) { + public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) { if(max < 0) throw new IllegalStateException("The max size is smaller then 0"); if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size"); int index = 0; @@ -324,7 +324,7 @@ public class ITERATORS @Override public KEY_TYPE NEXT() { - return EMPTY_VALUE; + return EMPTY_KEY_VALUE; } @Override @@ -334,7 +334,7 @@ public class ITERATORS @Override public KEY_TYPE PREVIOUS() { - return EMPTY_VALUE; + return EMPTY_KEY_VALUE; } @Override diff --git a/src/main/resources/speiger/assets/collections/templates/utils/Lists.template b/src/main/resources/speiger/assets/collections/templates/utils/Lists.template index 321a8eb8..a0061c28 100644 --- a/src/main/resources/speiger/assets/collections/templates/utils/Lists.template +++ b/src/main/resources/speiger/assets/collections/templates/utils/Lists.template @@ -23,7 +23,7 @@ public class LISTS * Returns a Immutable EmptyList instance that is automatically casted. * @return an empty list */ - public static GENERIC_BRACES EmptyList KEY_GENERIC_TYPE emptyList() { + public static GENERIC_KEY_BRACES EmptyList KEY_GENERIC_TYPE emptyList() { #if TYPE_OBJECT return (EmptyList)EMPTY; #else @@ -36,7 +36,7 @@ public class LISTS * @param l that should be made immutable/unmodifyable * @return a unmodifiable list wrapper. If the list is implementing RandomAccess that is also transferred. If the List already a unmodifyable wrapper then it just returns itself. */ - public static GENERIC_BRACES LIST KEY_GENERIC_TYPE unmodifiableList(LIST KEY_GENERIC_TYPE l) { + public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE unmodifiableList(LIST KEY_GENERIC_TYPE l) { return l instanceof UnmodifiableList ? l : l instanceof RandomAccess ? new UnmodifiableRandomListBRACES(l) : new UnmodifiableListBRACES(l); } @@ -45,7 +45,7 @@ public class LISTS * @param l that should be synchronized * @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself. */ - public static GENERIC_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l) { + public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l) { return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l) : new SynchronizedListBRACES(l))); } @@ -55,7 +55,7 @@ public class LISTS * @param mutex is the controller of the synchronization block. * @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself. */ - public static GENERIC_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l, Object mutex) { + public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l, Object mutex) { return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l, mutex) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l, mutex) : new SynchronizedListBRACES(l, mutex))); } diff --git a/src/main/resources/speiger/assets/collections/templates/utils/Sets.template b/src/main/resources/speiger/assets/collections/templates/utils/Sets.template index ca9f5a21..fa15ed85 100644 --- a/src/main/resources/speiger/assets/collections/templates/utils/Sets.template +++ b/src/main/resources/speiger/assets/collections/templates/utils/Sets.template @@ -20,7 +20,7 @@ public class SETS { public static final SET NO_GENERIC_TYPE EMPTY = new EmptySetBRACES(); - public static GENERIC_BRACES SET KEY_GENERIC_TYPE empty() { + public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE empty() { #if TYPE_OBJECT return (SET)EMPTY; #else @@ -28,39 +28,39 @@ public class SETS #endif } - public static GENERIC_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s) { + public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s) { return s instanceof SynchronizedSet ? s : (s instanceof ITrimmable ? new SynchronizedTrimSetBRACES(s) : new SynchronizedSetBRACES(s)); } - public static GENERIC_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s, Object mutex) { + public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s, Object mutex) { return s instanceof SynchronizedSet ? s : (s instanceof ITrimmable ? new SynchronizedTrimSetBRACES(s, mutex) : new SynchronizedSetBRACES(s, mutex)); } - public static GENERIC_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s) { + public static GENERIC_KEY_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s) { return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s) : new SynchronizedSortedSetBRACES(s)); } - public static GENERIC_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s, Object mutex) { + public static GENERIC_KEY_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s, Object mutex) { return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s, mutex) : new SynchronizedSortedSetBRACES(s, mutex)); } - public static GENERIC_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s) { + public static GENERIC_KEY_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s) { return s instanceof SynchronizedNavigableSet ? s : (s instanceof ITrimmable ? new SynchronizedNavigableTrimSetBRACES(s) : new SynchronizedNavigableSetBRACES(s)); } - public static GENERIC_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s, Object mutex) { + public static GENERIC_KEY_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s, Object mutex) { return s instanceof SynchronizedNavigableSet ? s : (s instanceof ITrimmable ? new SynchronizedNavigableTrimSetBRACES(s, mutex) : new SynchronizedNavigableSetBRACES(s, mutex)); } - public static GENERIC_BRACES SET KEY_GENERIC_TYPE unmodifiable(SET KEY_GENERIC_TYPE s) { + public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE unmodifiable(SET KEY_GENERIC_TYPE s) { return s instanceof SynchronizedSet ? s : new SynchronizedSetBRACES(s); } - public static GENERIC_BRACES SORTED_SET KEY_GENERIC_TYPE unmodifiable(SORTED_SET KEY_GENERIC_TYPE s) { + public static GENERIC_KEY_BRACES SORTED_SET KEY_GENERIC_TYPE unmodifiable(SORTED_SET KEY_GENERIC_TYPE s) { return s instanceof SynchronizedSortedSet ? s : new SynchronizedSortedSetBRACES(s); } - public static GENERIC_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable(NAVIGABLE_SET KEY_GENERIC_TYPE s) { + public static GENERIC_KEY_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable(NAVIGABLE_SET KEY_GENERIC_TYPE s) { return s instanceof UnmodifiableNavigableSet ? s : new UnmodifiableNavigableSetBRACES(s); } diff --git a/src/test/java/speiger/src/collections/ints/base/BaseIntPriorityQueueTest.java b/src/test/java/speiger/src/collections/ints/base/BaseIntPriorityQueueTest.java index 2b11dbe2..c8e7d291 100644 --- a/src/test/java/speiger/src/collections/ints/base/BaseIntPriorityQueueTest.java +++ b/src/test/java/speiger/src/collections/ints/base/BaseIntPriorityQueueTest.java @@ -1,7 +1,5 @@ package speiger.src.collections.ints.base; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; import java.util.EnumSet; @@ -9,6 +7,7 @@ import org.junit.Assert; import org.junit.Test; import speiger.src.collections.ints.queues.IntPriorityQueue; +import speiger.src.collections.ints.utils.IntArrays; import speiger.src.collections.tests.IterableTest; import speiger.src.collections.tests.PriorityQueueTest; @@ -19,6 +18,7 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest @Override protected EnumSet getValidIterableTests() { return EnumSet.of(IterableTest.FOR_EACH, IterableTest.ITERATOR_FOR_EACH, IterableTest.ITERATOR_LOOP, IterableTest.ITERATOR_SKIP); } protected EnumSet getValidPriorityQueueTests() { return EnumSet.allOf(PriorityQueueTest.class); } + protected boolean isUnsortedRead() { return true; } @Test public void testEnqueue() { @@ -26,11 +26,12 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest IntPriorityQueue queue = create(EMPTY_ARRAY); for(int i = 0;i<100;i++) { queue.enqueueInt(i); - Assert.assertEquals(i, queue.lastInt()); } for(int i = 0;i<100;i++) { - Assert.assertEquals(i, queue.firstInt()); - Assert.assertEquals(99, queue.lastInt()); + Assert.assertEquals(i, queue.dequeueInt()); + } + queue = create(TEST_ARRAY); + for(int i = 0;i<100;i++) { Assert.assertEquals(i, queue.dequeueInt()); } } @@ -42,10 +43,17 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest IntPriorityQueue queue = create(EMPTY_ARRAY); for(int i = 0;i<100;i++) { queue.enqueueInt(i); - Assert.assertEquals(i, queue.lastInt()); } - for(int i = 0;i<100;i++) { - assertEquals(i, queue.peekInt(i)); + if(isUnsortedRead()) { + for(int i = 0;i<100;i++) { + int value = queue.peekInt(i); + Assert.assertTrue(value >= 0 && value < 100); + } + } + else { + for(int i = 0;i<100;i++) { + Assert.assertEquals(i, queue.peekInt(i)); + } } } } @@ -56,21 +64,19 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest IntPriorityQueue queue = create(EMPTY_ARRAY); for(int i = 0;i<100;i++) { queue.enqueueInt(i); - Assert.assertEquals(i, queue.lastInt()); } queue.removeInt(40); for(int i = 0;i<99;i++) { - if(i >= 40) assertEquals(i + 1, queue.dequeueInt()); - else assertEquals(i, queue.dequeueInt()); + if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt()); + else Assert.assertEquals(i, queue.dequeueInt()); } for(int i = 0;i<100;i++) { queue.enqueueInt(i); - Assert.assertEquals(i, queue.lastInt()); } queue.removeLastInt(40); for(int i = 0;i<99;i++) { - if(i >= 40) assertEquals(i + 1, queue.dequeueInt()); - else assertEquals(i, queue.dequeueInt()); + if(i >= 40) Assert.assertEquals(i + 1, queue.dequeueInt()); + else Assert.assertEquals(i, queue.dequeueInt()); } } } @@ -79,36 +85,45 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest @SuppressWarnings("deprecation") public void testToArray() { if(getValidPriorityQueueTests().contains(PriorityQueueTest.TO_ARRAY)) { - IntPriorityQueue q = create(EMPTY_ARRAY); - Integer[] ref = new Integer[100]; - Integer[] shiftArray = new Integer[100]; - int[] primRef = new int[100]; - int[] shiftPrimArray = new int[100]; - for(int i = 0; i < 100; i++) { - q.enqueue(i); - assertEquals(i, q.lastInt()); - ref[i] = Integer.valueOf(i); - primRef[i] = i; - shiftPrimArray[(i+80) % 100] = i; - shiftArray[(i+80) % 100] = Integer.valueOf(i); + IntPriorityQueue queue = create(EMPTY_ARRAY); + if(isUnsortedRead()) { + for(int i = 0;i<100;i++) { + queue.enqueueInt(i); + } + int[] array = queue.toIntArray(); + IntArrays.stableSort(array); + Assert.assertArrayEquals(TEST_ARRAY, array); + int[] data = queue.toIntArray(new int[100]); + int[] nonData = queue.toIntArray(new int[0]); + IntArrays.stableSort(data); + IntArrays.stableSort(nonData); + Assert.assertArrayEquals(array, data); + Assert.assertArrayEquals(array, nonData); } - assertArrayEquals(q.toArray(), ref); - assertArrayEquals(q.toArray(new Integer[100]), ref); - assertArrayEquals(q.toArray(null), ref); - assertArrayEquals(q.toIntArray(), primRef); - assertArrayEquals(q.toIntArray(new int[100]), primRef); - assertArrayEquals(q.toIntArray(null), primRef); - IntPriorityQueue other = create(q.toIntArray()); - for(int i = 0;i<100;i++) { - assertEquals(other.peekInt(i), primRef[i]); + else { + Integer[] ref = IntArrays.wrap(TEST_ARRAY); + Integer[] shiftArray = new Integer[100]; + int[] shiftPrimArray = new int[100]; + for(int i = 0; i < 100; i++) { + queue.enqueue(i); + shiftPrimArray[(i+80) % 100] = i; + shiftArray[(i+80) % 100] = Integer.valueOf(i); + } + Assert.assertArrayEquals(ref, queue.toArray()); + Assert.assertArrayEquals(ref, queue.toArray(new Integer[100])); + Assert.assertArrayEquals(ref, queue.toArray(null)); + Assert.assertArrayEquals(TEST_ARRAY, queue.toIntArray()); + Assert.assertArrayEquals(TEST_ARRAY, queue.toIntArray(new int[100])); + Assert.assertArrayEquals(TEST_ARRAY, queue.toIntArray(null)); + IntPriorityQueue other = create(queue.toIntArray()); + for(int i = 0;i<20;i++) { + other.dequeueInt(); + other.enqueue(i); + } + Assert.assertArrayEquals(shiftPrimArray, other.toIntArray()); + Assert.assertArrayEquals(shiftPrimArray, other.toIntArray(new int[100])); + Assert.assertArrayEquals(shiftArray, other.toArray()); } - for(int i = 0;i<20;i++) { - other.dequeueInt(); - other.enqueue(i); - } - assertArrayEquals(other.toIntArray(), shiftPrimArray); - assertArrayEquals(other.toIntArray(new int[100]), shiftPrimArray); - assertArrayEquals(other.toArray(), shiftArray); } } } diff --git a/src/test/java/speiger/src/collections/ints/queues/IntArrayFIFOQueueTests.java b/src/test/java/speiger/src/collections/ints/queues/IntArrayFIFOQueueTests.java index 1dff9547..d9c7b89e 100644 --- a/src/test/java/speiger/src/collections/ints/queues/IntArrayFIFOQueueTests.java +++ b/src/test/java/speiger/src/collections/ints/queues/IntArrayFIFOQueueTests.java @@ -6,4 +6,7 @@ public class IntArrayFIFOQueueTests extends BaseIntPriorityQueueTest { @Override protected IntPriorityQueue create(int[] data){return new IntArrayFIFOQueue(data);} + + @Override + protected boolean isUnsortedRead() { return false; } } diff --git a/src/test/java/speiger/src/collections/ints/queues/IntArrayPriorityQueueTests.java b/src/test/java/speiger/src/collections/ints/queues/IntArrayPriorityQueueTests.java new file mode 100644 index 00000000..e6d8855f --- /dev/null +++ b/src/test/java/speiger/src/collections/ints/queues/IntArrayPriorityQueueTests.java @@ -0,0 +1,11 @@ +package speiger.src.collections.ints.queues; + +import speiger.src.collections.ints.base.BaseIntPriorityQueueTest; + +public class IntArrayPriorityQueueTests extends BaseIntPriorityQueueTest +{ + @Override + protected IntPriorityQueue create(int[] data) { + return new IntArrayPriorityQueue(data); + } +} diff --git a/src/test/java/speiger/src/collections/ints/queues/IntHeapPriorityQueueTests.java b/src/test/java/speiger/src/collections/ints/queues/IntHeapPriorityQueueTests.java new file mode 100644 index 00000000..efeea750 --- /dev/null +++ b/src/test/java/speiger/src/collections/ints/queues/IntHeapPriorityQueueTests.java @@ -0,0 +1,11 @@ +package speiger.src.collections.ints.queues; + +import speiger.src.collections.ints.base.BaseIntPriorityQueueTest; + +public class IntHeapPriorityQueueTests extends BaseIntPriorityQueueTest +{ + @Override + protected IntPriorityQueue create(int[] data) { + return new IntHeapPriorityQueue(data); + } +} \ No newline at end of file