From 8d079ae0abce46b96282d82e395fdbf7dd60fb28 Mon Sep 17 00:00:00 2001 From: Speiger Date: Tue, 1 Dec 2020 02:43:13 +0100 Subject: [PATCH] More Work done on the Collections. -Added: Empty/Synchronized/Unmodifiable Collections/Lists/Iterators -Changed: ObjectCollections now have more bulk Methods -Added: IArray for functions that would only apply to arrays. --- .../src/builder/example/GlobalVariables.java | 11 +- .../src/builder/example/TestBuilder.java | 5 +- .../collections/AbstractCollection.template | 40 +- .../templates/collections/Collection.template | 29 +- .../templates/lists/AbstractList.template | 12 +- .../templates/lists/ArrayList.template | 154 ++++++-- .../collections/templates/lists/List.template | 64 ++- .../templates/utils/Arrays.template | 49 +++ .../templates/utils/Collections.template | 369 ++++++++++++++++++ .../templates/utils/IArray.template | 8 + .../templates/utils/Iterators.template | 130 +++++- .../templates/utils/Lists.template | 367 +++++++++++++++++ 12 files changed, 1174 insertions(+), 64 deletions(-) create mode 100644 src/main/resources/speiger/assets/collections/templates/utils/Collections.template create mode 100644 src/main/resources/speiger/assets/collections/templates/utils/IArray.template create mode 100644 src/main/resources/speiger/assets/collections/templates/utils/Lists.template diff --git a/src/main/java/speiger/src/builder/example/GlobalVariables.java b/src/main/java/speiger/src/builder/example/GlobalVariables.java index 710f111..3a7cafc 100644 --- a/src/main/java/speiger/src/builder/example/GlobalVariables.java +++ b/src/main/java/speiger/src/builder/example/GlobalVariables.java @@ -32,7 +32,9 @@ public class GlobalVariables addSimpleMapper("KEY_TYPE", type.getKeyType()); addSimpleMapper("EMPTY_VALUE", type.getEmptyValue()); addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : ""); + 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("BRACES", type.isObject() ? "<>" : ""); @@ -61,16 +63,18 @@ 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("UNARY_OPERATOR", type.isPrimitiveBlocking() ? "" : type == ClassType.BOOLEAN ? "BinaryOperator" : type.getCustomJDKType().getFileType()+"UnaryOperator"); + addSimpleMapper("UNARY_OPERATOR", type.isObject() ? "" : type == ClassType.BOOLEAN ? "BinaryOperator" : type.getCustomJDKType().getFileType()+"UnaryOperator"); if(type.isObject()) { addSimpleMapper("CONSUMER", "Consumer"); addSimpleMapper("COMPARATOR", "Comparator"); + addSimpleMapper("IARRAY", "IObjectArray"); } else { addClassMapper("CONSUMER", "Consumer"); addClassMapper("COMPARATOR", "Comparator"); + addFunctionMappers("IARRAY", "I%sArray"); } addClassMapper("ITERATORS", "Iterators"); addClassMapper("BI_ITERATOR", "BidirectionalIterator"); @@ -78,10 +82,12 @@ public class GlobalVariables addClassMapper("ITERATOR", "Iterator"); addClassMapper("ITERABLE", "Iterable"); addClassMapper("ABSTRACT_COLLECTION", "AbstractCollection"); + addClassMapper("COLLECTIONS", "Collections"); addClassMapper("COLLECTION", "Collection"); addClassMapper("ARRAYS", "Arrays"); addClassMapper("ABSTRACT_LIST", "AbstractList"); addClassMapper("LIST_ITER", "ListIter"); + addClassMapper("LISTS", "Lists"); addClassMapper("SUB_LIST", "SubList"); addClassMapper("ARRAY_LIST", "ArrayList"); addClassMapper("LIST", "List"); @@ -102,6 +108,7 @@ public class GlobalVariables addFunctionMapper("PUSH", "push"); addFunctionMapper("TOP", "top"); addFunctionMappers("REPLACE", "replace%ss"); + addFunctionMappers("SORT", "sort%ss"); return this; } @@ -121,7 +128,7 @@ public class GlobalVariables public TemplateProcess create(String fileName) { - TemplateProcess process = new TemplateProcess(type.getFileType()+fileName+".java"); + TemplateProcess process = new TemplateProcess(String.format(fileName+".java", type.getFileType())); process.setPathBuilder(new PathBuilder(type.getPathType())); process.addFlags(flags); process.addMappers(operators); diff --git a/src/main/java/speiger/src/builder/example/TestBuilder.java b/src/main/java/speiger/src/builder/example/TestBuilder.java index 2ca13c3..fcae1e0 100644 --- a/src/main/java/speiger/src/builder/example/TestBuilder.java +++ b/src/main/java/speiger/src/builder/example/TestBuilder.java @@ -16,9 +16,11 @@ import speiger.src.builder.processor.TemplateProcessor; public class TestBuilder extends TemplateProcessor { Map> blocked = new HashMap>(); + Map nameRemapper = new HashMap(); public static final ClassType[] TYPE = ClassType.values(); List varibles = new ArrayList(); + public TestBuilder() { super(Paths.get("src\\main\\resources\\speiger\\assets\\collections\\templates\\"), Paths.get("src\\main\\java\\speiger\\src\\collections\\"), Paths.get("src\\main\\resources\\speiger\\assets\\collections\\")); @@ -50,6 +52,7 @@ public class TestBuilder extends TemplateProcessor type.createFunctions(); varibles.add(type); } + nameRemapper.put("IArray", "I%sArray"); blocked.put("Consumer", EnumSet.of(ClassType.OBJECT)); blocked.put("Comparator", EnumSet.of(ClassType.OBJECT)); blocked.put("Stack", EnumSet.of(ClassType.OBJECT)); @@ -64,7 +67,7 @@ public class TestBuilder extends TemplateProcessor GlobalVariables type = varibles.get(i); if(types == null || !types.contains(type.getType())) { - acceptor.accept(type.create(name)); + acceptor.accept(type.create(nameRemapper.getOrDefault(name, "%s"+name))); } } } diff --git a/src/main/resources/speiger/assets/collections/templates/collections/AbstractCollection.template b/src/main/resources/speiger/assets/collections/templates/collections/AbstractCollection.template index 1f3eb1a..08ff9b5 100644 --- a/src/main/resources/speiger/assets/collections/templates/collections/AbstractCollection.template +++ b/src/main/resources/speiger/assets/collections/templates/collections/AbstractCollection.template @@ -39,51 +39,43 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle return false; } +#endif @Override @Deprecated public boolean containsAll(Collection c) { - return c instanceof COLLECTION ? containsAll((COLLECTION)c) : super.containsAll(c); + return c instanceof COLLECTION ? containsAll((COLLECTION KEY_GENERIC_TYPE)c) : super.containsAll(c); } @Override @Deprecated public boolean addAll(Collection c) { - return c instanceof COLLECTION ? addAll((COLLECTION)c) : super.addAll(c); + return c instanceof COLLECTION ? addAll((COLLECTION KEY_GENERIC_TYPE)c) : super.addAll(c); } @Override @Deprecated public boolean removeAll(Collection c) { - return c instanceof COLLECTION ? removeAll((COLLECTION)c) : super.removeAll(c); + return c instanceof COLLECTION ? removeAll((COLLECTION KEY_GENERIC_TYPE)c) : super.removeAll(c); } @Override @Deprecated public boolean retainAll(Collection c) { - return c instanceof COLLECTION ? retainAll((COLLECTION)c) : super.retainAll(c); + return c instanceof COLLECTION ? retainAll((COLLECTION KEY_GENERIC_TYPE)c) : super.retainAll(c); } @Override - public boolean containsAll(COLLECTION c) { + public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { for(KEY_TYPE e : c) if(!contains(e)) return false; return true; } - @Override - public boolean containsAny(COLLECTION c) { - for(KEY_TYPE e : c) - if(contains(e)) - return true; - return false; - } - -#endif @Override @Primitive public boolean containsAny(Collection c) { @@ -93,6 +85,14 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle return false; } + @Override + public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { + for(KEY_TYPE e : c) + if(contains(e)) + return true; + return false; + } + #if !TYPE_OBJECT @Override @Deprecated @@ -100,7 +100,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle @Override public boolean REMOVE_KEY(KEY_TYPE e) { - for(ITERATOR iter = iterator();iter.hasNext();) { + for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(EQUALS(iter.NEXT(), e)) { iter.remove(); return true; @@ -109,10 +109,11 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle return false; } +#endif @Override - public boolean removeAll(COLLECTION c) { + public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { boolean modified = false; - for(ITERATOR iter = iterator();iter.hasNext();) { + for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(c.contains(iter.NEXT())) { iter.remove(); modified = true; @@ -122,9 +123,9 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle } @Override - public boolean retainAll(COLLECTION c) { + public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { boolean modified = false; - for(ITERATOR iter = iterator();iter.hasNext();) { + for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(!c.contains(iter.NEXT())) { iter.remove(); modified = true; @@ -133,6 +134,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle return modified; } +#if !TYPE_OBJECT @Override public KEY_TYPE[] TO_ARRAY() { return TO_ARRAY(new KEY_TYPE[size()]); diff --git a/src/main/resources/speiger/assets/collections/templates/collections/Collection.template b/src/main/resources/speiger/assets/collections/templates/collections/Collection.template index 24e8e59..a176c63 100644 --- a/src/main/resources/speiger/assets/collections/templates/collections/Collection.template +++ b/src/main/resources/speiger/assets/collections/templates/collections/Collection.template @@ -4,8 +4,13 @@ import java.util.Collection; #if PRIMITIVES import java.util.Objects; import java.util.function.JAVA_PREDICATE; +import java.util.function.Predicate; #endif +#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT +import speiger.src.collections.utils.SanityChecks; + +#endif public interface COLLECTION KEY_GENERIC_TYPE extends Collection, ITERABLE KEY_GENERIC_TYPE { #if !TYPE_OBJECT @@ -17,25 +22,37 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection, ITE #if !TYPE_OBJECT public boolean contains(KEY_TYPE o); - public boolean containsAll(COLLECTION c); - - public boolean containsAny(COLLECTION c); - #endif + public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c); + + public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c); + public boolean containsAny(Collection c); #if !TYPE_OBJECT public boolean REMOVE_KEY(KEY_TYPE o); - public boolean removeAll(COLLECTION c); +#endif + public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c); - public boolean retainAll(COLLECTION c); + public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c); +#if !TYPE_OBJECT public KEY_TYPE[] TO_ARRAY(); public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a); #if PRIMITIVES + @Override + public default boolean removeIf(Predicate filter) { + Objects.requireNonNull(filter); +#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT + return remIf(v -> filter.test(KEY_TO_OBJ(SanityChecks.SANITY_CAST(v)))); +#else + return remIf(v -> filter.test(KEY_TO_OBJ(v))); +#endif + } + public default boolean remIf(JAVA_PREDICATE filter) { Objects.requireNonNull(filter); boolean removed = false; 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 36918db..13e1bc8 100644 --- a/src/main/resources/speiger/assets/collections/templates/lists/AbstractList.template +++ b/src/main/resources/speiger/assets/collections/templates/lists/AbstractList.template @@ -18,6 +18,11 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION return true; } + @Override + public void add(int index, CLASS_TYPE element) { + add(index, OBJ_TO_KEY(element)); + } + @Override public boolean addAll(COLLECTION c) { boolean modified = false; @@ -188,13 +193,6 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION size++; } -#if !TYPE_OBJECT - @Override - public void add(int index, CLASS_TYPE element) { - add(index, OBJ_TO_KEY(element)); - } - -#endif @Override public boolean addAll(int index, Collection c) { checkAddRange(index); 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 2e9dc27..3e97e14 100644 --- a/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template +++ b/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template @@ -1,12 +1,20 @@ package speiger.src.collections.PACKAGE.lists; import java.util.Arrays; +#if TYPE_OBJECT +import java.util.Comparator; +#endif import java.util.Collection; import java.util.Iterator; import java.util.Objects; +#if TYPE_OBJECT +import java.util.function.Consumer; +#endif import java.util.function.Predicate; +import java.util.function.UnaryOperator; #if PRIMITIVES import java.util.function.JAVA_PREDICATE; +import java.util.function.UNARY_OPERATOR; #endif import speiger.src.collections.PACKAGE.collections.COLLECTION; @@ -14,6 +22,10 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.STACK; #endif import speiger.src.collections.PACKAGE.collections.ITERATOR; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.COMPARATOR; +import speiger.src.collections.PACKAGE.functions.CONSUMER; +#endif import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ITERATORS; #if TYPE_OBJECT @@ -21,13 +33,13 @@ import speiger.src.collections.utils.Stack; #else import speiger.src.collections.objects.utils.ObjectArrays; #endif -import speiger.src.collections.utils.IArray; +import speiger.src.collections.PACKAGE.utils.IARRAY; import speiger.src.collections.utils.SanityChecks; #if TYPE_OBJECT -public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IArray, Stack +public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY, Stack #else -public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IArray, STACK +public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY, STACK #endif { static final int DEFAULT_ARRAY_SIZE = 10; @@ -94,6 +106,14 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE return list; } +#if TYPE_OBJECT + public static GENERIC_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; + } + +#endif @Override public void add(int index, CLASS_TYPE element) { checkAddRange(index); @@ -228,9 +248,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE @Override @Primitive public boolean containsAll(Collection c) { -#if !TYPE_OBJECT - if(c instanceof COLLECTION) return containsAll((COLLECTION)c); -#endif + if(c instanceof COLLECTION) return containsAll((COLLECTION KEY_GENERIC_TYPE)c); Objects.requireNonNull(c); for(int i = 0,m=size;i c) { -#if !TYPE_OBJECT - if(c instanceof COLLECTION) return containsAny((COLLECTION)c); -#endif + if(c instanceof COLLECTION) return containsAny((COLLECTION KEY_GENERIC_TYPE)c); Objects.requireNonNull(c); for(int i = 0,m=size;i=0;i--) { + if(EQUALS_KEY_TYPE(data[i], o)) return i; + } + return -1; + } + +#if TYPE_OBJECT + @Override + public void sort(Comparator c) { + if(c != null) ARRAYS.stableSort(data, size, c); + else ARRAYS.stableSort((Comparable[])data, size); + } + + @Override + public void unstableSort(Comparator c) { + if(c != null) ARRAYS.unstableSort(data, size, c); + else ARRAYS.unstableSort((Comparable[])data, size); + } + +#endif + @Override + public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { Objects.requireNonNull(c); for(int i = 0,m=size;i=0;i--) { + if(EQUALS(data[i], e)) return i; + } + return -1; + } + + @Override + public void sort(COMPARATOR c) { + if(c != null) ARRAYS.stableSort(data, size, c); + else ARRAYS.stableSort(data, size); + } + + @Override + public void unstableSort(COMPARATOR c) { + if(c != null) ARRAYS.unstableSort(data, size, c); + else ARRAYS.unstableSort(data, size); + } + #endif @Override public KEY_TYPE GET_KEY(int index) { @@ -292,6 +370,19 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE return data[(size() - 1) - index]; } + @Override + public KEY_TYPE[] elements() { + return data; + } + + @Override + @Primitive + public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { + Objects.requireNonNull(action); + for(int i = 0;i o) { + for(int i = 0;i c) { if(c.isEmpty()) return false; -#if !TYPE_OBJECT - if(c instanceof COLLECTION) return removeAll((COLLECTION)c); -#endif + if(c instanceof COLLECTION) return removeAll((COLLECTION KEY_GENERIC_TYPE)c); boolean modified = false; for(int i = 0, j = 0;i c) { if(c.isEmpty()) { boolean modifed = size > 0; - Arrays.fill(data, 0, size, EMPTY_VALUE); - size = 0; + clear(); return modifed; } -#if !TYPE_OBJECT - if(c instanceof COLLECTION) return retainAll((COLLECTION)c); -#endif + if(c instanceof COLLECTION) return retainAll((COLLECTION KEY_GENERIC_TYPE)c); boolean modified = false; for(int i = 0, j = 0;i filter) { @@ -371,9 +474,8 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE return modified; } -#if !TYPE_OBJECT @Override - public boolean removeAll(COLLECTION c) { + public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { if(c.isEmpty()) return false; boolean modified = false; for(int i = 0, j = 0;i 0; - Arrays.fill(data, 0, size, EMPTY_VALUE); - size = 0; + clear(); return modifed; } boolean modified = false; @@ -417,7 +518,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE return modified; } -#endif #endif @Override @Primitive diff --git a/src/main/resources/speiger/assets/collections/templates/lists/List.template b/src/main/resources/speiger/assets/collections/templates/lists/List.template index 0cf8630..652aeb4 100644 --- a/src/main/resources/speiger/assets/collections/templates/lists/List.template +++ b/src/main/resources/speiger/assets/collections/templates/lists/List.template @@ -6,8 +6,16 @@ import java.util.Objects; import java.util.function.UNARY_OPERATOR; import java.util.function.UnaryOperator; #endif +import java.util.Comparator; import speiger.src.collections.PACKAGE.collections.COLLECTION; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.COMPARATOR; +#endif +import speiger.src.collections.PACKAGE.utils.ARRAYS; +#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT +import speiger.src.collections.utils.SanityChecks; +#endif public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List { @@ -41,7 +49,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List LIST_ITERATOR iter = listIterator(); while (iter.hasNext()) #if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT - iter.set((KEY_TYPE)o.APPLY(iter.NEXT())); + iter.set(SanityChecks.SANITY_CAST(o.APPLY(iter.NEXT()))); #else iter.set(o.APPLY(iter.NEXT())); #endif @@ -62,9 +70,63 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List #if TYPE_OBJECT public KEY_TYPE[] extractElements(int from, int to, Class type); + @Override + public default void sort(Comparator c) { + KEY_TYPE[] array = (KEY_TYPE[])TO_ARRAY(); + if(c != null) ARRAYS.stableSort(array, c); + else ARRAYS.stableSort((Comparable[])array); + LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); + for (int i = 0,m=size();i c) { + KEY_TYPE[] array = (KEY_TYPE[])TO_ARRAY(); + if(c != null) ARRAYS.unstableSort(array, c); + else ARRAYS.unstableSort((Comparable[])array); + LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); + for (int i = 0,m=size();i c) { + sort((K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V))); + } + + public default void sort(COMPARATOR c) { + KEY_TYPE[] array = TO_ARRAY(); + if(c != null) ARRAYS.stableSort(array, c); + else ARRAYS.stableSort(array); + LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); + for (int i = 0,m=size();i c) { + unstableSort((K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V))); + } + + public default void unstableSort(COMPARATOR c) { + KEY_TYPE[] array = TO_ARRAY(); + if(c != null) ARRAYS.unstableSort(array, c); + else ARRAYS.unstableSort(array); + LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); + for (int i = 0,m=size();i)EMPTY; +#else + return EMPTY; +#endif + } + + public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE unmodifiableCollection(COLLECTION KEY_GENERIC_TYPE c) { + return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollectionBRACES(c); + } + + public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c) { + return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c); + } + + public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c, Object mutex) { + return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c, mutex); + } + + public static class SynchronizedCollection KEY_GENERIC_TYPE implements COLLECTION KEY_GENERIC_TYPE { + COLLECTION KEY_GENERIC_TYPE c; + protected Object mutex; + + SynchronizedCollection(COLLECTION KEY_GENERIC_TYPE c) { + this.c = c; + mutex = this; + } + + SynchronizedCollection(COLLECTION KEY_GENERIC_TYPE c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public boolean add(KEY_TYPE o) { synchronized(mutex) { return c.add(o); } } + @Override + public boolean addAll(Collection c) { synchronized(mutex) { return this.c.addAll(c); } } + + @Override + public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.addAll(c); } } + +#if !TYPE_OBJECT + @Override + public boolean contains(KEY_TYPE o) { synchronized(mutex) { return c.contains(o); } } + +#else + @Override + public boolean contains(Object o) { synchronized(mutex) { return c.contains(o); } } + +#endif + @Override + public boolean containsAll(Collection c) { synchronized(mutex) { return this.c.containsAll(c); } } + + @Override + public boolean containsAny(Collection c) { synchronized(mutex) { return this.c.containsAny(c); } } + + @Override + public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.containsAll(c); } } + + @Override + public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.containsAny(c); } } + + @Override + public int size() { synchronized(mutex) { return c.size(); } } + + @Override + public boolean isEmpty() { synchronized(mutex) { return c.isEmpty(); } } + + @Override + public ITERATOR KEY_GENERIC_TYPE iterator() { + return c.iterator(); + } + + @Override + @Primitive + public boolean remove(Object o) { synchronized(mutex) { return c.remove(o); } } + @Override + public boolean removeAll(Collection c) { synchronized(mutex) { return this.c.removeAll(c); } } + @Override + public boolean retainAll(Collection c) { synchronized(mutex) { return this.c.retainAll(c); } } +#if !TYPE_OBJECT + @Override + public boolean REMOVE_KEY(KEY_TYPE o) { synchronized(mutex) { return c.REMOVE_KEY(o); } } +#endif + @Override + public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.removeAll(c); } } + @Override + public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.retainAll(c); } } +#if PRIMITIVES + @Override + public boolean remIf(JAVA_PREDICATE filter){ synchronized(mutex) { return c.remIf(filter); } } +#endif + @Override + public void clear() { synchronized(mutex) { c.clear(); } } + + @Override + public Object[] toArray() { synchronized(mutex) { return c.toArray(); } } + +#if !TYPE_OBJECT + @Override + public T[] toArray(T[] a) { synchronized(mutex) { return c.toArray(a); } } + + @Override + public KEY_TYPE[] TO_ARRAY() { synchronized(mutex) { return c.TO_ARRAY(); } } + + @Override + public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { synchronized(mutex) { return c.TO_ARRAY(a); } } +#else + @Override + public E[] toArray(E[] a) { synchronized(mutex) { return c.toArray(a); } } +#endif + } + + public static class UnmodifiableCollection KEY_GENERIC_TYPE implements COLLECTION KEY_GENERIC_TYPE { + COLLECTION KEY_GENERIC_TYPE c; + + UnmodifiableCollection(COLLECTION KEY_GENERIC_TYPE c) { + this.c = c; + } + + @Override + public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); } + @Override + public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } + @Override + public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + +#if !TYPE_OBJECT + @Override + public boolean contains(KEY_TYPE o) { + return c.contains(o); + } + +#else + @Override + public boolean contains(Object o) { + return c.contains(o); + } + +#endif + @Override + public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { + return this.c.containsAll(c); + } + + @Override + public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { + return this.c.containsAny(c); + } + + @Override + public boolean containsAny(Collection c) { + return this.c.containsAny(c); + } + + @Override + public boolean containsAll(Collection c) { + return this.c.containsAll(c); + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public ITERATOR KEY_GENERIC_TYPE iterator() { + return ITERATORS.unmodifiable(c.iterator()); + } + + @Override + @Deprecated + public boolean remove(Object o) { throw new UnsupportedOperationException(); } + @Override + public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } + @Override + public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } + @Override + @Primitive + public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); } +#if !TYPE_OBJECT + @Override + public boolean REMOVE_KEY(KEY_TYPE o) { throw new UnsupportedOperationException(); } +#endif + @Override + public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + @Override + public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } +#if PRIMITIVES + @Override + public boolean remIf(JAVA_PREDICATE filter){ throw new UnsupportedOperationException(); } +#endif + @Override + public void clear() { throw new UnsupportedOperationException(); } + + @Override + public Object[] toArray() { + return c.toArray(); + } + +#if !TYPE_OBJECT + @Override + public T[] toArray(T[] a) { + return c.toArray(a); + } + + @Override + public KEY_TYPE[] TO_ARRAY() { + return c.TO_ARRAY(); + } + + @Override + public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { + return c.TO_ARRAY(a); + } + +#else + @Override + public E[] toArray(E[] a) { + return c.toArray(a); + } + +#endif + } + + public static class EmptyCollection KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE { + @Override + public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); } + + @Override + public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + +#if !TYPE_OBJECT + @Override + public boolean contains(KEY_TYPE o) { + return false; + } + + @Override + public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { + return false; + } + + @Override + public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { + return false; + } + +#else + @Override + public boolean contains(Object o) { + return false; + } + +#endif + @Override + public boolean containsAny(Collection c) { + return false; + } + + @Override + public boolean containsAll(Collection c) { + return false; + } + + @Override + public int hashCode() { + return 0; + } + + @Override + public boolean equals(Object o) { + if(o == this) return true; + if(!(o instanceof Collection)) return false; + return ((Collection)o).isEmpty(); + } + + @Override + @Deprecated + public boolean remove(Object o) { throw new UnsupportedOperationException(); } + @Override + public boolean removeAll(Collection c) { throw new UnsupportedOperationException(); } + @Override + public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } + @Override + @Primitive + public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); } +#if !TYPE_OBJECT + @Override + public boolean REMOVE_KEY(KEY_TYPE o) { throw new UnsupportedOperationException(); } +#endif + @Override + public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + @Override + public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } +#if PRIMITIVES + @Override + public boolean remIf(JAVA_PREDICATE filter){ throw new UnsupportedOperationException(); } +#endif + + @Override + public Object[] toArray() { + return ObjectArrays.EMPTY_ARRAY; + } + +#if !TYPE_OBJECT + @Override + public T[] toArray(T[] a) { + return a; + } + + @Override + public KEY_TYPE[] TO_ARRAY() { + return ARRAYS.EMPTY_ARRAY; + } + + @Override + public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { + return a; + } + +#else + @Override + public E[] toArray(E[] a) { + return a; + } + +#endif + @Override + public ITERATOR KEY_GENERIC_TYPE iterator() { + return ITERATORS.emptyIterator(); + } + + @Override + public void clear() { + } + + @Override + public int size() { + return 0; + } + } +} diff --git a/src/main/resources/speiger/assets/collections/templates/utils/IArray.template b/src/main/resources/speiger/assets/collections/templates/utils/IArray.template new file mode 100644 index 0000000..9b24ddf --- /dev/null +++ b/src/main/resources/speiger/assets/collections/templates/utils/IArray.template @@ -0,0 +1,8 @@ +package speiger.src.collections.PACKAGE.utils; + +import speiger.src.collections.utils.IArray; + +public interface IARRAY KEY_GENERIC_TYPE extends IArray +{ + public KEY_TYPE[] elements(); +} 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 809a3a5..607e82a 100644 --- a/src/main/resources/speiger/assets/collections/templates/utils/Iterators.template +++ b/src/main/resources/speiger/assets/collections/templates/utils/Iterators.template @@ -2,9 +2,28 @@ package speiger.src.collections.PACKAGE.utils; import java.util.Iterator; import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; public class ITERATORS { + public static final EmptyIterator NO_GENERIC_TYPE EMPTY = new EmptyIteratorBRACES(); + + public static GENERIC_BRACES EmptyIterator KEY_GENERIC_TYPE emptyIterator() { +#if TYPE_OBJECT + return (EmptyIterator)EMPTY; +#else + return EMPTY; +#endif + } + + public static GENERIC_BRACES ITERATOR KEY_GENERIC_TYPE unmodifiable(ITERATOR KEY_GENERIC_TYPE iterator) { + return new UnmodifiableIteratorBRACES(iterator); + } + + public static GENERIC_BRACES LIST_ITERATOR KEY_GENERIC_TYPE unmodifiable(LIST_ITERATOR KEY_GENERIC_TYPE iterator) { + return new UnmodifiableListIteratorBRACES(iterator); + } + public static GENERIC_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) { return wrap(a, 0, a.length); } @@ -62,7 +81,116 @@ public class ITERATORS return index; } -#endif +#endif + private static class UnmodifiableListIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE + { + LIST_ITERATOR KEY_GENERIC_TYPE iter; + + UnmodifiableListIterator(LIST_ITERATOR KEY_GENERIC_TYPE iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public boolean hasPrevious() { + return iter.hasPrevious(); + } + + @Override + public int nextIndex() { + return iter.nextIndex(); + } + + @Override + public int previousIndex() { + return iter.previousIndex(); + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + + @Override + public KEY_TYPE PREVIOUS() { + return iter.PREVIOUS(); + } + + @Override + public KEY_TYPE NEXT() { + return iter.NEXT(); + } + + @Override + public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); } + + @Override + public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); } +} + + private static class UnmodifiableIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE + { + ITERATOR KEY_GENERIC_TYPE iterator; + + UnmodifiableIterator(ITERATOR KEY_GENERIC_TYPE iterator) { + this.iterator = iterator; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public KEY_TYPE NEXT() { + return iterator.NEXT(); + } + } + + private static class EmptyIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE + { + @Override + public boolean hasNext() { + return false; + } + + @Override + public KEY_TYPE NEXT() { + return EMPTY_VALUE; + } + + @Override + public boolean hasPrevious() { + return false; + } + + @Override + public KEY_TYPE PREVIOUS() { + return EMPTY_VALUE; + } + + @Override + public int nextIndex() { + return 0; + } + + @Override + public int previousIndex() { + return 0; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + + @Override + public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); } + + @Override + public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); } + } + private static class ArrayIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE { KEY_TYPE[] a; diff --git a/src/main/resources/speiger/assets/collections/templates/utils/Lists.template b/src/main/resources/speiger/assets/collections/templates/utils/Lists.template new file mode 100644 index 0000000..f113a8f --- /dev/null +++ b/src/main/resources/speiger/assets/collections/templates/utils/Lists.template @@ -0,0 +1,367 @@ +package speiger.src.collections.PACKAGE.utils; + +import java.util.Collection; +import java.util.RandomAccess; +#if TYPE_OBJECT +import java.util.function.Consumer; +#endif + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.CONSUMER; +#endif +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; + +public class LISTS +{ + public static final EmptyList NO_GENERIC_TYPE EMPTY = new EmptyListBRACES(); + + public static GENERIC_BRACES EmptyList KEY_GENERIC_TYPE emptyList() { +#if TYPE_OBJECT + return (EmptyList)EMPTY; +#else + return EMPTY; +#endif + } + + public static GENERIC_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); + } + + public static GENERIC_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))); + } + + public static GENERIC_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))); + } + + public static class SynchronizedArrayList KEY_GENERIC_TYPE extends SynchronizedList KEY_GENERIC_TYPE implements IARRAY KEY_GENERIC_TYPE + { + IARRAY KEY_GENERIC_TYPE l; + + SynchronizedArrayList(LIST KEY_GENERIC_TYPE l) { + super(l); + this.l = (IARRAY KEY_GENERIC_TYPE)l; + } + + SynchronizedArrayList(LIST KEY_GENERIC_TYPE l, Object mutex) { + super(l, mutex); + this.l = (IARRAY KEY_GENERIC_TYPE)l; + } + + public void ensureCapacity(int size) { synchronized(mutex) { l.ensureCapacity(size); } } + + public void trim(int size) { synchronized(mutex) { l.trim(size); } } + + public KEY_TYPE[] elements() { synchronized(mutex) { return l.elements(); } } + } + + public static class SynchronizedRandomAccessList KEY_GENERIC_TYPE extends SynchronizedList KEY_GENERIC_TYPE implements RandomAccess + { + SynchronizedRandomAccessList(LIST KEY_GENERIC_TYPE l) { + super(l); + } + + SynchronizedRandomAccessList(LIST KEY_GENERIC_TYPE l, Object mutex) { + super(l, mutex); + } + } + + public static class SynchronizedList KEY_GENERIC_TYPE extends COLLECTIONS.SynchronizedCollection KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE + { + LIST KEY_GENERIC_TYPE l; + + SynchronizedList(LIST KEY_GENERIC_TYPE l) { + super(l); + this.l = l; + } + + SynchronizedList(LIST KEY_GENERIC_TYPE l, Object mutex) { + super(l, mutex); + this.l = l; + } + + @Override + public boolean addAll(int index, Collection c) { synchronized(mutex) { return l.addAll(index, c); } } + + @Override + public void add(int index, CLASS_TYPE element) { synchronized(mutex) { l.add(index, element); } } + +#if !TYPE_OBJECT + @Override + public void add(int index, KEY_TYPE e) { synchronized(mutex) { l.add(index, e); } } + +#endif + @Override + public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return l.addAll(index, c); } } + + @Override + public boolean addAll(LIST KEY_GENERIC_TYPE c) { synchronized(mutex) { return l.addAll(c); } } + + @Override + public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) { synchronized(mutex) { return l.addAll(index, c); } } + + @Override + public KEY_TYPE GET_KEY(int index) { synchronized(mutex) { return l.GET_KEY(index); } } + +#if !TYPE_OBJECT + @Override + public void forEach(CONSUMER action) { synchronized(mutex) { l.forEach(action); } } + +#else + @Override + public void forEach(Consumer action) { synchronized(mutex) { l.forEach(action); } } + +#endif + @Override + public KEY_TYPE set(int index, KEY_TYPE e) { synchronized(mutex) { return l.set(index, e); } } + + @Override + public KEY_TYPE REMOVE(int index) { synchronized(mutex) { return l.REMOVE(index); } } + + @Override + @Primitive + public int indexOf(Object e) { synchronized(mutex) { return l.indexOf(e); } } + + @Override + @Primitive + public int lastIndexOf(Object e) { synchronized(mutex) { return l.lastIndexOf(e); } } + +#if !TYPE_OBJECT + @Override + public int indexOf(KEY_TYPE e) { synchronized(mutex) { return l.indexOf(e); } } + + @Override + public int lastIndexOf(KEY_TYPE e) { synchronized(mutex) { return l.lastIndexOf(e); } } + +#endif + @Override + public void addElements(int from, KEY_TYPE[] a, int offset, int length) { synchronized(mutex) { addElements(from, a, offset, length); } } + + @Override + public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) { synchronized(mutex) { return l.getElements(from, a, offset, length); } } + + @Override + public void removeElements(int from, int to) { synchronized(mutex) { l.removeElements(from, to); } } + +#if !TYPE_OBJECT + @Override + public KEY_TYPE[] extractElements(int from, int to) { synchronized(mutex) { return l.extractElements(from, to); } } + +#else + @Override + public KEY_TYPE[] extractElements(int from, int to, Class clz) { synchronized(mutex) { return l.extractElements(from, to, clz); } } + +#endif + @Override + public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() { + return l.listIterator(); + } + + @Override + public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) { + return l.listIterator(index); + } + + @Override + public LIST KEY_GENERIC_TYPE subList(int from, int to) { + return synchronizedList(l.subList(from, to)); + } + + @Override + public void size(int size) { synchronized(mutex) { l.size(size); } } + } + + public static class UnmodifiableRandomList KEY_GENERIC_TYPE extends UnmodifiableList KEY_GENERIC_TYPE implements RandomAccess + { + UnmodifiableRandomList(LIST KEY_GENERIC_TYPE l) { + super(l); + } + } + + public static class UnmodifiableList KEY_GENERIC_TYPE extends COLLECTIONS.UnmodifiableCollection KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE + { + LIST KEY_GENERIC_TYPE l; + + UnmodifiableList(LIST KEY_GENERIC_TYPE l) { + super(l); + this.l = l; + } + + @Override + public boolean addAll(int index, Collection c) { throw new UnsupportedOperationException(); } + + @Override + public void add(int index, CLASS_TYPE element) { throw new UnsupportedOperationException(); } + +#if !TYPE_OBJECT + @Override + public void add(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); } + +#endif + @Override + public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + + @Override + public boolean addAll(LIST KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + + @Override + public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + + @Override + public KEY_TYPE GET_KEY(int index) { return l.GET_KEY(index); } + +#if !TYPE_OBJECT + @Override + public void forEach(CONSUMER action) { l.forEach(action); } + +#else + @Override + public void forEach(Consumer action) { l.forEach(action); } + +#endif + @Override + public KEY_TYPE set(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); } + + @Override + public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); } + + @Override + @Primitive + public int indexOf(Object e) { return l.indexOf(e); } + + @Override + @Primitive + public int lastIndexOf(Object e) { return l.lastIndexOf(e); } + +#if !TYPE_OBJECT + @Override + public int indexOf(KEY_TYPE e) { return l.indexOf(e); } + + @Override + public int lastIndexOf(KEY_TYPE e) { return l.lastIndexOf(e); } + +#endif + @Override + public void addElements(int from, KEY_TYPE[] a, int offset, int length) { throw new UnsupportedOperationException(); } + + @Override + public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) { + return l.getElements(from, a, offset, length); + } + + @Override + public void removeElements(int from, int to) { throw new UnsupportedOperationException(); } + +#if !TYPE_OBJECT + @Override + public KEY_TYPE[] extractElements(int from, int to) { throw new UnsupportedOperationException(); } + +#else + @Override + public KEY_TYPE[] extractElements(int from, int to, Class clz) { throw new UnsupportedOperationException(); } + +#endif + @Override + public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() { + return ITERATORS.unmodifiable(l.listIterator()); + } + + @Override + public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) { + return ITERATORS.unmodifiable(l.listIterator(index)); + } + + @Override + public LIST KEY_GENERIC_TYPE subList(int from, int to) { + return unmodifiableList(l.subList(from, to)); + } + + @Override + public void size(int size) { throw new UnsupportedOperationException(); } + } + + public static class EmptyList KEY_GENERIC_TYPE extends COLLECTIONS.EmptyCollection KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE + { + @Override + public boolean addAll(int index, Collection c) { throw new UnsupportedOperationException(); } + + @Override + public void add(int index, CLASS_TYPE element) { throw new UnsupportedOperationException(); } + +#if !TYPE_OBJECT + @Override + public void add(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); } + +#endif + @Override + public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + + @Override + public boolean addAll(LIST KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + + @Override + public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } + + @Override + public KEY_TYPE GET_KEY(int index) { throw new IndexOutOfBoundsException(); } + + @Override + public KEY_TYPE set(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); } + + @Override + public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); } + + @Override + public int indexOf(Object e) { return -1; } + + @Override + public int lastIndexOf(Object e) { return -1; } + +#if !TYPE_OBJECT + @Override + public int indexOf(KEY_TYPE e) { return -1; } + + @Override + public int lastIndexOf(KEY_TYPE e) { return -1; } + +#endif + @Override + public void addElements(int from, KEY_TYPE[] a, int offset, int length){ throw new UnsupportedOperationException(); } + + @Override + public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) { throw new IndexOutOfBoundsException(); } + + @Override + public void removeElements(int from, int to) { throw new UnsupportedOperationException(); } + +#if !TYPE_OBJECT + @Override + public KEY_TYPE[] extractElements(int from, int to) { throw new UnsupportedOperationException(); } + +#else + @Override + public KEY_TYPE[] extractElements(int from, int to, Class clz) { throw new UnsupportedOperationException(); } + +#endif + @Override + public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() { + return ITERATORS.emptyIterator(); + } + + @Override + public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) { + if(index != 0) + throw new IndexOutOfBoundsException(); + return ITERATORS.emptyIterator(); + } + + @Override + public LIST KEY_GENERIC_TYPE subList(int from, int to) { throw new UnsupportedOperationException(); } + + @Override + public void size(int size) { throw new UnsupportedOperationException(); } + } +}