From 42458bc4a3912fa06b0469d00ec9511dd3c9b27d Mon Sep 17 00:00:00 2001 From: Speiger Date: Thu, 21 Jan 2021 21:35:23 +0100 Subject: [PATCH] More work. -Added: BiFunction -Added: Function -Added: BiConsumer -Changed: Remapping Names to be more friendly for KEY_VALUE. -Added: A Bunch of Variables --- libs/Simple Code Generator-1.0.1-sources.jar | Bin 12996 -> 13065 bytes libs/Simple Code Generator-1.0.1.jar | Bin 26299 -> 26428 bytes .../src/builder/example/ClassType.java | 52 +++++++ .../src/builder/example/GlobalVariables.java | 94 +++++++++--- .../src/builder/example/TestBuilder.java | 50 ++++-- .../collections/AbstractCollection.template | 4 +- .../templates/functions/Consumer.template | 24 +-- .../functions/consumer/BiConsumer.template | 35 +++++ .../functions/function/BiFunction.template | 26 ++++ .../functions/function/Function.template | 59 +++++++ .../templates/lists/AbstractList.template | 10 +- .../templates/lists/ArrayList.template | 12 +- .../queues/ArrayPriorityQueue.template | 18 +-- .../queues/HeapPriorityQueue.template | 12 +- .../templates/queues/PriorityDequeue.template | 2 + .../templates/queues/PriorityQueue.template | 4 +- .../templates/sets/AVLTreeSet.template | 6 +- .../templates/sets/AbstractSet.template | 4 +- .../templates/sets/ArraySet.template | 18 +-- .../sets/LinkedOpenCustomHashSet.template | 38 ++--- .../templates/sets/LinkedOpenHashSet.template | 68 ++++----- .../templates/sets/OpenCustomHashSet.template | 52 +++---- .../templates/sets/OpenHashSet.template | 70 ++++----- .../templates/sets/RBTreeSet.template | 16 +- .../templates/utils/Arrays.template | 144 +++++++++--------- .../templates/utils/Collections.template | 8 +- .../templates/utils/Iterators.template | 34 ++--- .../templates/utils/Lists.template | 8 +- .../collections/templates/utils/Sets.template | 20 +-- .../ints/base/BaseIntPriorityQueueTest.java | 99 +++++++----- .../ints/queues/IntArrayFIFOQueueTests.java | 3 + .../queues/IntArrayPriorityQueueTests.java | 11 ++ .../queues/IntHeapPriorityQueueTests.java | 11 ++ 33 files changed, 645 insertions(+), 367 deletions(-) create mode 100644 src/main/resources/speiger/assets/collections/templates/functions/consumer/BiConsumer.template create mode 100644 src/main/resources/speiger/assets/collections/templates/functions/function/BiFunction.template create mode 100644 src/main/resources/speiger/assets/collections/templates/functions/function/Function.template create mode 100644 src/test/java/speiger/src/collections/ints/queues/IntArrayPriorityQueueTests.java create mode 100644 src/test/java/speiger/src/collections/ints/queues/IntHeapPriorityQueueTests.java diff --git a/libs/Simple Code Generator-1.0.1-sources.jar b/libs/Simple Code Generator-1.0.1-sources.jar index 3033ef5db5803a0b0441a9c6191fd6c95ef8b931..ed45e4882ce20e256b7b6ca545611a879c204473 100644 GIT binary patch delta 2446 zcmZWrdoWSgAP2-BeA0R2(2JYmiL+Y2OCP zFg;-#X*R^sUSJ)P@qF7t;#)OD?lEN4?K5ts$Y26I}29I`;P9iF#0V<0D zSQDCL-?C^OOfP4+L$c6HayzVEXJPI&kHzin5i{?V#}*FZ<3^68>!-2lO7IipUlv8QrVafRmUgixVd0I+@4V#j?MTsq)6Q{-eFv#YrDB2OQx%KfR z@s|)Gy27G@le<3N@sWdXwDp(y_1khUr1u@u60$Mt7L-nKPS(O71q`1}5a6u)zHzf{ zm)v}`t9oomMCTbI>x~K5*7B#Y^~i$3A}xk6CP5uj-SlZvw;n8&?Jd(7r@XrLhOEbaZ)Fbkw|5ru zt9;5d65Co<-$Z5^k#w$&z4CW|xl&%2e=ho3mm%4>fNB`TA;BiPd`<6u96>8G+{+FlWm3E03k&=eDwC8uyMa4-2SKQ>p z+k!9-{T>;c+B>=z&#zfwz+3AfgNbn`EjNHq7jEUB-wt0DZ-`UY&AZpu73u7By zx9hrZ%^EHjHtUQ%*Sk96ku4oyc7IDI_T2$Ee%SO6UeTMpaZJSxF+Gno54Xws@_cI# z& zmn2jwEPX^7?{WlFo_qle0wEzF5C*V@z<`V&L;)``X&O0r5-S(iK;x9Fr`pR5Km0M| zC{k4ps!VLe*(s&QE}nNi>y(}QAb4jh<4hlQNR*N=p0chQ3sWuUzmxPvu%Ltl(}SiC zIS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3(9E=eb}I;neI?oX+*!BRg|jx zW}r#SYkkCQj6JXsWbe)T$Ep;UVQXp=L)h%6={cv9qZgMkdySV8zj`^a2j1KWOPHfb zyf_)&BNyIdZc#9^n7%k-v69=)djDOh~9C>rI*GGc^MMzx}R zN_W!(bkqHGt-44Sl`jTHi<&0luajEXk?a+R>~(ijV!(vP*u?u*jh2MMrUWBz1QA-$ zV)Gzn3(DF+U*mxt^;cnC6HDd5uHD&94RW80-~&v+cr{&Iq` zvc&0>&37z*Osx}TFn6@Wxzgk6zKwUYvYv*#y}Kv~3&{PjDN5#?qQVDM^%=X zfTY8R%~@>Vh->dqZa`QsIo8$e$l6$UR@&cd6#|Wq>R^fP>mOnkn=D>8GluRs9bFtTojEYe3U%R_kc}ER^PS^~wVpv+ zrDEI5(P8!diuY!^-eM`47O=9ZcD?*UPoIeNOGxv)w)TZYA*aR9!XuIEUep=~N|k@J zPmT7zh}UNVKbde^eJav!TzxrN5jZ}%^lD6_p$CtqbFRVM^z3Cgtt7=4j&Dk`PVZ@e zz}BL*SW0rb2-x;}&N{9f^v8ofrVA$R09 zBn^tFDMRyrg=j12wgjp$dEcrz64l|2o?z4;E?Rpo6kI!w2Q0gzT&k96!Zy O+w~e30PrdQ?EM#6;US0s diff --git a/libs/Simple Code Generator-1.0.1.jar b/libs/Simple Code Generator-1.0.1.jar index e21ac446189d897c7c2e9c4cd4d895475bbfca5b..72d45d1865753ba971cf24c20a39355654733ad4 100644 GIT binary patch delta 5952 zcmZ8lWmuG5*PR)pyJILpIwhqWq`OOoZjcTcQ94F+XpkDZ8-YP7L0~9p5Kv0G1PM_- zpYge#_wu{{oPDjm&pPYeKh8S)bdCa%V?aVZO^iEu000gSzyl%rlJEz{?*Wbv6eIdQ z8fayd-_~FQ00|^;U7!SXFNk83_O@$b1U06^Y`*XTinuueBv@wv@W^ycbKWD*U_mwuDSs8PoN9;-4mAu!&Wv zPIJ(LyumBvk?{DBPphlnP{$`T#Ikql!KNbniZ%)gN`$Af+x44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H$=t9dI*UR|PH5dKv@#2WDcJ=Qvzl#{= z`o|fJcCh*rS$vt#_K(Lbp=-o{e^3+n6BY+QwCrl{0e43lUe@>z+}w; zZ21lG-2R``b=xR;r`N8oIGF?h0M~yKnUzLIS&Lj>Mle@=O2sQaE&AM=_PT(-_Yx2Q z!1o`X_8-UB>O^S0Ck)qomnRHBjM_E-wL0^Ea=7{zb=|~^Kk$$O04vM@0Q^6(JhlEI PfzeDhH}Li!|F-@guZ^x( diff --git a/src/main/java/speiger/src/builder/example/ClassType.java b/src/main/java/speiger/src/builder/example/ClassType.java index fa9a265..e6ff4c9 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 05fc924..cb26cfb 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 433a882..38dcf08 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 0000000..bd0bdfd --- /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 0000000..2121724 --- /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 0000000..e7388a7 --- /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 956b120..8fd18a0 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 5e7a3d0..bd4159e 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 a7b9c74..0016e00 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 41fbb90..569dd0d 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 1aff3f7..9c77015 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 4ea46e8..a29c553 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 e35d63d..afecbf1 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 fd3df0f..141b836 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 9c20c5b..6db3590 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 9d53a9d..8d17ae5 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 a3aca05..4e7b3ed 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 208a56b..65b639d 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 0a1638b..f5d9480 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 1148395..964e952 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 321a8eb..a0061c2 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 ca9f5a2..fa15ed8 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 2b11dbe..c8e7d29 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 1dff954..d9c7b89 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 0000000..e6d8855 --- /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 0000000..efeea75 --- /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