Added missing doc and made it a bit more consistend

This commit is contained in:
Speiger 2020-12-07 08:55:22 +01:00
parent 6f4b8dfed0
commit fc7bca3500
13 changed files with 537 additions and 114 deletions

View File

@ -16,8 +16,8 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
#if !TYPE_OBJECT #if !TYPE_OBJECT
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -35,8 +35,8 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
#if !TYPE_OBJECT #if !TYPE_OBJECT
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -55,8 +55,8 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
#endif #endif
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -66,8 +66,8 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -77,8 +77,8 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Primitive @Primitive
@ -88,8 +88,8 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Primitive @Primitive
@ -147,8 +147,8 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
#if !TYPE_OBJECT #if !TYPE_OBJECT
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated

View File

@ -29,8 +29,8 @@ public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
#if !TYPE_OBJECT #if !TYPE_OBJECT
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated

View File

@ -57,7 +57,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
/** /**
* Returns true if any element of the Collection is found in the provided collection. * Returns true if any element of the Collection is found in the provided collection.
* A Small Optimization method to find out of any element is present when comparing collections and not all of them. * A Small Optimization function to find out of any element is present when comparing collections and not all of them.
* @return true if any element was found. * @return true if any element was found.
*/ */
@Primitive @Primitive
@ -104,8 +104,8 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
#if PRIMITIVES #if PRIMITIVES
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -140,24 +140,24 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
#endif #endif
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
public default boolean add(CLASS_TYPE o) { return add(OBJ_TO_KEY(o)); } public default boolean add(CLASS_TYPE o) { return add(OBJ_TO_KEY(o)); }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
public default boolean contains(Object o) { return o != null && contains(CLASS_TO_KEY(o)); } public default boolean contains(Object o) { return o != null && contains(CLASS_TO_KEY(o)); }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated

View File

@ -22,7 +22,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
#if !TYPE_OBJECT #if !TYPE_OBJECT
/** /**
* A Type Specific foreach method that reduces (un)boxing * A Type Specific foreach function that reduces (un)boxing
* *
* @implSpec * @implSpec
* <p>The default implementation behaves as if: * <p>The default implementation behaves as if:
@ -40,8 +40,8 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Deprecated @Deprecated
@Override @Override

View File

@ -25,8 +25,8 @@ public interface ITERATOR KEY_GENERIC_TYPE extends Iterator<CLASS_TYPE>
public KEY_TYPE NEXT(); public KEY_TYPE NEXT();
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -54,8 +54,8 @@ public interface ITERATOR KEY_GENERIC_TYPE extends Iterator<CLASS_TYPE>
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Deprecated @Deprecated
@Override @Override

View File

@ -44,24 +44,24 @@ public interface STACK extends Stack<CLASS_TYPE>
#if !OBJECT_TYPE #if !OBJECT_TYPE
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
public default void push(CLASS_TYPE e) { PUSH(OBJ_TO_KEY(e)); } public default void push(CLASS_TYPE e) { PUSH(OBJ_TO_KEY(e)); }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
public default CLASS_TYPE pop() { return KEY_TO_OBJ(POP()); } public default CLASS_TYPE pop() { return KEY_TO_OBJ(POP()); }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -70,8 +70,8 @@ public interface STACK extends Stack<CLASS_TYPE>
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated

View File

@ -1,6 +1,7 @@
package speiger.src.collections.PACKAGE.functions; package speiger.src.collections.PACKAGE.functions;
import java.util.Comparator; import java.util.Comparator;
import java.util.Objects;
/** /**
* Type-Specific Class for Comparator to reduce (un)boxing * Type-Specific Class for Comparator to reduce (un)boxing
@ -14,12 +15,23 @@ public interface COMPARATOR extends Comparator<CLASS_TYPE>
int compare(KEY_TYPE o1, KEY_TYPE o2); int compare(KEY_TYPE o1, KEY_TYPE o2);
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
default int compare(CLASS_TYPE o1, CLASS_TYPE o2) { default int compare(CLASS_TYPE o1, CLASS_TYPE o2) {
return compare(OBJ_TO_KEY(o1), OBJ_TO_KEY(o2)); return compare(OBJ_TO_KEY(o1), OBJ_TO_KEY(o2));
} }
/**
* A Wrapper function to convert a Non-Type-Specific Comparator to a Type-Specific-Comparator
* @param c comparator to convert
* @return the wrapper of the comparator
* @throws NullPointerException if the comparator is null
*/
public static COMPARATOR of(Comparator<CLASS_TYPE> c) {
Objects.requireNonNull(c);
return (K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V))
}
} }

View File

@ -21,7 +21,7 @@ public interface CONSUMER extends Consumer<CLASS_TYPE>
#endif #endif
{ {
/** /**
* Type-Specific method to reduce (un)boxing. * Type-Specific function to reduce (un)boxing.
* Performs this operation on the given argument. * Performs this operation on the given argument.
* *
* @param t the input argument * @param t the input argument
@ -30,8 +30,8 @@ public interface CONSUMER extends Consumer<CLASS_TYPE>
#if !JDK_CONSUMER #if !JDK_CONSUMER
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -44,16 +44,16 @@ public interface CONSUMER extends Consumer<CLASS_TYPE>
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
default void accept(CLASS_TYPE t) { accept(OBJ_TO_KEY(t)); } default void accept(CLASS_TYPE t) { accept(OBJ_TO_KEY(t)); }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -64,8 +64,8 @@ public interface CONSUMER extends Consumer<CLASS_TYPE>
#if PRIMITIVES #if PRIMITIVES
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated

View File

@ -9,29 +9,50 @@ import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.PACKAGE.collections.ITERATOR;
/**
* Abstract implementation of the {@link LIST} interface.
*/
public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
{ {
#if !TYPE_OBJECT #if !TYPE_OBJECT
/**
* A Type-Specific implementation of add function that delegates to {@link #add(int, KEY_TYPE)}
*/
@Override @Override
public boolean add(KEY_TYPE e) { public boolean add(KEY_TYPE e) {
add(size(), e); add(size(), e);
return true; return true;
} }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override @Override
@Deprecated
public void add(int index, CLASS_TYPE element) { public void add(int index, CLASS_TYPE element) {
add(index, OBJ_TO_KEY(element)); add(index, OBJ_TO_KEY(element));
} }
#endif
/**
* A Type-Specific implementation that iterates over the elements and adds them.
* @param c the elements that wants to be added
* @return true if the list was modified
*/
@Override @Override
public boolean addAll(COLLECTION c) { public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) {
boolean modified = false; boolean modified = false;
for(KEY_TYPE e : c) for(KEY_TYPE e : c)
modified |= add(e); modified |= add(e);
return modified; return modified;
} }
#endif /**
* A Type-Specific implementation that iterates over the elements and adds them.
* @param c the elements that wants to be added
* @return true if the list was modified
*/
@Override @Override
public boolean addAll(LIST KEY_GENERIC_TYPE c) { public boolean addAll(LIST KEY_GENERIC_TYPE c) {
boolean modified = false; boolean modified = false;
@ -40,7 +61,14 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
return modified; return modified;
} }
/**
* The IndexOf implementation iterates over all elements and compares them to the search value.
* @param e the value that the index is searched for.
* @return index of the value that was searched for. -1 if not found
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
*/
@Override @Override
@Primitive
public int indexOf(Object o) { public int indexOf(Object o) {
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator();
#if TYPE_OBJECT #if TYPE_OBJECT
@ -61,7 +89,14 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
return -1; return -1;
} }
/**
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
* @param e the value that the index is searched for.
* @return the last index of the value that was searched for. -1 if not found
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
*/
@Override @Override
@Primitive
public int lastIndexOf(Object o) { public int lastIndexOf(Object o) {
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(size()); LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(size());
#if TYPE_OBJECT #if TYPE_OBJECT
@ -83,6 +118,11 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
} }
#if !TYPE_OBJECT #if !TYPE_OBJECT
/**
* The indexOf implementation iterates over all elements and compares them to the search value.
* @param e the value that the index is searched for.
* @return index of the value that was searched for. -1 if not found
*/
@Override @Override
public int indexOf(KEY_TYPE e) { public int indexOf(KEY_TYPE e) {
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator();
@ -93,6 +133,11 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
return -1; return -1;
} }
/**
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
* @param e the value that the index is searched for.
* @return the last index of the value that was searched for. -1 if not found
*/
@Override @Override
public int lastIndexOf(KEY_TYPE e) { public int lastIndexOf(KEY_TYPE e) {
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(size()); LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(size());
@ -104,6 +149,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
} }
#endif #endif
/**
* Compares if the list are the same.
*/
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == this) if (o == this)
@ -133,6 +181,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
return !(e1.hasNext() || e2.hasNext()); return !(e1.hasNext() || e2.hasNext());
} }
/**
* Generates the hashcode based on the values stored in the list.
*/
@Override @Override
public int hashCode() { public int hashCode() {
int hashCode = 1; int hashCode = 1;

View File

@ -37,16 +37,33 @@ import speiger.src.collections.PACKAGE.utils.IARRAY;
import speiger.src.collections.utils.SanityChecks; import speiger.src.collections.utils.SanityChecks;
#if TYPE_OBJECT #if TYPE_OBJECT
/**
* A Type-Specific Array-based implementation of list that is written to reduce (un)boxing
*
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IARRAY}, {@link Stack}
* and with optimized functions that use type-specific implementations for primitives and optimized logic for bulkactions.
*/
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY<KEY_TYPE>, Stack<KEY_TYPE> public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE implements IARRAY<KEY_TYPE>, Stack<KEY_TYPE>
#else #else
/**
* A Type-Specific Array-based implementation of list that is written to reduce (un)boxing
*
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IARRAY}, {@link STACK}
* and with optimized functions that use type-specific implementations for primitives and optimized logic for bulkactions.
*/
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 #endif
{ {
static final int DEFAULT_ARRAY_SIZE = 10; static final int DEFAULT_ARRAY_SIZE = 10;
/** The backing array */
protected transient KEY_TYPE[] data; protected transient KEY_TYPE[] data;
/** The current size of the elements stored in the backing array */
protected int size = 0; protected int size = 0;
/**
* Creates a new ArrayList with a Empty array.
*/
public ARRAY_LIST() { public ARRAY_LIST() {
#if TYPE_OBJECT #if TYPE_OBJECT
data = (KEY_TYPE[])ARRAYS.EMPTY_ARRAY; data = (KEY_TYPE[])ARRAYS.EMPTY_ARRAY;
@ -55,6 +72,9 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
#endif #endif
} }
/**
* Creates a new ArrayList with the specific requested size
*/
public ARRAY_LIST(int size) { public ARRAY_LIST(int size) {
#if TYPE_OBJECT #if TYPE_OBJECT
data = (KEY_TYPE[])new Object[size]; data = (KEY_TYPE[])new Object[size];
@ -63,30 +83,48 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
#endif #endif
} }
/**
* Creates a new ArrayList a copy with the contents of the Collection.
*/
public ARRAY_LIST(Collection<? extends CLASS_TYPE> c) { public ARRAY_LIST(Collection<? extends CLASS_TYPE> c) {
this(c.size()); this(c.size());
size = ITERATORS.unwrap(data, c.iterator()); size = ITERATORS.unwrap(data, c.iterator());
} }
/**
* Creates a new ArrayList a copy with the contents of the Collection.
*/
public ARRAY_LIST(COLLECTION KEY_GENERIC_TYPE c) { public ARRAY_LIST(COLLECTION KEY_GENERIC_TYPE c) {
this(c.size()); this(c.size());
size = ITERATORS.unwrap(data, c.iterator()); size = ITERATORS.unwrap(data, c.iterator());
} }
/**
* Creates a new ArrayList a copy with the contents of the List.
*/
public ARRAY_LIST(LIST KEY_GENERIC_TYPE l) { public ARRAY_LIST(LIST KEY_GENERIC_TYPE l) {
this(l.size()); this(l.size());
size = l.size(); size = l.size();
l.getElements(0, data, 0, size); l.getElements(0, data, 0, size);
} }
/**
* Creates a new ArrayList with a Copy of the array
*/
public ARRAY_LIST(KEY_TYPE[] a) { public ARRAY_LIST(KEY_TYPE[] a) {
this(a, 0, a.length); this(a, 0, a.length);
} }
/**
* Creates a new ArrayList with a Copy of the array with a custom length
*/
public ARRAY_LIST(KEY_TYPE[] a, int length) { public ARRAY_LIST(KEY_TYPE[] a, int length) {
this(a, 0, length); this(a, 0, length);
} }
/**
* Creates a new ArrayList with a Copy of the array with in the custom range.
*/
public ARRAY_LIST(KEY_TYPE[] a, int offset, int length) { public ARRAY_LIST(KEY_TYPE[] a, int offset, int length) {
this(length); this(length);
SanityChecks.checkArrayCapacity(a.length, offset, length); SanityChecks.checkArrayCapacity(a.length, offset, length);
@ -94,10 +132,16 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
size = length; size = length;
} }
/**
* Creates a wrapped arraylist that uses the array as backing array
*/
public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) { public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
return wrap(a, a.length); return wrap(a, a.length);
} }
/**
* Creates a wrapped arraylist that uses the array as backing array and a custom fillsize
*/
public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int length) { public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int length) {
SanityChecks.checkArrayCapacity(a.length, 0, length); SanityChecks.checkArrayCapacity(a.length, 0, length);
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
@ -107,6 +151,9 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#if TYPE_OBJECT #if TYPE_OBJECT
/**
* Creates a new ArrayList with a EmptyObject array of the Type requested
*/
public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) { public static GENERIC_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) {
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
list.data = (KEY_TYPE[])ObjectArrays.newArray(c.getClass().getComponentType(), 0); list.data = (KEY_TYPE[])ObjectArrays.newArray(c.getClass().getComponentType(), 0);
@ -114,15 +161,12 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#endif #endif
@Override /**
public void add(int index, CLASS_TYPE element) { * Appends the specified element to the end of this list.
checkAddRange(index); *
grow(size + 1); * @param e element to be appended to this list
if(index != size) System.arraycopy(data, index, data, index+1, size - index); * @return <tt>true</tt> (as specified by {@link Collection#add})
data[index] = OBJ_TO_KEY(element); */
size++;
}
@Override @Override
public boolean add(KEY_TYPE e) { public boolean add(KEY_TYPE e) {
grow(size + 1); grow(size + 1);
@ -130,12 +174,21 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return true; return true;
} }
/**
* Appends the specified element to the end of this Stack.
* @param e element to be appended to this Stack
*/
@Override @Override
public void PUSH(KEY_TYPE e) { public void PUSH(KEY_TYPE e) {
add(e); add(e);
} }
#if !TYPE_OBJECT /**
* Appends the specified element to the index of the list
* @param index the index where to append the element to
* @param e the element to append to the list
* @throws IndexOutOfBoundsException if index is outside of the lists range
*/
@Override @Override
public void add(int index, KEY_TYPE e) { public void add(int index, KEY_TYPE e) {
checkAddRange(index); checkAddRange(index);
@ -145,7 +198,14 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
size++; size++;
} }
#endif /**
* Appends the specified elements to the index of the list.
* This function may delegate to more appropiate function if nessesary
* @param index the index where to append the elements to
* @param e the elements to append to the list
* @throws IndexOutOfBoundsException if index is outside of the lists range
* @deprecated if type is primitive
*/
@Override @Override
@Primitive @Primitive
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) { public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
@ -160,6 +220,14 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return true; return true;
} }
/**
* Appends the specified elements to the index of the list.
* This function may delegate to more appropiate function if nessesary
* @param index the index where to append the elements to
* @param e the elements to append to the list
* @throws IndexOutOfBoundsException if index is outside of the lists range
* @deprecated if type is primitive
*/
@Override @Override
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) { public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
if(c instanceof LIST) return addAll(index, (LIST KEY_GENERIC_TYPE)c); if(c instanceof LIST) return addAll(index, (LIST KEY_GENERIC_TYPE)c);
@ -173,6 +241,13 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return true; return true;
} }
/**
* Appends the specified elements to the index of the list.
* @param index the index where to append the elements to
* @param e the elements to append to the list
* @throws IndexOutOfBoundsException if index is outside of the lists range
* @deprecated if type is primitive
*/
@Override @Override
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) { public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
int add = c.size(); int add = c.size();
@ -185,6 +260,15 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return true; return true;
} }
/**
* Appends the specified array elements to the index of the list.
* @param from the index where to append the elements to
* @param a the elements to append to the list
* @param offset where to start ino the array
* @param length the amount of elements to insert
* @throws IndexOutOfBoundsException if index is outside of the lists range
* @deprecated if type is primitive
*/
@Override @Override
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
if(length <= 0) return; if(length <= 0) return;
@ -195,6 +279,17 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
System.arraycopy(a, offset, data, from, length); System.arraycopy(a, offset, data, from, length);
} }
/**
* A function to fast fetch elements from the list
* @param from index where the list should be fetching elements from
* @param a the array where the values should be inserted to
* @param offset the startIndex of where the array should be written to
* @param length the number of elements the values should be fetched from
* @returns the inputArray
* @throws NullPointerException if the array is null
* @throws IndexOutOfBoundsException if from is outside of the lists range
* @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length
*/
@Override @Override
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) { public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
SanityChecks.checkArrayCapacity(size, offset, length); SanityChecks.checkArrayCapacity(size, offset, length);
@ -202,6 +297,11 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return a; return a;
} }
/**
* a function to fast remove elements from the list.
* @param from the start index of where the elements should be removed from (inclusive)
* @param to the end index of where the elements should be removed to (exclusive)
*/
@Override @Override
public void removeElements(int from, int to) { public void removeElements(int from, int to) {
checkRange(from); checkRange(from);
@ -217,6 +317,13 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#if TYPE_OBJECT #if TYPE_OBJECT
/**
* A function to fast extract elements out of the list, this removes the elements that were fetched.
* @param from the start index of where the elements should be fetched from (inclusive)
* @param to the end index of where the elements should be fetched to (exclusive)
* @param type the type of the OutputArray
* @return a array of the elements that were fetched
*/
@Override @Override
public <K> K[] extractElements(int from, int to, Class<K> type) { public <K> K[] extractElements(int from, int to, Class<K> type) {
checkRange(from); checkRange(from);
@ -233,6 +340,12 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#else #else
/**
* A function to fast extract elements out of the list, this removes the elements that were fetched.
* @param from the start index of where the elements should be fetched from (inclusive)
* @param to the end index of where the elements should be fetched to (exclusive)
* @return a array of the elements that were fetched
*/
@Override @Override
public KEY_TYPE[] extractElements(int from, int to) { public KEY_TYPE[] extractElements(int from, int to) {
int length = to - from; int length = to - from;
@ -245,6 +358,14 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#endif #endif
/**
* A function to check if all elements requested are present in the other collection.
* This function might delegate to a more appropiate function if nessesary
* @param c the collection that should be checked
* @return true if the collection contains all elements in this list
* @throws NullPointerException if the collection is null
* @deprecated if the collection is type-specific
*/
@Override @Override
@Primitive @Primitive
public boolean containsAll(Collection<?> c) { public boolean containsAll(Collection<?> c) {
@ -260,6 +381,14 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return true; return true;
} }
/**
* A function to check if any element of this list is present in the collection.
* This function might delegate to a more appropiate function if nessesary
* @param c the collection that should be checked
* @return true if the collection contains any elements in this list
* @throws NullPointerException if the collection is null
* @deprecated if the collection is type-specific
*/
@Override @Override
@Primitive @Primitive
public boolean containsAny(Collection<?> c) public boolean containsAny(Collection<?> c)
@ -276,20 +405,48 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return false; return false;
} }
/**
* A function to find the index of a given element
* @param e the element that is searched for
* @return the index of the element if found. (if not found then -1)
* @deprecated if type-specific but still supported because of special edgecase Object-Comparason features
*/
@Override @Override
@Primitive @Primitive
public int indexOf(Object o) { public int indexOf(Object o) {
#if TYPE_OBJECT
if(o == null) {
for(int i = 0;i<size;i++)
if(data[i] == null) return i;
return -1;
}
#else
if(o == null) return -1; if(o == null) return -1;
#endif
for(int i = 0;i<size;i++) { for(int i = 0;i<size;i++) {
if(EQUALS_KEY_TYPE(data[i], o)) return i; if(EQUALS_KEY_TYPE(data[i], o)) return i;
} }
return -1; return -1;
} }
/**
* A function to find the last index of a given element
* @param e the element that is searched for
* @return the last index of the element if found. (if not found then -1)
* @deprecated if type-specific but still supported because of special edgecase Object-Comparason features
*/
@Override @Override
@Primitive @Primitive
public int lastIndexOf(Object o) { public int lastIndexOf(Object o) {
#if TYPE_OBJECT
if(o == null) {
for(int i = size - 1;i>=0;i--)
if(data[i] == null) return i;
return -1;
}
#else
if(o == null) return -1; if(o == null) return -1;
#endif
for(int i = size - 1;i>=0;i--) { for(int i = size - 1;i>=0;i--) {
if(EQUALS_KEY_TYPE(data[i], o)) return i; if(EQUALS_KEY_TYPE(data[i], o)) return i;
} }
@ -297,12 +454,22 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#if TYPE_OBJECT #if TYPE_OBJECT
/**
* Sorts the elements specified by the Natural order either by using the Comparator or the elements
* @see List#sort(Comparator)
* @see ARRAYS#stableSort(KEY_TYPE[], Comparator)
*/
@Override @Override
public void sort(Comparator<? super CLASS_TYPE> c) { public void sort(Comparator<? super CLASS_TYPE> c) {
if(c != null) ARRAYS.stableSort(data, size, c); if(c != null) ARRAYS.stableSort(data, size, c);
else ARRAYS.stableSort((Comparable[])data, size); else ARRAYS.stableSort((Comparable[])data, size);
} }
/**
* Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort
* @see List#sort(Comparator)
* @see ARRAYS#unstableSort(KEY_TYPE[], Comparator)
*/
@Override @Override
public void unstableSort(Comparator<? super CLASS_TYPE> c) { public void unstableSort(Comparator<? super CLASS_TYPE> c) {
if(c != null) ARRAYS.unstableSort(data, size, c); if(c != null) ARRAYS.unstableSort(data, size, c);
@ -310,6 +477,12 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#endif #endif
/**
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
* @param the collection that should be checked if it contains all elements.
* @return true if all elements were found in the collection
* @throws NullPointerException if the collection is null
*/
@Override @Override
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
Objects.requireNonNull(c); Objects.requireNonNull(c);
@ -319,6 +492,12 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return true; return true;
} }
/**
* This implementation iterates over the elements of the collection and checks if they are stored in this collection.
* @param c the elements that should be checked for
* @return true if any element is in this collection
* @throws NullPointerException if the collection is null
*/
@Override @Override
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
Objects.requireNonNull(c); Objects.requireNonNull(c);
@ -329,6 +508,11 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#if !TYPE_OBJECT #if !TYPE_OBJECT
/**
* A Type-Specific function to find the index of a given element
* @param e the element that is searched for
* @return the index of the element if found. (if not found then -1)
*/
@Override @Override
public int indexOf(KEY_TYPE e) { public int indexOf(KEY_TYPE e) {
for(int i = 0;i<size;i++) { for(int i = 0;i<size;i++) {
@ -337,6 +521,11 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return -1; return -1;
} }
/**
* A Type-Specific function to find the last index of a given element
* @param e the element that is searched for
* @return the last index of the element if found. (if not found then -1)
*/
@Override @Override
public int lastIndexOf(KEY_TYPE e) { public int lastIndexOf(KEY_TYPE e) {
for(int i = size - 1;i>=0;i--) { for(int i = size - 1;i>=0;i--) {
@ -345,12 +534,22 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return -1; return -1;
} }
/**
* Sorts the elements specified by the Natural order either by using the Comparator or the elements
* @see List#sort(Comparator)
* @see ARRAYS#stableSort(KEY_TYPE[], Comparator)
*/
@Override @Override
public void sort(COMPARATOR c) { public void sort(COMPARATOR c) {
if(c != null) ARRAYS.stableSort(data, size, c); if(c != null) ARRAYS.stableSort(data, size, c);
else ARRAYS.stableSort(data, size); else ARRAYS.stableSort(data, size);
} }
/**
* Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort
* @see List#sort(Comparator)
* @see ARRAYS#unstableSort(KEY_TYPE[], Comparator)
*/
@Override @Override
public void unstableSort(COMPARATOR c) { public void unstableSort(COMPARATOR c) {
if(c != null) ARRAYS.unstableSort(data, size, c); if(c != null) ARRAYS.unstableSort(data, size, c);
@ -358,31 +557,70 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#endif #endif
/**
* A Type-Specific get function to reduce (un)boxing
* @param index the index of the element to fetch
* @return the value of the requested index
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override @Override
public KEY_TYPE GET_KEY(int index) { public KEY_TYPE GET_KEY(int index) {
checkRange(index); checkRange(index);
return data[index]; return data[index];
} }
/**
* Provides the Selected Object from the stack.
* Top to bottom
* @param index of the element that should be provided
* @return the element that was requested
* @throws ArrayIndexOutOfBoundsException if the index is out of bounds
* @see Stack#peek(int)
*/
@Override @Override
public KEY_TYPE PEEK(int index) { public KEY_TYPE PEEK(int index) {
checkRange((size() - 1) - index); checkRange((size() - 1) - index);
return data[(size() - 1) - index]; return data[(size() - 1) - index];
} }
/**
* Provides the Underlying Array in the Implementation
* @return underlying Array
* @throws ClassCastException if the return type does not match the underlying array. (Only for Object Implementations)
*/
@Override @Override
public KEY_TYPE[] elements() { public KEY_TYPE[] elements() {
return data; return data;
} }
/**
* A Type Specific foreach function that reduces (un)boxing
*
* @implSpec
* <p>The default implementation behaves as if:
* <pre>{@code
* for(int i = 0;i<size;i++)
* action.accept(data[i]);
* }</pre>
*
* @param action The action to be performed for each element
* @throws NullPointerException if the specified action is null
* @see Iterable#forEach(Consumer)
*/
@Override @Override
@Primitive
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
Objects.requireNonNull(action); Objects.requireNonNull(action);
for(int i = 0;i<size;i++) for(int i = 0;i<size;i++)
action.accept(data[i]); action.accept(data[i]);
} }
/**
* A Type-Specific set function to reduce (un)boxing
* @param index the index of the element to set
* @param e the value that should be set
* @return the previous element
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override @Override
public KEY_TYPE set(int index, KEY_TYPE e) { public KEY_TYPE set(int index, KEY_TYPE e) {
checkRange(index); checkRange(index);
@ -391,13 +629,29 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return old; return old;
} }
/**
* A function to replace all values in the list
* @param o the action to replace the values
* @throws NullPointerException if o is null
*/
@Override @Override
@Primitive
public void replaceAll(UnaryOperator<CLASS_TYPE> o) { public void replaceAll(UnaryOperator<CLASS_TYPE> o) {
for(int i = 0;i<size;i++) Objects.requireNonNull(o);
data[i] = OBJ_TO_KEY(o.apply(KEY_TO_OBJ(data[i]))); #if TYPE_OBJECT
REPLACE(T -> KEY_TO_OBJ(o.APPLY(OBJ_TO_KEY(T))));
#else
for(int i = 0;i<size;i++)
data[i] = OBJ_TO_KEY(o.apply(KEY_TO_OBJ(data[i])));
#endif
} }
#if PRIMITIVES #if PRIMITIVES
/**
* A Type-Specific replace function to reduce (un)boxing
* @param o the action to replace the values
* @throws NullPointerException if o is null
*/
@Override @Override
public void REPLACE(UNARY_OPERATOR o) { public void REPLACE(UNARY_OPERATOR o) {
for(int i = 0;i<size;i++) for(int i = 0;i<size;i++)
@ -409,6 +663,12 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#endif #endif
/**
* A Type-Specific remove function to reduce (un)boxing
* @param index the index of the element to fetch
* @return the value of the requested index
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override @Override
public KEY_TYPE REMOVE(int index) { public KEY_TYPE REMOVE(int index) {
checkRange(index); checkRange(index);
@ -421,26 +681,52 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return old; return old;
} }
/**
* A Type-Specific pop function to reduce (un)boxing
* @param index the index of the element to fetch
* @return the value of the requested index
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override @Override
public KEY_TYPE POP() { public KEY_TYPE POP() {
return REMOVE(size() - 1); return REMOVE(size() - 1);
} }
/**
* A function to remove all elements that were provided in the other collection
* This function might delegate to a more appropiate function if nessesary
* @param c the elements that should be removed
* @return true if the collection was modified
* @throws NullPointerException if the collection is null
* @deprecated if the collection is type-specific
*/
@Override @Override
@Primitive @Primitive
public boolean removeAll(Collection<?> c) { public boolean removeAll(Collection<?> c) {
if(c.isEmpty()) return false; if(c.isEmpty()) return false;
if(c instanceof COLLECTION) return removeAll((COLLECTION KEY_GENERIC_TYPE)c); if(c instanceof COLLECTION) return removeAll((COLLECTION KEY_GENERIC_TYPE)c);
boolean modified = false; boolean modified = false;
for(int i = 0, j = 0;i<size;i++) { int j = 0;
for(int i = 0;i<size;i++) {
if(!c.contains(KEY_TO_OBJ(data[i]))) { if(!c.contains(KEY_TO_OBJ(data[i]))) {
data[j++] = data[i]; data[j++] = data[i];
modified = true; modified = true;
} }
} }
#if TYPE_OBJECT
Arrays.fill(data, j, size, null);
#endif
return modified; return modified;
} }
/**
* A function to retain all elements that were provided in the other collection
* This function might delegate to a more appropiate function if nessesary
* @param c the elements that should be kept. If empty, ARRAY_LIST#clear is called.
* @return true if the collection was modified
* @throws NullPointerException if the collection is null
* @deprecated if the collection is type-specific
*/
@Override @Override
@Primitive @Primitive
public boolean retainAll(Collection<?> c) { public boolean retainAll(Collection<?> c) {
@ -451,42 +737,74 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
if(c instanceof COLLECTION) return retainAll((COLLECTION KEY_GENERIC_TYPE)c); if(c instanceof COLLECTION) return retainAll((COLLECTION KEY_GENERIC_TYPE)c);
boolean modified = false; boolean modified = false;
for(int i = 0, j = 0;i<size;i++) { int j = 0;
for(int i = 0;i<size;i++) {
if(c.contains(KEY_TO_OBJ(data[i]))) { if(c.contains(KEY_TO_OBJ(data[i]))) {
data[j++] = data[i]; data[j++] = data[i];
modified = true; modified = true;
} }
} }
#if TYPE_OBJECT
Arrays.fill(data, j, size, null);
#endif
return modified; return modified;
} }
/**
* A optimized List#removeIf(Predicate) that more quickly removes elements from the list then the ArrayList implementation
* @param filter the filter to remove elements
* @return true if the list was modified
* @deprecated if Type-Specific, use #remIf instead
*/
@Override @Override
@Primitive @Primitive
public boolean removeIf(Predicate<? super CLASS_TYPE> filter) { public boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
boolean modified = false; boolean modified = false;
for(int i = 0, j = 0;i<size;i++) { int j = 0;
for(int i = 0;i<size;i++) {
if(!filter.test(KEY_TO_OBJ(data[i]))) { if(!filter.test(KEY_TO_OBJ(data[i]))) {
data[j++] = data[i]; data[j++] = data[i];
modified = true; modified = true;
} }
} }
#if TYPE_OBJECT
Arrays.fill(data, j, size, null);
#endif
return modified; return modified;
} }
/**
* A function to remove all elements that were provided in the other collection
* @param c the elements that should be removed
* @return true if the collection was modified
* @throws NullPointerException if the collection is null
*/
@Override @Override
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
if(c.isEmpty()) return false; if(c.isEmpty()) return false;
boolean modified = false; boolean modified = false;
for(int i = 0, j = 0;i<size;i++) { int j = 0;
for(int i = 0;i<size;i++) {
if(!c.contains(data[i])) { if(!c.contains(data[i])) {
data[j++] = data[i]; data[j++] = data[i];
modified = true; modified = true;
} }
} }
#if TYPE_OBJECT
Arrays.fill(data, j, size, null);
#endif
return modified; return modified;
} }
/**
* A function to retain all elements that were provided in the other collection
* This function might delegate to a more appropiate function if nessesary
* @param c the elements that should be kept. If empty, ARRAY_LIST#clear is called.
* @return true if the collection was modified
* @throws NullPointerException if the collection is null
*/
@Override @Override
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
if(c.isEmpty()) { if(c.isEmpty()) {
@ -495,16 +813,25 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return modifed; return modifed;
} }
boolean modified = false; boolean modified = false;
for(int i = 0, j = 0;i<size;i++) { int j = 0;
for(int i = 0;i<size;i++) {
if(c.contains(data[i])) { if(c.contains(data[i])) {
data[j++] = data[i]; data[j++] = data[i];
modified = true; modified = true;
} }
} }
#if TYPE_OBJECT
Arrays.fill(data, j, size, null);
#endif
return modified; return modified;
} }
#if PRIMITIVES #if PRIMITIVES
/**
* A optimized List#removeIf(Predicate) that more quickly removes elements from the list then the ArrayList implementation
* @param filter the filter to remove elements
* @return true if the list was modified
*/
@Override @Override
public boolean remIf(JAVA_PREDICATE filter) { public boolean remIf(JAVA_PREDICATE filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
@ -519,6 +846,10 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#endif #endif
/**
* A toArray implementation that ensures the Array itself is a Object.
* @return a Array of the elements in the list
*/
@Override @Override
@Primitive @Primitive
public Object[] toArray() { public Object[] toArray() {
@ -528,6 +859,11 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return obj; return obj;
} }
/**
* A toArray implementation that ensures the Array itself is a Object.
* @param a original array. If null a Object array with the right size is created. If to small the Array of the same type is created with the right size
* @return a Array of the elements in the list
*/
@Override @Override
@Primitive @Primitive
public <E> E[] toArray(E[] a) { public <E> E[] toArray(E[] a) {
@ -547,11 +883,21 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
} }
#endif #endif
/**
* A function to return the size of the list
* @return the size of elements in the list
*/
@Override @Override
public int size() { public int size() {
return size; return size;
} }
/**
* A function to ensure the elements are within the requested size.
* If smaller then the stored elements they get removed as needed.
* If bigger it is ensured that enough room is provided depending on the implementation
* @param size the requested amount of elements/room for elements
*/
@Override @Override
public void size(int size) { public void size(int size) {
if(size > data.length) if(size > data.length)
@ -560,6 +906,9 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
Arrays.fill(data, size, size(), EMPTY_VALUE); Arrays.fill(data, size, size(), EMPTY_VALUE);
} }
/**
* A function to clear all elements in the list.
*/
@Override @Override
public void clear() { public void clear() {
#if TYPE_OBJECT #if TYPE_OBJECT
@ -568,6 +917,10 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
size = 0; size = 0;
} }
/**
* Trims the original collection down to the size of the current elements or the requested size depending which is bigger
* @param size the requested trim size.
*/
@Override @Override
public void trim(int size) { public void trim(int size) {
if(size > size() || size() == data.length) return; if(size > size() || size() == data.length) return;
@ -579,6 +932,13 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
#endif #endif
} }
/**
* Increases the capacity of this implementation instance, if necessary,
* to ensure that it can hold at least the number of elements specified by
* the minimum capacity argument.
*
* @param size the desired minimum capacity
*/
@Override @Override
public void ensureCapacity(int size) { public void ensureCapacity(int size) {
grow(size); grow(size);

View File

@ -142,7 +142,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
#endif #endif
/** /**
* A method to fast add elements to the list * A function to fast add elements to the list
* @param from the index where the elements should be added into the list * @param from the index where the elements should be added into the list
* @param a the elements that should be added * @param a the elements that should be added
* @throws IndexOutOfBoundsException if from is outside of the lists range * @throws IndexOutOfBoundsException if from is outside of the lists range
@ -150,7 +150,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
public default void addElements(int from, KEY_TYPE[] a) { addElements(from, a, 0, a.length); } public default void addElements(int from, KEY_TYPE[] a) { addElements(from, a, 0, a.length); }
/** /**
* A method to fast add elements to the list * A function to fast add elements to the list
* @param from the index where the elements should be added into the list * @param from the index where the elements should be added into the list
* @param a the elements that should be added * @param a the elements that should be added
* @param offset the start index of the array should be read from * @param offset the start index of the array should be read from
@ -161,7 +161,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
public void addElements(int from, KEY_TYPE[] a, int offset, int length); public void addElements(int from, KEY_TYPE[] a, int offset, int length);
/** /**
* A method to fast fetch elements from the list * A function to fast fetch elements from the list
* @param from index where the list should be fetching elements from * @param from index where the list should be fetching elements from
* @param a the array where the values should be inserted to * @param a the array where the values should be inserted to
* @returns the inputArray * @returns the inputArray
@ -172,7 +172,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
public default KEY_TYPE[] getElements(int from, KEY_TYPE[] a) { return getElements(from, a, 0, a.length); } public default KEY_TYPE[] getElements(int from, KEY_TYPE[] a) { return getElements(from, a, 0, a.length); }
/** /**
* A method to fast fetch elements from the list * A function to fast fetch elements from the list
* @param from index where the list should be fetching elements from * @param from index where the list should be fetching elements from
* @param a the array where the values should be inserted to * @param a the array where the values should be inserted to
* @param offset the startIndex of where the array should be written to * @param offset the startIndex of where the array should be written to
@ -185,7 +185,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length); public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length);
/** /**
* a method to fast remove elements from the list. * a function to fast remove elements from the list.
* @param from the start index of where the elements should be removed from (inclusive) * @param from the start index of where the elements should be removed from (inclusive)
* @param to the end index of where the elements should be removed to (exclusive) * @param to the end index of where the elements should be removed to (exclusive)
*/ */
@ -193,7 +193,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
#if TYPE_OBJECT #if TYPE_OBJECT
/** /**
* A method to fast extract elements out of the list, this removes the elements that were fetched. * A function to fast extract elements out of the list, this removes the elements that were fetched.
* @param from the start index of where the elements should be fetched from (inclusive) * @param from the start index of where the elements should be fetched from (inclusive)
* @param to the end index of where the elements should be fetched to (exclusive) * @param to the end index of where the elements should be fetched to (exclusive)
* @param type the type of the OutputArray * @param type the type of the OutputArray
@ -236,7 +236,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
#else #else
/** /**
* A method to fast extract elements out of the list, this removes the elements that were fetched. * A function to fast extract elements out of the list, this removes the elements that were fetched.
* @param from the start index of where the elements should be fetched from (inclusive) * @param from the start index of where the elements should be fetched from (inclusive)
* @param to the end index of where the elements should be fetched to (exclusive) * @param to the end index of where the elements should be fetched to (exclusive)
* @return a array of the elements that were fetched * @return a array of the elements that were fetched
@ -244,8 +244,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
public KEY_TYPE[] extractElements(int from, int to); public KEY_TYPE[] extractElements(int from, int to);
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -270,8 +270,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Deprecated @Deprecated
public default void unstableSort(Comparator<? super CLASS_TYPE> c) { public default void unstableSort(Comparator<? super CLASS_TYPE> c) {
@ -317,7 +317,7 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
public LIST KEY_GENERIC_TYPE subList(int from, int to); public LIST KEY_GENERIC_TYPE subList(int from, int to);
/** /**
* A Method to ensure the elements are within the requested size. * A function to ensure the elements are within the requested size.
* If smaller then the stored elements they get removed as needed. * If smaller then the stored elements they get removed as needed.
* If bigger it is ensured that enough room is provided depending on the implementation * If bigger it is ensured that enough room is provided depending on the implementation
* @param size the requested amount of elements/room for elements * @param size the requested amount of elements/room for elements
@ -327,8 +327,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
#if !TYPE_OBJECT #if !TYPE_OBJECT
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -337,8 +337,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -347,8 +347,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -357,8 +357,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -367,8 +367,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -377,8 +377,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -387,8 +387,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -397,8 +397,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -408,8 +408,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
#if !TYPE_BOOLEAN #if !TYPE_BOOLEAN
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated

View File

@ -20,8 +20,8 @@ public interface LIST_ITERATOR KEY_GENERIC_TYPE extends ListIterator<CLASS_TYPE>
public void add(KEY_TYPE e); public void add(KEY_TYPE e);
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -30,8 +30,8 @@ public interface LIST_ITERATOR KEY_GENERIC_TYPE extends ListIterator<CLASS_TYPE>
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -40,8 +40,8 @@ public interface LIST_ITERATOR KEY_GENERIC_TYPE extends ListIterator<CLASS_TYPE>
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated
@ -50,8 +50,8 @@ public interface LIST_ITERATOR KEY_GENERIC_TYPE extends ListIterator<CLASS_TYPE>
} }
/** {@inheritDoc} /** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific method. * <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific method instead. * @deprecated Please use the corresponding type-specific function instead.
*/ */
@Override @Override
@Deprecated @Deprecated

View File

@ -19,7 +19,7 @@ public interface IARRAY KEY_GENERIC_TYPE extends IArray
public KEY_TYPE[] elements(); public KEY_TYPE[] elements();
/** /**
* Provides the Underlying Array in the Implementation. This method exists purely because of Synchronization wrappers to help run Synchronized Code * Provides the Underlying Array in the Implementation. This function exists purely because of Synchronization wrappers to help run Synchronized Code
* @param action the action that handles the array * @param action the action that handles the array
* @throws NullPointerException if action is null * @throws NullPointerException if action is null
* @throws ClassCastException if the return type does not match the underlying array. (Only for Object Implementations) * @throws ClassCastException if the return type does not match the underlying array. (Only for Object Implementations)