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.
This commit is contained in:
Speiger 2020-12-01 02:43:13 +01:00
parent 0c53fbab6b
commit 8d079ae0ab
12 changed files with 1174 additions and 64 deletions

View File

@ -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<T>>" : "");
addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "<? super "+type.getKeyType()+">" : "");
addSimpleMapper(" GENERIC_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : "");
addSimpleMapper(" COMPAREABLE_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable<T>>" : "");
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);

View File

@ -16,9 +16,11 @@ import speiger.src.builder.processor.TemplateProcessor;
public class TestBuilder extends TemplateProcessor
{
Map<String, EnumSet<ClassType>> blocked = new HashMap<String, EnumSet<ClassType>>();
Map<String, String> nameRemapper = new HashMap<String, String>();
public static final ClassType[] TYPE = ClassType.values();
List<GlobalVariables> varibles = new ArrayList<GlobalVariables>();
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)));
}
}
}

View File

@ -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<? extends CLASS_TYPE> 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()]);

View File

@ -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<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE
{
#if !TYPE_OBJECT
@ -17,25 +22,37 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, 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<? super CLASS_TYPE> 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;

View File

@ -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<? extends CLASS_TYPE> c) {
checkAddRange(index);

View File

@ -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<KEY_TYPE>
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY<KEY_TYPE>, Stack<KEY_TYPE>
#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<KEY_TYPE> 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<m;i++) {
#if !TYPE_OBJECT
@ -246,9 +264,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
@Primitive
public boolean containsAny(Collection<?> 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<m;i++) {
#if !TYPE_OBJECT
@ -260,9 +276,42 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return false;
}
#if !TYPE_OBJECT
@Override
public boolean containsAll(COLLECTION c) {
@Primitive
public int indexOf(Object o) {
if(o == null) return -1;
for(int i = 0;i<size;i++) {
if(EQUALS_KEY_TYPE(data[i], o)) return i;
}
return -1;
}
@Override
@Primitive
public int lastIndexOf(Object o) {
if(o == null) return -1;
for(int i = size - 1;i>=0;i--) {
if(EQUALS_KEY_TYPE(data[i], o)) return i;
}
return -1;
}
#if TYPE_OBJECT
@Override
public void sort(Comparator<? super CLASS_TYPE> c) {
if(c != null) ARRAYS.stableSort(data, size, c);
else ARRAYS.stableSort((Comparable[])data, size);
}
@Override
public void unstableSort(Comparator<? super CLASS_TYPE> 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<m;i++) {
if(!c.contains(data[i])) return false;
@ -271,7 +320,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
}
@Override
public boolean containsAny(COLLECTION c) {
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
Objects.requireNonNull(c);
for(int i = 0,m=size;i<m;i++) {
if(c.contains(data[i])) return true;
@ -279,6 +328,35 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return false;
}
#if !TYPE_OBJECT
@Override
public int indexOf(KEY_TYPE e) {
for(int i = 0;i<size;i++) {
if(EQUALS(data[i], e)) return i;
}
return -1;
}
@Override
public int lastIndexOf(KEY_TYPE e) {
for(int i = size - 1;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<size;i++)
action.accept(data[i]);
}
@Override
public KEY_TYPE set(int index, KEY_TYPE e) {
checkRange(index);
@ -300,6 +391,24 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return old;
}
@Override
public void replaceAll(UnaryOperator<CLASS_TYPE> o) {
for(int i = 0;i<size;i++)
data[i] = OBJ_TO_KEY(o.apply(KEY_TO_OBJ(data[i])));
}
#if PRIMITIVES
@Override
public void REPLACE(UNARY_OPERATOR o) {
for(int i = 0;i<size;i++)
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
data[i] = SanityChecks.SANITY_CAST(o.APPLY(data[i]));
#else
data[i] = o.APPLY(data[i]);
#endif
}
#endif
@Override
public KEY_TYPE REMOVE(int index) {
checkRange(index);
@ -321,9 +430,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
@Primitive
public boolean removeAll(Collection<?> 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<size;i++) {
if(!c.contains(KEY_TO_OBJ(data[i]))) {
@ -339,13 +446,10 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
public boolean retainAll(Collection<?> 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<size;i++) {
if(c.contains(KEY_TO_OBJ(data[i]))) {
@ -356,7 +460,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return modified;
}
@Override
@Primitive
public boolean removeIf(Predicate<? super CLASS_TYPE> 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<size;i++) {
@ -386,11 +488,10 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
}
@Override
public boolean retainAll(COLLECTION c) {
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
if(c.isEmpty()) {
boolean modifed = size > 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

View File

@ -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<CLASS_TYPE>
{
@ -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<KEY_TYPE> type);
@Override
public default void sort(Comparator<? super CLASS_TYPE> 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<m && iter.hasNext();i++) {
iter.NEXT();
iter.set(array[i]);
}
}
public default void unstableSort(Comparator<? super CLASS_TYPE> 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<m && iter.hasNext();i++) {
iter.NEXT();
iter.set(array[i]);
}
}
#else
public KEY_TYPE[] extractElements(int from, int to);
@Override
default void sort(Comparator<? super CLASS_TYPE> 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<m && iter.hasNext();i++) {
iter.NEXT();
iter.set(array[i]);
}
}
public default void unstableSort(Comparator<? super CLASS_TYPE> 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<m && iter.hasNext();i++) {
iter.NEXT();
iter.set(array[i]);
}
}
#endif
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator();

View File

@ -60,6 +60,55 @@ public class ARRAYS
}
#endif
public static GENERIC_BRACES void stableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
stableSort(array, 0, array.length, comp);
}
public static GENERIC_BRACES void stableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
stableSort(array, 0, length, comp);
}
public static GENERIC_BRACES void stableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
mergeSort(array, null, from, to, comp);
}
public static COMPAREABLE_BRACES void stableSort(KEY_TYPE[] array) {
stableSort(array, 0, array.length);
}
public static COMPAREABLE_BRACES void stableSort(KEY_TYPE[] array, int length) {
stableSort(array, 0, length);
}
public static COMPAREABLE_BRACES void stableSort(KEY_TYPE[] array, int from, int to) {
mergeSort(array, null, from, to);
}
public static GENERIC_BRACES void unstableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
unstableSort(array, 0, array.length, comp);
}
public static GENERIC_BRACES void unstableSort(KEY_TYPE[] array, int length, COMPARATOR KEY_GENERIC_TYPE comp) {
unstableSort(array, 0, length, comp);
}
public static GENERIC_BRACES void unstableSort(KEY_TYPE[] array, int from, int to, COMPARATOR KEY_GENERIC_TYPE comp) {
quickSort(array, from, to, comp);
}
public static COMPAREABLE_BRACES void unstableSort(KEY_TYPE[] array) {
unstableSort(array, 0, array.length);
}
public static COMPAREABLE_BRACES void unstableSort(KEY_TYPE[] array, int length) {
unstableSort(array, 0, length);
}
public static COMPAREABLE_BRACES void unstableSort(KEY_TYPE[] array, int from, int to) {
quickSort(array, from, to);
}
public static GENERIC_BRACES void insertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
insertionSort(array, 0, array.length, comp);
}

View File

@ -0,0 +1,369 @@
package speiger.src.collections.PACKAGE.utils;
import java.util.Collection;
import java.util.function.Predicate;
#if PRIMITIVES
import java.util.function.JAVA_PREDICATE;
#endif
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.objects.utils.ObjectArrays;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.utils.ARRAYS;
#endif
public class COLLECTIONS
{
public static final COLLECTION NO_GENERIC_TYPE EMPTY = new EmptyCollectionBRACES();
public static GENERIC_BRACES COLLECTION KEY_GENERIC_TYPE emptyCollection() {
#if TYPE_OBJECT
return (COLLECTION<KEY_TYPE>)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<? extends CLASS_TYPE> 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> 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> 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<? extends CLASS_TYPE> 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<? super CLASS_TYPE> 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> 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> 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<? super CLASS_TYPE> 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> 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> 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;
}
}
}

View File

@ -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();
}

View File

@ -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<KEY_TYPE>)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);
}
@ -63,6 +82,115 @@ public class ITERATORS
}
#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;

View File

@ -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<KEY_TYPE>)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<? extends CLASS_TYPE> 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<? super KEY_TYPE> 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<T> 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<? extends CLASS_TYPE> 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<? super KEY_TYPE> 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<T> 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<? extends CLASS_TYPE> 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<T> 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(); }
}
}