2020-12-01 02:43:13 +01:00
|
|
|
package speiger.src.collections.PACKAGE.utils;
|
|
|
|
|
2022-12-05 00:00:05 +01:00
|
|
|
import java.util.Arrays;
|
2020-12-01 02:43:13 +01:00
|
|
|
import java.util.Collection;
|
2022-12-07 02:50:42 +01:00
|
|
|
#if !TYPE_BOOLEAN
|
|
|
|
import java.util.ConcurrentModificationException;
|
|
|
|
#endif
|
2022-12-08 10:40:21 +01:00
|
|
|
import java.util.Iterator;
|
2022-12-05 07:10:53 +01:00
|
|
|
import java.util.NoSuchElementException;
|
2022-12-05 00:00:05 +01:00
|
|
|
import java.util.Objects;
|
2021-10-29 16:03:39 +02:00
|
|
|
#if TYPE_OBJECT
|
2022-12-05 00:00:05 +01:00
|
|
|
import java.util.Comparator;
|
2021-10-29 16:03:39 +02:00
|
|
|
import java.util.function.BiFunction;
|
|
|
|
#endif
|
2020-12-01 02:43:13 +01:00
|
|
|
import java.util.function.Predicate;
|
|
|
|
#if PRIMITIVES
|
|
|
|
import java.util.function.JAVA_PREDICATE;
|
|
|
|
#endif
|
2021-09-13 17:02:24 +02:00
|
|
|
import java.util.function.Consumer;
|
2020-12-01 02:43:13 +01:00
|
|
|
|
|
|
|
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
|
|
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|
|
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
2022-12-05 00:00:05 +01:00
|
|
|
#if !TYPE_OBJECT
|
|
|
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
|
|
#endif
|
2020-12-01 02:43:13 +01:00
|
|
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
|
|
|
#if !TYPE_OBJECT
|
2021-09-13 17:02:24 +02:00
|
|
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
2020-12-01 02:43:13 +01:00
|
|
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
|
|
|
#endif
|
2021-10-07 14:50:52 +02:00
|
|
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
2021-10-27 14:09:19 +02:00
|
|
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
2021-10-07 14:50:52 +02:00
|
|
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
2022-12-07 02:50:42 +01:00
|
|
|
#if !TYPE_BOOLEAN
|
|
|
|
import speiger.src.collections.utils.HashUtil;
|
|
|
|
#endif
|
2022-12-05 00:00:05 +01:00
|
|
|
import speiger.src.collections.utils.ITrimmable;
|
|
|
|
import speiger.src.collections.utils.SanityChecks;
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* A Helper class for Collections
|
|
|
|
*/
|
2020-12-01 02:43:13 +01:00
|
|
|
public class COLLECTIONS
|
|
|
|
{
|
2021-04-26 22:25:09 +02:00
|
|
|
/**
|
|
|
|
* Empty Collection Reference
|
|
|
|
*/
|
2020-12-01 02:43:13 +01:00
|
|
|
public static final COLLECTION NO_GENERIC_TYPE EMPTY = new EmptyCollectionBRACES();
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Returns a Immutable EmptyCollection instance that is automatically casted.
|
2021-04-24 20:13:25 +02:00
|
|
|
* @Type(T)
|
2020-12-06 09:32:22 +01:00
|
|
|
* @return an empty collection
|
|
|
|
*/
|
2021-06-23 18:53:40 +02:00
|
|
|
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE empty() {
|
2020-12-01 02:43:13 +01:00
|
|
|
#if TYPE_OBJECT
|
|
|
|
return (COLLECTION<KEY_TYPE>)EMPTY;
|
|
|
|
#else
|
|
|
|
return EMPTY;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Returns a Immutable Collection instance based on the instance given.
|
2021-04-24 17:37:06 +02:00
|
|
|
* @param c that should be made immutable/unmodifiable
|
2021-04-24 20:13:25 +02:00
|
|
|
* @Type(T)
|
2021-04-24 17:37:06 +02:00
|
|
|
* @return a unmodifiable collection wrapper. If the Collection already a unmodifiable wrapper then it just returns itself.
|
2020-12-06 09:32:22 +01:00
|
|
|
*/
|
2021-06-23 18:53:40 +02:00
|
|
|
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE unmodifiable(COLLECTION KEY_GENERIC_TYPE c) {
|
2020-12-01 02:43:13 +01:00
|
|
|
return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollectionBRACES(c);
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Returns a synchronized Collection instance based on the instance given.
|
2021-04-24 17:37:06 +02:00
|
|
|
* @param c that should be synchronized
|
2021-04-24 20:13:25 +02:00
|
|
|
* @Type(T)
|
2020-12-06 09:32:22 +01:00
|
|
|
* @return a synchronized collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
|
|
|
*/
|
2021-06-23 18:53:40 +02:00
|
|
|
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE synchronize(COLLECTION KEY_GENERIC_TYPE c) {
|
2020-12-01 02:43:13 +01:00
|
|
|
return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c);
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Returns a synchronized Collection instance based on the instance given.
|
2021-04-24 17:37:06 +02:00
|
|
|
* @param c that should be synchronized
|
2020-12-06 09:32:22 +01:00
|
|
|
* @param mutex is the controller of the synchronization block.
|
2021-04-24 20:13:25 +02:00
|
|
|
* @Type(T)
|
2020-12-06 09:32:22 +01:00
|
|
|
* @return a synchronized collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
|
|
|
*/
|
2021-06-23 18:53:40 +02:00
|
|
|
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE synchronize(COLLECTION KEY_GENERIC_TYPE c, Object mutex) {
|
2020-12-01 02:43:13 +01:00
|
|
|
return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c, mutex);
|
|
|
|
}
|
|
|
|
|
2022-12-05 07:10:53 +01:00
|
|
|
/**
|
|
|
|
* Creates a Singleton Collection of a given element
|
|
|
|
* @param element the element that should be converted into a singleton collection
|
|
|
|
* @Type(T)
|
|
|
|
* @return a singletoncollection of the given element
|
|
|
|
*/
|
|
|
|
public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE singleton(KEY_TYPE element) {
|
|
|
|
return new SingletonCollectionBRACES(element);
|
|
|
|
}
|
|
|
|
|
2022-12-05 00:00:05 +01:00
|
|
|
protected static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper() {
|
|
|
|
return new CollectionWrapperBRACES();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper(int size) {
|
|
|
|
return new CollectionWrapperBRACES(size);
|
|
|
|
}
|
|
|
|
|
2022-12-07 02:50:42 +01:00
|
|
|
#if !TYPE_BOOLEAN
|
|
|
|
protected static GENERIC_KEY_BRACES DistinctCollectionWrapper KEY_GENERIC_TYPE distinctWrapper() {
|
|
|
|
return new DistinctCollectionWrapperBRACES();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static GENERIC_KEY_BRACES DistinctCollectionWrapper KEY_GENERIC_TYPE distinctWrapper(int size) {
|
|
|
|
return new DistinctCollectionWrapperBRACES(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2022-12-05 00:00:05 +01:00
|
|
|
protected static class CollectionWrapper KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements ITrimmable {
|
|
|
|
KEY_TYPE[] elements;
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
public CollectionWrapper() {
|
|
|
|
this(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CollectionWrapper(int size) {
|
|
|
|
if(size < 0) throw new IllegalStateException("Size has to be 0 or greater");
|
|
|
|
elements = NEW_KEY_ARRAY(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean add(KEY_TYPE o) {
|
|
|
|
if(size >= elements.length) elements = Arrays.copyOf(elements, (int)Math.min((long)elements.length + (elements.length >> 1), SanityChecks.MAX_ARRAY_SIZE));
|
|
|
|
elements[size++] = o;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public KEY_TYPE GET_KEY(int index) {
|
|
|
|
if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
|
|
|
return elements[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
#if TYPE_OBJECT
|
|
|
|
@Override
|
|
|
|
public boolean remove(Object e) {
|
|
|
|
for(int i = 0;i<size;i++) {
|
|
|
|
if(KEY_EQUALS(elements[i], e)) {
|
|
|
|
removeIndex(i);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
@Override
|
|
|
|
public boolean REMOVE_KEY(KEY_TYPE e) {
|
|
|
|
for(int i = 0;i<size;i++) {
|
|
|
|
if(KEY_EQUALS(elements[i], e)) {
|
|
|
|
removeIndex(i);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
private void removeIndex(int index) {
|
|
|
|
if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
|
|
|
size--;
|
|
|
|
if(index != size) System.arraycopy(elements, index+1, elements, index, size - index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
|
|
|
return new ITERATOR KEY_GENERIC_TYPE() {
|
|
|
|
int index = 0;
|
|
|
|
int lastReturned = -1;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() {
|
|
|
|
return index < size;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() {
|
|
|
|
int i = index++;
|
|
|
|
return elements[(lastReturned = i)];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove() {
|
|
|
|
if(lastReturned == -1) throw new IllegalStateException();
|
|
|
|
removeIndex(lastReturned);
|
|
|
|
index = lastReturned;
|
|
|
|
lastReturned = -1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int size() {
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clear() {
|
|
|
|
#if TYPE_OBJECT
|
|
|
|
for(int i = 0;i<size;elements[i] = null,i++);
|
|
|
|
#endif
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if TYPE_OBJECT
|
|
|
|
public void sort(Comparator<? super CLASS_TYPE> c) {
|
|
|
|
if(c != null) ARRAYS.stableSort(elements, size, c);
|
|
|
|
else ARRAYS.stableSort(elements, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unstableSort(Comparator<? super CLASS_TYPE> c) {
|
|
|
|
if(c != null) ARRAYS.unstableSort(elements, size, c);
|
|
|
|
else ARRAYS.unstableSort(elements, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
public void sort(COMPARATOR c) {
|
|
|
|
if(c != null) ARRAYS.stableSort(elements, size, c);
|
|
|
|
else ARRAYS.stableSort(elements, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unstableSort(COMPARATOR c) {
|
|
|
|
if(c != null) ARRAYS.unstableSort(elements, size, c);
|
|
|
|
else ARRAYS.unstableSort(elements, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
@Override
|
|
|
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
|
|
|
Objects.requireNonNull(action);
|
|
|
|
for(int i = 0;i<size;i++)
|
|
|
|
action.accept(elements[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
|
|
|
Objects.requireNonNull(action);
|
|
|
|
for(int i = 0;i<size;i++)
|
|
|
|
action.accept(input, elements[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean trim(int size) {
|
|
|
|
if(size > size() || size() == elements.length) return false;
|
|
|
|
int value = Math.max(size, size());
|
|
|
|
elements = value == 0 ? EMPTY_KEY_ARRAY : Arrays.copyOf(elements, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clearAndTrim(int size) {
|
|
|
|
if(elements.length <= size) {
|
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elements = size == 0 ? EMPTY_KEY_ARRAY : NEW_KEY_ARRAY(size);
|
|
|
|
this.size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Primitive
|
|
|
|
public Object[] toArray() {
|
|
|
|
Object[] obj = new Object[size];
|
|
|
|
for(int i = 0;i<size;i++)
|
|
|
|
obj[i] = KEY_TO_OBJ(elements[i]);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Primitive
|
|
|
|
public <E> E[] toArray(E[] a) {
|
|
|
|
if(a == null) a = (E[])new Object[size];
|
|
|
|
else if(a.length < size) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size);
|
|
|
|
#if TYPE_OBJECT
|
|
|
|
System.arraycopy(elements, 0, a, 0, size);
|
|
|
|
#else
|
|
|
|
for(int i = 0;i<size;i++)
|
|
|
|
a[i] = (E)KEY_TO_OBJ(elements[i]);
|
|
|
|
#endif
|
|
|
|
if (a.length > size) a[size] = null;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !TYPE_OBJECT
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
|
|
|
if(a.length < size) a = new KEY_TYPE[size];
|
|
|
|
System.arraycopy(elements, 0, a, 0, size);
|
|
|
|
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-12-07 02:50:42 +01:00
|
|
|
#if !TYPE_BOOLEAN
|
|
|
|
protected static class DistinctCollectionWrapper KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE {
|
|
|
|
KEY_TYPE[] keys;
|
|
|
|
boolean containsNull;
|
|
|
|
int minCapacity;
|
|
|
|
int nullIndex;
|
|
|
|
int maxFill;
|
|
|
|
int mask;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
public DistinctCollectionWrapper() {
|
|
|
|
this(HashUtil.DEFAULT_MIN_CAPACITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public DistinctCollectionWrapper(int size) {
|
|
|
|
if(minCapacity < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
|
|
|
|
minCapacity = nullIndex = HashUtil.arraySize(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR);
|
|
|
|
mask = nullIndex - 1;
|
|
|
|
maxFill = Math.min((int)Math.ceil(nullIndex * HashUtil.DEFAULT_LOAD_FACTOR), nullIndex - 1);
|
|
|
|
keys = NEW_KEY_ARRAY(nullIndex + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean add(KEY_TYPE o) {
|
|
|
|
if(KEY_EQUALS_NULL(o)) {
|
|
|
|
if(containsNull) return false;
|
|
|
|
containsNull = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
|
|
|
KEY_TYPE current = keys[pos];
|
|
|
|
if(KEY_EQUALS_NOT_NULL(current)) {
|
|
|
|
if(KEY_EQUALS(current, o)) return false;
|
|
|
|
while(KEY_EQUALS_NOT_NULL((current = keys[pos = (++pos & mask)])))
|
|
|
|
if(KEY_EQUALS(current, o)) return false;
|
|
|
|
}
|
|
|
|
keys[pos] = o;
|
|
|
|
}
|
|
|
|
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, HashUtil.DEFAULT_LOAD_FACTOR));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean contains(Object o) {
|
|
|
|
#if TYPE_OBJECT
|
|
|
|
if(o == null) return containsNull;
|
|
|
|
#else
|
|
|
|
if(o == null) return false;
|
|
|
|
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return containsNull;
|
|
|
|
#endif
|
|
|
|
int pos = HashUtil.mix(o.hashCode()) & mask;
|
|
|
|
KEY_TYPE current = keys[pos];
|
|
|
|
if(KEY_EQUALS_NULL(current)) return false;
|
|
|
|
if(EQUALS_KEY_TYPE(current, o)) return true;
|
|
|
|
while(true) {
|
|
|
|
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
|
|
|
else if(EQUALS_KEY_TYPE(current, o)) return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean remove(Object o) {
|
|
|
|
#if TYPE_OBJECT
|
|
|
|
if(o == null) return (containsNull ? removeNullIndex() : false);
|
|
|
|
#else
|
|
|
|
if(o == null) return false;
|
|
|
|
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return (containsNull ? removeNullIndex() : false);
|
|
|
|
#endif
|
|
|
|
int pos = HashUtil.mix(o.hashCode()) & mask;
|
|
|
|
KEY_TYPE current = keys[pos];
|
|
|
|
if(KEY_EQUALS_NULL(current)) return false;
|
|
|
|
if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos);
|
|
|
|
while(true) {
|
|
|
|
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
|
|
|
else if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !TYPE_OBJECT
|
|
|
|
@Override
|
|
|
|
public boolean contains(KEY_TYPE o) {
|
|
|
|
if(KEY_EQUALS_NULL(o)) return containsNull;
|
|
|
|
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
|
|
|
KEY_TYPE current = keys[pos];
|
|
|
|
if(KEY_EQUALS_NULL(current)) return false;
|
|
|
|
if(KEY_EQUALS(current, o)) return true;
|
|
|
|
while(true) {
|
|
|
|
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
|
|
|
else if(KEY_EQUALS(current, o)) return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean REMOVE_KEY(KEY_TYPE o) {
|
|
|
|
if(KEY_EQUALS_NULL(o)) return containsNull ? removeNullIndex() : false;
|
|
|
|
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
|
|
|
KEY_TYPE current = keys[pos];
|
|
|
|
if(KEY_EQUALS_NULL(current)) return false;
|
|
|
|
if(KEY_EQUALS(current, o)) return removeIndex(pos);
|
|
|
|
while(true) {
|
|
|
|
if(KEY_EQUALS_NULL((current = keys[pos = (++pos & mask)]))) return false;
|
|
|
|
else if(KEY_EQUALS(current, o)) return removeIndex(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
protected boolean removeIndex(int pos) {
|
|
|
|
if(pos == nullIndex) return containsNull ? removeNullIndex() : false;
|
|
|
|
keys[pos] = EMPTY_KEY_VALUE;
|
|
|
|
size--;
|
|
|
|
shiftKeys(pos);
|
|
|
|
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean removeNullIndex() {
|
|
|
|
containsNull = false;
|
|
|
|
keys[nullIndex] = EMPTY_KEY_VALUE;
|
|
|
|
size--;
|
|
|
|
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
|
|
|
return new SetIterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
|
|
|
if(size() <= 0) return;
|
|
|
|
if(containsNull) action.accept(keys[nullIndex]);
|
|
|
|
for(int i = nullIndex-1;i>=0;i--) {
|
|
|
|
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DistinctCollectionWrapper KEY_GENERIC_TYPE copy() {
|
|
|
|
DistinctCollectionWrapper KEY_GENERIC_TYPE set = new DistinctCollectionWrapperBRACES(0);
|
|
|
|
set.minCapacity = minCapacity;
|
|
|
|
set.mask = mask;
|
|
|
|
set.maxFill = maxFill;
|
|
|
|
set.nullIndex = nullIndex;
|
|
|
|
set.containsNull = containsNull;
|
|
|
|
set.size = size;
|
|
|
|
set.keys = Arrays.copyOf(keys, keys.length);
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void shiftKeys(int startPos) {
|
|
|
|
int slot, last;
|
|
|
|
KEY_TYPE current;
|
|
|
|
while(true) {
|
|
|
|
startPos = ((last = startPos) + 1) & mask;
|
|
|
|
while(true){
|
|
|
|
if(KEY_EQUALS_NULL((current = keys[startPos]))) {
|
|
|
|
keys[last] = EMPTY_KEY_VALUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
slot = HashUtil.mix(KEY_TO_HASH(current)) & mask;
|
|
|
|
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
|
|
|
startPos = ++startPos & mask;
|
|
|
|
}
|
|
|
|
keys[last] = current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void rehash(int newSize) {
|
|
|
|
int newMask = newSize - 1;
|
|
|
|
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
|
|
|
|
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
|
|
|
|
while(true) {
|
|
|
|
if(--i < 0) throw new ConcurrentModificationException("Set was modified during rehash");
|
|
|
|
if(KEY_EQUALS_NOT_NULL(keys[i])) break;
|
|
|
|
}
|
|
|
|
if(KEY_EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask]))
|
|
|
|
while(KEY_EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)]));
|
|
|
|
newKeys[pos] = keys[i];
|
|
|
|
}
|
|
|
|
nullIndex = newSize;
|
|
|
|
mask = newMask;
|
|
|
|
maxFill = Math.min((int)Math.ceil(nullIndex * HashUtil.DEFAULT_LOAD_FACTOR), nullIndex - 1);
|
|
|
|
keys = newKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clear() {
|
|
|
|
if(size == 0) return;
|
|
|
|
size = 0;
|
|
|
|
containsNull = false;
|
|
|
|
Arrays.fill(keys, EMPTY_KEY_VALUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int size() {
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
|
|
|
int pos = nullIndex;
|
|
|
|
int returnedPos = -1;
|
|
|
|
int lastReturned = -1;
|
|
|
|
int nextIndex = Integer.MIN_VALUE;
|
|
|
|
boolean returnNull = containsNull;
|
|
|
|
KEY_TYPE[] wrapped = null;
|
|
|
|
int wrappedIndex = 0;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() {
|
|
|
|
if(nextIndex == Integer.MIN_VALUE) {
|
|
|
|
if(returnNull) {
|
|
|
|
returnNull = false;
|
|
|
|
nextIndex = nullIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(true) {
|
|
|
|
if(--pos < 0) {
|
|
|
|
if(wrapped == null || wrappedIndex <= -pos - 1) break;
|
|
|
|
nextIndex = -pos - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(KEY_EQUALS_NOT_NULL(keys[pos])){
|
|
|
|
nextIndex = pos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nextIndex != Integer.MIN_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() {
|
|
|
|
if(!hasNext()) throw new NoSuchElementException();
|
|
|
|
returnedPos = pos;
|
|
|
|
if(nextIndex < 0){
|
|
|
|
lastReturned = Integer.MAX_VALUE;
|
|
|
|
KEY_TYPE value = wrapped[nextIndex];
|
|
|
|
nextIndex = Integer.MIN_VALUE;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
KEY_TYPE value = keys[(lastReturned = nextIndex)];
|
|
|
|
nextIndex = Integer.MIN_VALUE;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove() {
|
|
|
|
if(lastReturned == -1) throw new IllegalStateException();
|
|
|
|
if(lastReturned == nullIndex) {
|
|
|
|
containsNull = false;
|
|
|
|
keys[nullIndex] = EMPTY_KEY_VALUE;
|
|
|
|
}
|
|
|
|
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
|
|
|
else {
|
|
|
|
#if TYPE_OBJECT
|
|
|
|
DistinctCollectionWrapper.this.remove(wrapped[-returnedPos - 1]);
|
|
|
|
#else
|
|
|
|
DistinctCollectionWrapper.this.REMOVE_KEY(wrapped[-returnedPos - 1]);
|
|
|
|
#endif
|
|
|
|
lastReturned = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size--;
|
|
|
|
lastReturned = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void shiftKeys(int startPos) {
|
|
|
|
int slot, last;
|
|
|
|
KEY_TYPE current;
|
|
|
|
while(true) {
|
|
|
|
startPos = ((last = startPos) + 1) & mask;
|
|
|
|
while(true){
|
|
|
|
if(KEY_EQUALS_NULL((current = keys[startPos]))) {
|
|
|
|
keys[last] = EMPTY_KEY_VALUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
slot = HashUtil.mix(KEY_TO_HASH(current)) & mask;
|
|
|
|
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
|
|
|
startPos = ++startPos & mask;
|
|
|
|
}
|
|
|
|
if(startPos < last) addWrapper(keys[startPos]);
|
|
|
|
keys[last] = current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addWrapper(KEY_TYPE value) {
|
|
|
|
if(wrapped == null) wrapped = NEW_KEY_ARRAY(2);
|
|
|
|
else if(wrappedIndex >= wrapped.length) {
|
|
|
|
KEY_TYPE[] newArray = NEW_KEY_ARRAY(wrapped.length * 2);
|
|
|
|
System.arraycopy(wrapped, 0, newArray, 0, wrapped.length);
|
|
|
|
wrapped = newArray;
|
|
|
|
}
|
|
|
|
wrapped[wrappedIndex++] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2022-12-05 07:10:53 +01:00
|
|
|
private static class SingletonCollection KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE
|
|
|
|
{
|
|
|
|
KEY_TYPE element;
|
|
|
|
|
|
|
|
SingletonCollection(KEY_TYPE element) {
|
|
|
|
this.element = element;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !TYPE_OBJECT
|
|
|
|
@Override
|
|
|
|
public boolean REMOVE_KEY(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
|
|
#endif
|
|
|
|
@Override
|
|
|
|
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
|
|
@Override
|
|
|
|
public ITERATOR KEY_GENERIC_TYPE iterator()
|
|
|
|
{
|
|
|
|
return new ITERATOR KEY_GENERIC_TYPE() {
|
|
|
|
boolean next = true;
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() { return next; }
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() {
|
|
|
|
if(!hasNext()) throw new NoSuchElementException();
|
|
|
|
next = false;
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2022-12-08 10:40:21 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (o == this)
|
|
|
|
return true;
|
|
|
|
if (!(o instanceof Collection))
|
|
|
|
return false;
|
|
|
|
Collection<?> l = (Collection<?>)o;
|
|
|
|
if(l.size() != size()) return false;
|
|
|
|
Iterator<?> iter = l.iterator();
|
|
|
|
if (iter.hasNext() && !Objects.equals(element, iter.next())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !iter.hasNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return KEY_TO_HASH(element);
|
|
|
|
}
|
|
|
|
|
2022-12-05 07:10:53 +01:00
|
|
|
@Override
|
|
|
|
public int size() { return 1; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SingletonCollection KEY_GENERIC_TYPE copy() { return new SingletonCollectionBRACES(element); }
|
|
|
|
}
|
|
|
|
|
2021-04-26 22:25:09 +02:00
|
|
|
/**
|
|
|
|
* Synchronized Collection Wrapper for the synchronizedCollection function
|
|
|
|
* @Type(T)
|
|
|
|
*/
|
2020-12-01 02:43:13 +01:00
|
|
|
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); } }
|
2021-09-28 03:23:21 +02:00
|
|
|
@Override
|
|
|
|
public boolean addAll(KEY_TYPE[] e, int offset, int length) { synchronized(mutex) { return c.addAll(e, offset, length); } }
|
2020-12-01 02:43:13 +01:00
|
|
|
#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
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2020-12-01 02:43:13 +01:00
|
|
|
public boolean containsAll(Collection<?> c) { synchronized(mutex) { return this.c.containsAll(c); } }
|
|
|
|
|
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2020-12-01 02:43:13 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:48:37 +02:00
|
|
|
@Override
|
2021-12-09 09:14:55 +01:00
|
|
|
public COLLECTION KEY_GENERIC_TYPE copy() { synchronized(mutex) { return c.copy(); } }
|
2021-10-06 17:48:37 +02:00
|
|
|
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
|
|
|
@Primitive
|
|
|
|
public boolean remove(Object o) { synchronized(mutex) { return c.remove(o); } }
|
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2020-12-01 02:43:13 +01:00
|
|
|
public boolean removeAll(Collection<?> c) { synchronized(mutex) { return this.c.removeAll(c); } }
|
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2020-12-01 02:43:13 +01:00
|
|
|
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
|
2021-10-24 01:11:11 +02:00
|
|
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { synchronized(mutex) { return this.c.removeAll(c, r); } }
|
|
|
|
@Override
|
2020-12-01 02:43:13 +01:00
|
|
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.retainAll(c); } }
|
2021-10-24 01:11:11 +02:00
|
|
|
@Override
|
|
|
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { synchronized(mutex) { return this.c.retainAll(c, r); } }
|
2020-12-01 02:43:13 +01:00
|
|
|
#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); } }
|
2021-09-13 17:02:24 +02:00
|
|
|
@Override
|
|
|
|
public void forEach(CONSUMER action) { synchronized(mutex) { c.forEach(action); } }
|
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
public void forEach(Consumer<? super CLASS_TYPE> action) { synchronized(mutex) { c.forEach(action); } }
|
2020-12-01 02:43:13 +01:00
|
|
|
#else
|
|
|
|
@Override
|
|
|
|
public <E> E[] toArray(E[] a) { synchronized(mutex) { return c.toArray(a); } }
|
2021-09-13 17:02:24 +02:00
|
|
|
@Override
|
|
|
|
public void forEach(Consumer<? super CLASS_TYPE> action) { synchronized(mutex) { c.forEach(action); } }
|
2020-12-01 02:43:13 +01:00
|
|
|
#endif
|
2021-09-13 17:02:24 +02:00
|
|
|
@Override
|
|
|
|
public int hashCode() { synchronized(mutex) { return c.hashCode(); } }
|
2022-06-02 16:21:48 +02:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if(obj == this) return true;
|
|
|
|
synchronized(mutex) { return c.equals(obj); }
|
|
|
|
}
|
2021-09-13 17:02:24 +02:00
|
|
|
@Override
|
|
|
|
public String toString() { synchronized(mutex) { return c.toString(); } }
|
2021-10-07 14:50:52 +02:00
|
|
|
@Override
|
|
|
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { synchronized(mutex) { c.forEach(input, action); } }
|
|
|
|
@Override
|
|
|
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAny(filter); } }
|
|
|
|
@Override
|
|
|
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesNone(filter); } }
|
|
|
|
@Override
|
|
|
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAll(filter); } }
|
2021-10-29 16:03:39 +02:00
|
|
|
#if TYPE_OBJECT
|
|
|
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
|
|
|
|
#else
|
2021-10-07 14:50:52 +02:00
|
|
|
@Override
|
2021-10-27 14:09:19 +02:00
|
|
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
|
2021-10-29 16:03:39 +02:00
|
|
|
#endif
|
2021-10-27 14:09:19 +02:00
|
|
|
@Override
|
|
|
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(operator); } }
|
|
|
|
@Override
|
2021-10-29 16:03:39 +02:00
|
|
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
|
|
|
|
@Override
|
2021-10-07 14:50:52 +02:00
|
|
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } }
|
2020-12-01 02:43:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-26 22:25:09 +02:00
|
|
|
/**
|
|
|
|
* Unmodifyable Collection Wrapper for the unmodifyableCollection method
|
|
|
|
* @Type(T)
|
|
|
|
*/
|
2020-12-01 02:43:13 +01:00
|
|
|
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(); }
|
2021-09-28 03:23:21 +02:00
|
|
|
@Override
|
|
|
|
public boolean addAll(KEY_TYPE[] e, int offset, int length) { throw new UnsupportedOperationException(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
#if !TYPE_OBJECT
|
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean contains(KEY_TYPE o) { return c.contains(o); }
|
2020-12-01 02:43:13 +01:00
|
|
|
#else
|
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean contains(Object o) { return c.contains(o); }
|
2020-12-01 02:43:13 +01:00
|
|
|
#endif
|
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return this.c.containsAll(c); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { return this.c.containsAny(c); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean containsAny(Collection<?> c) { return this.c.containsAny(c); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean containsAll(Collection<?> c) { return this.c.containsAll(c); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public int size() { return c.size(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean isEmpty() { return c.isEmpty(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(c.iterator()); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-12-09 09:14:55 +01:00
|
|
|
public COLLECTION KEY_GENERIC_TYPE copy() { return c.copy(); }
|
2021-10-06 17:48:37 +02:00
|
|
|
@Override
|
2020-12-01 02:43:13 +01:00
|
|
|
@Deprecated
|
|
|
|
public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2020-12-01 02:43:13 +01:00
|
|
|
public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2020-12-01 02:43:13 +01:00
|
|
|
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
|
2021-10-24 01:11:11 +02:00
|
|
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
|
|
|
@Override
|
2020-12-01 02:43:13 +01:00
|
|
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
2021-10-24 01:11:11 +02:00
|
|
|
@Override
|
|
|
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
#if PRIMITIVES
|
|
|
|
@Override
|
|
|
|
public boolean remIf(JAVA_PREDICATE filter){ throw new UnsupportedOperationException(); }
|
|
|
|
#endif
|
|
|
|
@Override
|
|
|
|
public void clear() { throw new UnsupportedOperationException(); }
|
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public Object[] toArray() { return c.toArray(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
#if !TYPE_OBJECT
|
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public <T> T[] toArray(T[] a) { return c.toArray(a); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public KEY_TYPE[] TO_ARRAY() { return c.TO_ARRAY(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { return c.TO_ARRAY(a); }
|
|
|
|
@Override
|
|
|
|
public void forEach(CONSUMER action) { c.forEach(action); }
|
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
public void forEach(Consumer<? super CLASS_TYPE> action) { c.forEach(action); }
|
2020-12-01 02:43:13 +01:00
|
|
|
#else
|
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public <E> E[] toArray(E[] a) { return c.toArray(a); }
|
|
|
|
@Override
|
|
|
|
public void forEach(Consumer<? super CLASS_TYPE> action) { c.forEach(action); }
|
2020-12-01 02:43:13 +01:00
|
|
|
#endif
|
2021-09-13 17:02:24 +02:00
|
|
|
@Override
|
|
|
|
public int hashCode() { return c.hashCode(); }
|
2022-06-02 16:21:48 +02:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) { return obj == this || c.equals(obj); }
|
2021-09-13 17:02:24 +02:00
|
|
|
@Override
|
|
|
|
public String toString() { return c.toString(); }
|
2021-10-07 14:50:52 +02:00
|
|
|
@Override
|
|
|
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { c.forEach(input, action); }
|
|
|
|
@Override
|
|
|
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAny(filter); }
|
|
|
|
@Override
|
|
|
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesNone(filter); }
|
|
|
|
@Override
|
|
|
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAll(filter); }
|
2021-10-29 16:03:39 +02:00
|
|
|
#if TYPE_OBJECT
|
|
|
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) { return c.reduce(identity, operator); }
|
|
|
|
#else
|
2021-10-07 14:50:52 +02:00
|
|
|
@Override
|
2021-10-27 14:09:19 +02:00
|
|
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(identity, operator); }
|
2021-10-29 16:03:39 +02:00
|
|
|
#endif
|
2021-10-27 14:09:19 +02:00
|
|
|
@Override
|
|
|
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(operator); }
|
|
|
|
@Override
|
2021-10-29 16:03:39 +02:00
|
|
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
|
|
|
|
@Override
|
2021-10-07 14:50:52 +02:00
|
|
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) { return c.count(filter); }
|
2020-12-01 02:43:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-26 22:25:09 +02:00
|
|
|
/**
|
|
|
|
* Empty Collection implementation for the empty collection function
|
|
|
|
* @Type(T)
|
|
|
|
*/
|
2020-12-01 02:43:13 +01:00
|
|
|
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(); }
|
2021-09-28 03:23:21 +02:00
|
|
|
@Override
|
|
|
|
public boolean addAll(KEY_TYPE[] e, int offset, int length) { throw new UnsupportedOperationException(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
|
|
|
|
#if !TYPE_OBJECT
|
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean contains(KEY_TYPE o) { return false; }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2022-06-02 11:02:19 +02:00
|
|
|
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return c.isEmpty(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { return false; }
|
2020-12-01 02:43:13 +01:00
|
|
|
#else
|
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean contains(Object o) { return false; }
|
2020-12-01 02:43:13 +01:00
|
|
|
#endif
|
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2021-09-13 17:02:24 +02:00
|
|
|
public boolean containsAny(Collection<?> c) { return false; }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2022-06-02 11:02:19 +02:00
|
|
|
public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public int hashCode() { return 0; }
|
2020-12-01 02:43:13 +01:00
|
|
|
|
|
|
|
@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
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2020-12-01 02:43:13 +01:00
|
|
|
public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
|
|
|
@Override
|
2020-12-06 09:32:22 +01:00
|
|
|
@Primitive
|
2020-12-01 02:43:13 +01:00
|
|
|
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
|
2021-09-13 17:02:24 +02:00
|
|
|
public Object[] toArray() { return ObjectArrays.EMPTY_ARRAY; }
|
2020-12-01 02:43:13 +01:00
|
|
|
#if !TYPE_OBJECT
|
|
|
|
@Override
|
2022-06-02 11:02:19 +02:00
|
|
|
public <T> T[] toArray(T[] a) {
|
|
|
|
if(a != null && a.length > 0)
|
|
|
|
a[0] = null;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public KEY_TYPE[] TO_ARRAY() { return ARRAYS.EMPTY_ARRAY; }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2022-06-02 11:02:19 +02:00
|
|
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
|
|
|
if(a != null && a.length > 0)
|
|
|
|
a[0] = EMPTY_KEY_VALUE;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2021-09-13 17:02:24 +02:00
|
|
|
#else
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2022-06-02 11:02:19 +02:00
|
|
|
public <E> E[] toArray(E[] a) {
|
|
|
|
if(a != null && a.length > 0)
|
|
|
|
a[0] = EMPTY_KEY_VALUE;
|
|
|
|
return a;
|
|
|
|
}
|
2020-12-01 02:43:13 +01:00
|
|
|
#endif
|
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.empty(); }
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public void clear() {}
|
2020-12-01 02:43:13 +01:00
|
|
|
@Override
|
2021-09-13 17:02:24 +02:00
|
|
|
public int size() { return 0; }
|
2021-10-06 17:48:37 +02:00
|
|
|
@Override
|
|
|
|
public EmptyCollection KEY_GENERIC_TYPE copy() { return this; }
|
2020-12-01 02:43:13 +01:00
|
|
|
}
|
2021-09-13 17:02:24 +02:00
|
|
|
}
|