Project is now buildable.
-Moved: Code generation is in its own sourceset. -Fixed: Bugs that caused that the project isnt buildable. -Changed: Made build.gradle to a standard.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+404
@@ -0,0 +1,404 @@
|
||||
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
|
||||
|
||||
/**
|
||||
* A Helper class for Collections
|
||||
*/
|
||||
public class COLLECTIONS
|
||||
{
|
||||
public static final COLLECTION NO_GENERIC_TYPE EMPTY = new EmptyCollectionBRACES();
|
||||
|
||||
/**
|
||||
* Returns a Immutable EmptyCollection instance that is automatically casted.
|
||||
* @return an empty collection
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE emptyCollection() {
|
||||
#if TYPE_OBJECT
|
||||
return (COLLECTION<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
return EMPTY;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Immutable Collection instance based on the instance given.
|
||||
* @param l that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable collection wrapper. If the Collection already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE unmodifiableCollection(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized Collection instance based on the instance given.
|
||||
* @param l that should be synchronized
|
||||
* @return a synchronized collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE synchronizedCollection(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized Collection instance based on the instance given.
|
||||
* @param l that should be synchronized
|
||||
* @param mutex is the controller of the synchronization block.
|
||||
* @return a synchronized collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_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
|
||||
@Primitive
|
||||
public boolean containsAll(Collection<?> c) { synchronized(mutex) { return this.c.containsAll(c); } }
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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
|
||||
@Primitive
|
||||
public boolean removeAll(Collection<?> c) { synchronized(mutex) { return this.c.removeAll(c); } }
|
||||
@Override
|
||||
@Primitive
|
||||
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
|
||||
@Primitive
|
||||
public boolean containsAny(Collection<?> c) {
|
||||
return this.c.containsAny(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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
|
||||
@Primitive
|
||||
public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@Primitive
|
||||
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
|
||||
@Primitive
|
||||
public boolean containsAny(Collection<?> c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
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
|
||||
@Primitive
|
||||
public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@Primitive
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.utils.IArray;
|
||||
|
||||
/**
|
||||
* Type-Specific Helper class to get the underlying array of array implementations.
|
||||
* @see speiger.src.collections.PACKAGE.lists.ARRAY_LIST
|
||||
*/
|
||||
public interface IARRAY KEY_GENERIC_TYPE extends IArray
|
||||
{
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
public KEY_TYPE[] elements();
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @throws NullPointerException if action is null
|
||||
* @throws ClassCastException if the return type does not match the underlying array. (Only for Object Implementations)
|
||||
*/
|
||||
public default void elements(Consumer<KEY_TYPE[]> action) {
|
||||
Objects.requireNonNull(action);
|
||||
action.accept(elements());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
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;
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
|
||||
/**
|
||||
* A Helper class for Iterators
|
||||
*/
|
||||
public class ITERATORS
|
||||
{
|
||||
public static final EmptyIterator NO_GENERIC_TYPE EMPTY = new EmptyIteratorBRACES();
|
||||
|
||||
/**
|
||||
* Returns a Immutable EmptyIterator instance that is automatically casted.
|
||||
* @return an empty iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES EmptyIterator KEY_GENERIC_TYPE emptyIterator() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyIterator<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
return EMPTY;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES BI_ITERATOR KEY_GENERIC_TYPE invert(BI_ITERATOR KEY_GENERIC_TYPE it) {
|
||||
return new BI_ITERATOR KEY_GENERIC_TYPE() {
|
||||
@Override
|
||||
public KEY_TYPE NEXT() { return it.PREVIOUS(); }
|
||||
@Override
|
||||
public boolean hasNext() { return it.hasPrevious(); }
|
||||
@Override
|
||||
public boolean hasPrevious() { return it.hasNext(); }
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() { return it.NEXT(); }
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
};
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE invert(LIST_ITERATOR KEY_GENERIC_TYPE it) {
|
||||
return new LIST_ITERATOR KEY_GENERIC_TYPE() {
|
||||
@Override
|
||||
public KEY_TYPE NEXT() { return it.PREVIOUS(); }
|
||||
@Override
|
||||
public boolean hasNext() { return it.hasPrevious(); }
|
||||
@Override
|
||||
public boolean hasPrevious() { return it.hasNext(); }
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() { return it.NEXT(); }
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
@Override
|
||||
public int nextIndex() { return it.previousIndex(); }
|
||||
@Override
|
||||
public int previousIndex() { return it.nextIndex(); }
|
||||
@Override
|
||||
public void set(KEY_TYPE e) { it.set(e); }
|
||||
@Override
|
||||
public void add(KEY_TYPE e) { it.add(e); }
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Immutable Iterator instance based on the instance given.
|
||||
* @param l that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable iterator wrapper. If the Iterator already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE unmodifiable(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return iterator instanceof UnmodifiableIterator ? iterator : new UnmodifiableIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES BI_ITERATOR KEY_GENERIC_TYPE unmodifiable(BI_ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return iterator instanceof UnmodifiableBiIterator ? iterator : new UnmodifiableBiIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Immutable ListIterator instance based on the instance given.
|
||||
* @param l that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable listiterator wrapper. If the ListIterator already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE unmodifiable(LIST_ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
public static ITERATOR wrap(Iterator<CLASS_TYPE> iterator) {
|
||||
return iterator instanceof ITERATOR ? (ITERATOR)iterator : new IteratorWrapper(iterator);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Returns a Array Wrapping iterator
|
||||
* @param a the array that should be wrapped
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Array Wrapping iterator
|
||||
* @param a the array that should be wrapped.
|
||||
* @param start the index to be started from.
|
||||
* @param end the index that should be ended.
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
return new ArrayIteratorBRACES(a, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
||||
* @param a where the elements should be inserted
|
||||
* @param i the source iterator
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i) {
|
||||
return unwrap(a, i, 0, a.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
||||
* @param a where the elements should be inserted
|
||||
* @param i the source iterator
|
||||
* @param offset the array offset where the start should be
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i, int offset) {
|
||||
return unwrap(a, i, offset, a.length - offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
||||
* @param a where the elements should be inserted
|
||||
* @param i the source iterator
|
||||
* @param offset the array offset where the start should be
|
||||
* @param max the maximum values that should be extracted from the source
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
* @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i, int offset, int max) {
|
||||
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
||||
if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size");
|
||||
int index = 0;
|
||||
for(;index<max && i.hasNext();index++) a[index+offset] = OBJ_TO_KEY(i.next());
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Primitive iterator variant of the {@link #unwrap(KEY_TYPE[], Iterator)} function
|
||||
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
||||
* @param a where the elements should be inserted
|
||||
* @param i the source iterator
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
||||
return unwrap(a, i, 0, a.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Primitive iterator variant of the {@link #unwrap(KEY_TYPE[], Iterator, int)} function
|
||||
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
||||
* @param a where the elements should be inserted
|
||||
* @param i the source iterator
|
||||
* @param offset the array offset where the start should be
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
||||
return unwrap(a, i, offset, a.length - offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Primitive iterator variant of the {@link #unwrap(KEY_TYPE[], Iterator, int, int)} function
|
||||
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
||||
* @param a where the elements should be inserted
|
||||
* @param i the source iterator
|
||||
* @param offset the array offset where the start should be
|
||||
* @param max the maximum values that should be extracted from the source
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
* @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
||||
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
||||
if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size");
|
||||
int index = 0;
|
||||
for(;index<max && i.hasNext();index++) a[index+offset] = i.NEXT();
|
||||
return index;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Function to convert a Primitive Iterator to a Object array.
|
||||
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
||||
* @param a where the elements should be inserted
|
||||
* @param i the source iterator
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
||||
return unwrap(a, i, 0, a.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Function to convert a Primitive Iterator to a Object array.
|
||||
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
||||
* @param a where the elements should be inserted
|
||||
* @param i the source iterator
|
||||
* @param offset the array offset where the start should be
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
||||
return unwrap(a, i, offset, a.length - offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Function to convert a Primitive Iterator to a Object array.
|
||||
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
||||
* @param a where the elements should be inserted
|
||||
* @param i the source iterator
|
||||
* @param offset the array offset where the start should be
|
||||
* @param max the maximum values that should be extracted from the source
|
||||
* @return the amount of elements that were inserted into the array.
|
||||
* @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
||||
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
||||
if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size");
|
||||
int index = 0;
|
||||
for(;index<max && i.hasNext();index++) a[index+offset] = KEY_TO_OBJ(i.NEXT());
|
||||
return index;
|
||||
}
|
||||
|
||||
private static class IteratorWrapper implements ITERATOR
|
||||
{
|
||||
Iterator<CLASS_TYPE> iter;
|
||||
|
||||
public IteratorWrapper(Iterator<CLASS_TYPE> iter) {
|
||||
this.iter = iter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iter.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
return OBJ_TO_KEY(iter.next());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public CLASS_TYPE next() {
|
||||
return iter.next();
|
||||
}
|
||||
}
|
||||
|
||||
#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 UnmodifiableBiIterator KEY_GENERIC_TYPE implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
BI_ITERATOR KEY_GENERIC_TYPE iter;
|
||||
|
||||
UnmodifiableBiIterator(BI_ITERATOR KEY_GENERIC_TYPE iter) {
|
||||
this.iter = iter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
return iter.NEXT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iter.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return iter.hasPrevious();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
return iter.PREVIOUS();
|
||||
}
|
||||
}
|
||||
|
||||
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_KEY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
return EMPTY_KEY_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;
|
||||
int from;
|
||||
int to;
|
||||
|
||||
ArrayIterator(KEY_TYPE[] a, int from, int to) {
|
||||
this.a = a;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return from < to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
return a[from++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int left = Math.min(amount, to - from);
|
||||
from += left;
|
||||
return amount - left;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,400 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.RandomAccess;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* A Helper class for Lists
|
||||
*/
|
||||
public class LISTS
|
||||
{
|
||||
public static final EmptyList NO_GENERIC_TYPE EMPTY = new EmptyListBRACES();
|
||||
|
||||
/**
|
||||
* Returns a Immutable EmptyList instance that is automatically casted.
|
||||
* @return an empty list
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES EmptyList KEY_GENERIC_TYPE emptyList() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyList<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
return EMPTY;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Immutable List instance based on the instance given.
|
||||
* @param l that should be made immutable/unmodifyable
|
||||
* @return a unmodifiable list wrapper. If the list is implementing RandomAccess that is also transferred. If the List already a unmodifyable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE unmodifiableList(LIST KEY_GENERIC_TYPE l) {
|
||||
return l instanceof UnmodifiableList ? l : l instanceof RandomAccess ? new UnmodifiableRandomListBRACES(l) : new UnmodifiableListBRACES(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized List instance based on the instance given.
|
||||
* @param l that should be synchronized
|
||||
* @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l) {
|
||||
return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l) : new SynchronizedListBRACES(l)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized List instance based on the instance given.
|
||||
* @param l that should be synchronized
|
||||
* @param mutex is the controller of the synchronization block.
|
||||
* @return a synchronized list wrapper. If the list is implementing RandomAccess or IARRAY that is also transferred. If the List already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE synchronizedList(LIST KEY_GENERIC_TYPE l, Object mutex) {
|
||||
return l instanceof SynchronizedList ? l : (l instanceof IARRAY ? new SynchronizedArrayListBRACES(l, mutex) : (l instanceof RandomAccess ? new SynchronizedRandomAccessListBRACES(l, mutex) : new SynchronizedListBRACES(l, mutex)));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ensureCapacity(int size) { synchronized(mutex) { l.ensureCapacity(size); } }
|
||||
|
||||
@Override
|
||||
public boolean trim(int size) { synchronized(mutex) { return l.trim(size); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE[] elements() { synchronized(mutex) { return l.elements(); } }
|
||||
|
||||
@Override
|
||||
public void elements(Consumer<KEY_TYPE[]> action) {
|
||||
Objects.requireNonNull(action);
|
||||
synchronized(mutex) {
|
||||
action.accept(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 <K> K[] extractElements(int from, int to, Class<K> 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
|
||||
{
|
||||
final 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 <K> K[] extractElements(int from, int to, Class<K> 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 <K> K[] extractElements(int from, int to, Class<K> 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(); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,417 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.EmptyCollection;
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.SynchronizedCollection;
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.UnmodifiableCollection;
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
|
||||
public class SETS
|
||||
{
|
||||
public static final SET NO_GENERIC_TYPE EMPTY = new EmptySetBRACES();
|
||||
|
||||
public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT
|
||||
return (SET<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
return EMPTY;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedSet ? s : (s instanceof ITrimmable ? new SynchronizedTrimSetBRACES(s) : new SynchronizedSetBRACES(s));
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE synchronizedSet(SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||
return s instanceof SynchronizedSet ? s : (s instanceof ITrimmable ? new SynchronizedTrimSetBRACES(s, mutex) : new SynchronizedSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s) : new SynchronizedSortedSetBRACES(s));
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES SORTED_SET KEY_GENERIC_TYPE synchronizedSet(SORTED_SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s, mutex) : new SynchronizedSortedSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedNavigableSet ? s : (s instanceof ITrimmable ? new SynchronizedNavigableTrimSetBRACES(s) : new SynchronizedNavigableSetBRACES(s));
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE synchronizedSet(NAVIGABLE_SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||
return s instanceof SynchronizedNavigableSet ? s : (s instanceof ITrimmable ? new SynchronizedNavigableTrimSetBRACES(s, mutex) : new SynchronizedNavigableSetBRACES(s, mutex));
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE unmodifiable(SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedSet ? s : new SynchronizedSetBRACES(s);
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES SORTED_SET KEY_GENERIC_TYPE unmodifiable(SORTED_SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof SynchronizedSortedSet ? s : new SynchronizedSortedSetBRACES(s);
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_BRACES NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable(NAVIGABLE_SET KEY_GENERIC_TYPE s) {
|
||||
return s instanceof UnmodifiableNavigableSet ? s : new UnmodifiableNavigableSetBRACES(s);
|
||||
}
|
||||
|
||||
public static class EmptySet KEY_GENERIC_TYPE extends EmptyCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
}
|
||||
|
||||
public static class UnmodifiableNavigableSet KEY_GENERIC_TYPE extends UnmodifiableSortedSet KEY_GENERIC_TYPE implements NAVIGABLE_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
NAVIGABLE_SET KEY_GENERIC_TYPE n;
|
||||
|
||||
public UnmodifiableNavigableSet(NAVIGABLE_SET KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
n = c;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) { return n.contains(o); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object o) { return n.contains(o); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE lower(KEY_TYPE e) { return n.lower(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE floor(KEY_TYPE e) { return n.floor(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ceiling(KEY_TYPE e) { return n.ceiling(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE higher(KEY_TYPE e) { return n.higher(e); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE getDefaultMaxValue() { return n.getDefaultMaxValue(); }
|
||||
|
||||
@Override
|
||||
public void setDefaultMinValue(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE getDefaultMinValue() { return n.getDefaultMinValue(); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { return unmodifiable(n.headSet(toElement, inclusive)); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { return unmodifiable(n.tailSet(fromElement, inclusive)); }
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { return ITERATORS.unmodifiable(n.descendingIterator()); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { return unmodifiable(n.descendingSet()); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(n.subSet(fromElement, toElement)); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(n.headSet(toElement)); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(n.tailSet(fromElement)); }
|
||||
|
||||
}
|
||||
|
||||
public static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
SORTED_SET KEY_GENERIC_TYPE s;
|
||||
public UnmodifiableSortedSet(SORTED_SET KEY_GENERIC_TYPE c)
|
||||
{
|
||||
super(c);
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return s.comparator(); }
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(s.subSet(fromElement, toElement)); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(s.headSet(toElement)); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(s.tailSet(fromElement)); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
public static class UnmodifiableSet KEY_GENERIC_TYPE extends UnmodifiableCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||
{
|
||||
SET KEY_GENERIC_TYPE s;
|
||||
|
||||
public UnmodifiableSet(SET KEY_GENERIC_TYPE c)
|
||||
{
|
||||
super(c);
|
||||
s = c;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
}
|
||||
|
||||
public static class SynchronizedNavigableTrimSet KEY_GENERIC_TYPE extends SynchronizedNavigableSet KEY_GENERIC_TYPE implements ITrimmable
|
||||
{
|
||||
ITrimmable trim;
|
||||
|
||||
public SynchronizedNavigableTrimSet(NAVIGABLE_SET KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
trim = (ITrimmable)c;
|
||||
}
|
||||
|
||||
public SynchronizedNavigableTrimSet(NAVIGABLE_SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
trim = (ITrimmable)c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(int size) { synchronized(mutex) { return trim.trim(size); } }
|
||||
}
|
||||
|
||||
public static class SynchronizedNavigableSet KEY_GENERIC_TYPE extends SynchronizedSortedSet KEY_GENERIC_TYPE implements NAVIGABLE_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
NAVIGABLE_SET KEY_GENERIC_TYPE n;
|
||||
|
||||
public SynchronizedNavigableSet(NAVIGABLE_SET KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
n = c;
|
||||
}
|
||||
|
||||
public SynchronizedNavigableSet(NAVIGABLE_SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
n = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object o) { synchronized(mutex) { return n.contains(o); } }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) { synchronized(mutex) { return n.contains(o); } }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE lower(KEY_TYPE e) { synchronized(mutex) { return n.lower(e); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE floor(KEY_TYPE e) { synchronized(mutex) { return n.floor(e); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ceiling(KEY_TYPE e) { synchronized(mutex) { return n.ceiling(e); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE higher(KEY_TYPE e) { synchronized(mutex) { return n.higher(e); } }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE e) { synchronized(mutex) { n.setDefaultMaxValue(e); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE getDefaultMaxValue() { synchronized(mutex) { return n.getDefaultMaxValue(); } }
|
||||
|
||||
@Override
|
||||
public void setDefaultMinValue(KEY_TYPE e) { synchronized(mutex) { n.setDefaultMinValue(e); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE getDefaultMinValue() { synchronized(mutex) { return n.getDefaultMinValue(); } }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return synchronizedSet(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { synchronized(mutex) { return synchronizedSet(n.headSet(toElement, inclusive), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { synchronized(mutex) { return synchronizedSet(n.tailSet(fromElement, inclusive), mutex); } }
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { synchronized(mutex) { return n.descendingIterator(); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { synchronized(mutex) { return synchronizedSet(n.descendingSet(), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronizedSet(n.subSet(fromElement, toElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronizedSet(n.headSet(toElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronizedSet(n.tailSet(fromElement), mutex); } }
|
||||
}
|
||||
|
||||
public static class SynchronizedSortedTrimSet KEY_GENERIC_TYPE extends SynchronizedSortedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||
{
|
||||
ITrimmable trim;
|
||||
|
||||
public SynchronizedSortedTrimSet(SORTED_SET KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
trim = (ITrimmable)c;
|
||||
}
|
||||
|
||||
public SynchronizedSortedTrimSet(SORTED_SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
trim = (ITrimmable)c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(int size) { synchronized(mutex) { return trim.trim(size); } }
|
||||
}
|
||||
|
||||
public static class SynchronizedSortedSet KEY_GENERIC_TYPE extends SynchronizedSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
SORTED_SET KEY_GENERIC_TYPE s;
|
||||
|
||||
public SynchronizedSortedSet(SORTED_SET KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
s = c;
|
||||
}
|
||||
|
||||
public SynchronizedSortedSet(SORTED_SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator(){ synchronized(mutex) { return s.comparator(); } }
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronizedSet(s.subSet(fromElement, toElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronizedSet(s.headSet(toElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronizedSet(s.tailSet(fromElement), mutex); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
||||
}
|
||||
|
||||
public static class SynchronizedTrimSet KEY_GENERIC_TYPE extends SynchronizedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||
{
|
||||
ITrimmable trim;
|
||||
|
||||
public SynchronizedTrimSet(SET KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
trim = (ITrimmable)c;
|
||||
}
|
||||
|
||||
public SynchronizedTrimSet(SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
trim = (ITrimmable)c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(int size) { synchronized(mutex) { return trim.trim(size); } }
|
||||
}
|
||||
|
||||
public static class SynchronizedSet KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||
{
|
||||
SET KEY_GENERIC_TYPE s;
|
||||
|
||||
public SynchronizedSet(SET KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
s = c;
|
||||
}
|
||||
|
||||
public SynchronizedSet(SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
s = c;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE o) { synchronized(mutex) { return s.remove(o); } }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
public interface STRATEGY KEY_GENERIC_TYPE
|
||||
{
|
||||
public int hashCode(KEY_TYPE o);
|
||||
|
||||
public boolean equals(KEY_TYPE key, KEY_TYPE value);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package speiger.src.collections.PACKAGE.utils.maps;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
|
||||
public class MAPS
|
||||
{
|
||||
public static GENERIC_KEY_VALUE_BRACES ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entries = map.ENTRY_SET();
|
||||
return entries instanceof MAP.FastEntrySet ? ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastIterator() : entries.iterator();
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_VALUE_BRACES ObjectIterable<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterable(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entries = map.ENTRY_SET();
|
||||
return map instanceof MAP.FastEntrySet ? new ObjectIterable<MAP.Entry KEY_VALUE_GENERIC_TYPE>(){
|
||||
@Override
|
||||
public ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() { return ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastIterator(); }
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) { ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastForEach(action); }
|
||||
} : entries;
|
||||
}
|
||||
|
||||
public static GENERIC_KEY_VALUE_BRACES void fastForEach(MAP KEY_VALUE_GENERIC_TYPE map, Consumer<MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entries = map.ENTRY_SET();
|
||||
if(entries instanceof MAP.FastEntrySet) ((MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE)entries).fastForEach(action);
|
||||
else entries.forEach(action);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user