Small Fixes to doc and Useless Imports
This commit is contained in:
+265
-265
@@ -1,266 +1,266 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
|
||||
/**
|
||||
* Abstract Type Specific Collection that reduces boxing/unboxing
|
||||
* @Type(T)
|
||||
*/
|
||||
public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractCollection<CLASS_TYPE> implements COLLECTION KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean add(CLASS_TYPE e) { return COLLECTION.super.add(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();modified |= add(iter.NEXT()));
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) { return COLLECTION.super.contains(e); }
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of contains. This implementation iterates over the elements and returns true if the value match.
|
||||
* @param e the element that should be searched for.
|
||||
* @return true if the value was found.
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(KEY_EQUALS(iter.NEXT(), e)) return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean addAll(Collection<? extends CLASS_TYPE> c)
|
||||
{
|
||||
return c instanceof COLLECTION ? addAll((COLLECTION KEY_GENERIC_TYPE)c) : super.addAll(c);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
|
||||
* @param c the collection that should be checked if it contains all elements.
|
||||
* @return true if all elements were found in the collection
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return true;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
if(!contains(iter.NEXT()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
Objects.requireNonNull(c);
|
||||
return c instanceof COLLECTION ? containsAll((COLLECTION KEY_GENERIC_TYPE)c) : super.containsAll(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
||||
* @param c the elements that should be checked for
|
||||
* @return true if any element is in this collection
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
@Primitive
|
||||
public boolean containsAny(Collection<?> c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
for(Object e : c)
|
||||
if(contains(e))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection.
|
||||
* @param c the elements that should be checked for
|
||||
* @return true if any element is in this collection
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
if(contains(iter.NEXT()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean remove(Object e) { return COLLECTION.super.remove(e); }
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of remove. This implementation iterates over the elements until it finds the element that is searched for or it runs out of elements.
|
||||
* It stops after finding the first element
|
||||
* @param e the element that is searched for
|
||||
* @return true if the element was found and removed.
|
||||
*/
|
||||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(KEY_EQUALS(iter.NEXT(), e)) {
|
||||
iter.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific implementation of removeAll. This Implementation iterates over all elements and removes them as they were found in the other collection.
|
||||
* @param c the elements that should be deleted
|
||||
* @return true if the collection was modified.
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(c.contains(iter.NEXT())) {
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
Objects.requireNonNull(r);
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE e = iter.NEXT();
|
||||
if(c.contains(e)) {
|
||||
r.accept(e);
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
|
||||
* @param c the elements that should be kept
|
||||
* @return true if the collection was modified.
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) {
|
||||
boolean modified = !isEmpty();
|
||||
clear();
|
||||
return modified;
|
||||
}
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(!c.contains(iter.NEXT())) {
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
Objects.requireNonNull(c);
|
||||
Objects.requireNonNull(r);
|
||||
if(c.isEmpty()) {
|
||||
boolean modified = !isEmpty();
|
||||
forEach(r);
|
||||
clear();
|
||||
return modified;
|
||||
}
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE e = iter.NEXT();
|
||||
if(!c.contains(e)) {
|
||||
r.accept(e);
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific implementation of toArray that links to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||
* @return an array containing all of the elements in this collection
|
||||
*/
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY() {
|
||||
if(isEmpty()) return ARRAYS.EMPTY_ARRAY;
|
||||
return TO_ARRAY(new KEY_TYPE[size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of toArray. This implementation iterates over all elements and unwraps them into primitive type.
|
||||
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
||||
* @return an array containing all of the elements in this collection
|
||||
*/
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
ITERATORS.unwrap(a, iterator());
|
||||
if (a.length > size()) a[size()] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Abstract Type Specific Collection that reduces boxing/unboxing
|
||||
* @Type(T)
|
||||
*/
|
||||
public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractCollection<CLASS_TYPE> implements COLLECTION KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean add(CLASS_TYPE e) { return COLLECTION.super.add(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();modified |= add(iter.NEXT()));
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) { return COLLECTION.super.contains(e); }
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of contains. This implementation iterates over the elements and returns true if the value match.
|
||||
* @param e the element that should be searched for.
|
||||
* @return true if the value was found.
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(KEY_EQUALS(iter.NEXT(), e)) return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean addAll(Collection<? extends CLASS_TYPE> c)
|
||||
{
|
||||
return c instanceof COLLECTION ? addAll((COLLECTION KEY_GENERIC_TYPE)c) : super.addAll(c);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
|
||||
* @param c the collection that should be checked if it contains all elements.
|
||||
* @return true if all elements were found in the collection
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return true;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
if(!contains(iter.NEXT()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
Objects.requireNonNull(c);
|
||||
return c instanceof COLLECTION ? containsAll((COLLECTION KEY_GENERIC_TYPE)c) : super.containsAll(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
||||
* @param c the elements that should be checked for
|
||||
* @return true if any element is in this collection
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
@Primitive
|
||||
public boolean containsAny(Collection<?> c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
for(Object e : c)
|
||||
if(contains(e))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection.
|
||||
* @param c the elements that should be checked for
|
||||
* @return true if any element is in this collection
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
if(contains(iter.NEXT()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean remove(Object e) { return COLLECTION.super.remove(e); }
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of remove. This implementation iterates over the elements until it finds the element that is searched for or it runs out of elements.
|
||||
* It stops after finding the first element
|
||||
* @param e the element that is searched for
|
||||
* @return true if the element was found and removed.
|
||||
*/
|
||||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(KEY_EQUALS(iter.NEXT(), e)) {
|
||||
iter.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific implementation of removeAll. This Implementation iterates over all elements and removes them as they were found in the other collection.
|
||||
* @param c the elements that should be deleted
|
||||
* @return true if the collection was modified.
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(c.contains(iter.NEXT())) {
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) return false;
|
||||
Objects.requireNonNull(r);
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE e = iter.NEXT();
|
||||
if(c.contains(e)) {
|
||||
r.accept(e);
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
|
||||
* @param c the elements that should be kept
|
||||
* @return true if the collection was modified.
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
Objects.requireNonNull(c);
|
||||
if(c.isEmpty()) {
|
||||
boolean modified = !isEmpty();
|
||||
clear();
|
||||
return modified;
|
||||
}
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(!c.contains(iter.NEXT())) {
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||
Objects.requireNonNull(c);
|
||||
Objects.requireNonNull(r);
|
||||
if(c.isEmpty()) {
|
||||
boolean modified = !isEmpty();
|
||||
forEach(r);
|
||||
clear();
|
||||
return modified;
|
||||
}
|
||||
boolean modified = false;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE e = iter.NEXT();
|
||||
if(!c.contains(e)) {
|
||||
r.accept(e);
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific implementation of toArray that links to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||
* @return an array containing all of the elements in this collection
|
||||
*/
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY() {
|
||||
if(isEmpty()) return ARRAYS.EMPTY_ARRAY;
|
||||
return TO_ARRAY(new KEY_TYPE[size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type-Specific implementation of toArray. This implementation iterates over all elements and unwraps them into primitive type.
|
||||
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
||||
* @return an array containing all of the elements in this collection
|
||||
*/
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
ITERATORS.unwrap(a, iterator());
|
||||
if (a.length > size()) a[size()] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+322
-321
@@ -1,322 +1,323 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
#if PRIMITIVES
|
||||
import java.util.Objects;
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
import java.util.function.Predicate;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntFunction;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
* A Type-Specific {@link Collection} that reduces (un)boxing
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific add function to reduce (un)boxing
|
||||
* @param o the element that should be added
|
||||
* @return true if the element was added to the collection
|
||||
*/
|
||||
public boolean add(KEY_TYPE o);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific addAll function to reduce (un)boxing
|
||||
* @param c the collection of elements that should be added
|
||||
* @return true if elements were added into the collection
|
||||
*/
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||
* @param e the elements that should be added
|
||||
* @return if the collection was modified
|
||||
*/
|
||||
public default boolean addAll(KEY_TYPE... e) { return addAll(e, 0, e.length); }
|
||||
|
||||
/**
|
||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||
* @param e the elements that should be added
|
||||
* @param length how many elements of the array should be added
|
||||
* @return if the collection was modified
|
||||
*/
|
||||
public default boolean addAll(KEY_TYPE[] e, int length) { return addAll(e, 0, length); }
|
||||
|
||||
/**
|
||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||
* @param e the elements that should be added
|
||||
* @param offset where to start within the array
|
||||
* @param length how many elements of the array should be added
|
||||
* @return if the collection was modified
|
||||
*/
|
||||
public default boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
||||
if(length <= 0) return false;
|
||||
SanityChecks.checkArrayCapacity(e.length, offset, length);
|
||||
boolean added = false;
|
||||
for(int i = 0;i<length;i++) {
|
||||
if(add(e[offset+i])) added = true;
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific contains function to reduce (un)boxing
|
||||
* @param o the element that is checked for
|
||||
* @return true if the element is found in the collection
|
||||
*/
|
||||
public boolean contains(KEY_TYPE o);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific containsAll function to reduce (un)boxing
|
||||
* @param c the collection of elements that should be tested for
|
||||
* @return true if all the element is found in the collection
|
||||
*/
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific containsAny function to reduce (un)boxing
|
||||
* @param c the collection of elements that should be tested for
|
||||
* @return true if any element was found
|
||||
*/
|
||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* Returns true if any element of the Collection is found in the provided collection.
|
||||
* A Small Optimization function to find out of any element is present when comparing collections and not all of them.
|
||||
* @param c the collection of elements that should be tested for
|
||||
* @return true if any element was found.
|
||||
*/
|
||||
@Primitive
|
||||
public boolean containsAny(Collection<?> c);
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific remove function that reduces (un)boxing.
|
||||
* @param o the element that should be removed
|
||||
* @return true if the element was removed
|
||||
* @see Collection#remove(Object)
|
||||
*/
|
||||
public boolean REMOVE_KEY(KEY_TYPE o);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||
* @param c the collection of elements that should be removed
|
||||
* @return true if any element was removed
|
||||
* @see Collection#removeAll(Collection)
|
||||
*/
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||
* It also notifies the remover of which exact element is going to be removed.
|
||||
* @param c the collection of elements that should be removed
|
||||
* @param r elements that got removed
|
||||
* @return true if any element was removed
|
||||
* @see Collection#removeAll(Collection)
|
||||
*/
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||
|
||||
/**
|
||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||
* @param c the collection of elements that should be kept
|
||||
* @return true if any element was removed
|
||||
* @see Collection#retainAll(Collection)
|
||||
*/
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||
* It also notifies the remover of which exact element is going to be removed.
|
||||
* @param c the collection of elements that should be kept
|
||||
* @param r elements that got removed
|
||||
* @return true if any element was removed
|
||||
* @see Collection#retainAll(Collection)
|
||||
*/
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||
* @param collection that the elements should be inserted to
|
||||
* @param <E> the collection type
|
||||
* @return the input with the desired elements
|
||||
*/
|
||||
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||
collection.addAll(this);
|
||||
return collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Function that does a shallow clone of the Collection itself.
|
||||
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
||||
* It can be compared to Cloneable but with less exception risk
|
||||
* @return a Shallow Copy of the collection
|
||||
* @note Wrappers and view collections will not support this feature
|
||||
*/
|
||||
public COLLECTION KEY_GENERIC_TYPE copy();
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that simplifies the process of creating a new Array.
|
||||
* @param action the array creation function
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray(Object[])
|
||||
*/
|
||||
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||
return TO_ARRAY(action.apply(size()));
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray()
|
||||
*/
|
||||
public KEY_TYPE[] TO_ARRAY();
|
||||
|
||||
/**
|
||||
* A Type-Specific toArray function that reduces (un)boxing.
|
||||
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray(Object[])
|
||||
*/
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a);
|
||||
|
||||
#if PRIMITIVES
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||
return remIf(v -> filter.test(KEY_TO_OBJ(SanityChecks.SANITY_CAST(v))));
|
||||
#else
|
||||
return remIf(v -> filter.test(KEY_TO_OBJ(v)));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type-Specific removeIf function to reduce (un)boxing.
|
||||
* <p>Removes elements that were selected by the filter
|
||||
* @see Collection#removeIf(Predicate)
|
||||
* @param filter Filters the elements that should be removed
|
||||
* @return true if the collection was modified
|
||||
* @throws java.lang.NullPointerException if filter is null
|
||||
*/
|
||||
public default boolean remIf(JAVA_PREDICATE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
boolean removed = false;
|
||||
final ITERATOR each = iterator();
|
||||
while (each.hasNext()) {
|
||||
if (filter.test(each.NEXT())) {
|
||||
each.remove();
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
#endif
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(CLASS_TYPE o) { return add(OBJ_TO_KEY(o)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) { return o != null && contains(CLASS_TO_KEY(o)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) { return o != null && REMOVE_KEY(CLASS_TO_KEY(o)); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Returns a Type-Specific Iterator to reduce (un)boxing
|
||||
* @return a iterator of the collection
|
||||
* @see Collection#iterator()
|
||||
*/
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Collection that is Synchronized
|
||||
* @return a new Collection that is synchronized
|
||||
* @see COLLECTIONS#synchronize
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE synchronize() { return COLLECTIONS.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Collection that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new Collection Wrapper that is synchronized
|
||||
* @see COLLECTIONS#synchronize
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE synchronize(Object mutex) { return COLLECTIONS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Collection that is unmodifiable
|
||||
* @return a new Collection Wrapper that is unmodifiable
|
||||
* @see COLLECTIONS#unmodifiable
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); }
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
* @return a Stream of the closest java type
|
||||
*/
|
||||
default JAVA_STREAM primitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), false); }
|
||||
|
||||
/**
|
||||
* Returns a Java-Type-Specific Parallel Stream to reduce boxing/unboxing.
|
||||
* @return a Stream of the closest java type
|
||||
*/
|
||||
default JAVA_STREAM parallelPrimitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), true); }
|
||||
|
||||
#endif
|
||||
#if STREAM_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
#endif
|
||||
#endif
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
#if PRIMITIVES
|
||||
import java.util.Objects;
|
||||
import java.util.function.JAVA_PREDICATE;
|
||||
import java.util.function.Predicate;
|
||||
#if SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntFunction;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
* A Type-Specific {@link Collection} that reduces (un)boxing
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific add function to reduce (un)boxing
|
||||
* @param o the element that should be added
|
||||
* @return true if the element was added to the collection
|
||||
*/
|
||||
public boolean add(KEY_TYPE o);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific addAll function to reduce (un)boxing
|
||||
* @param c the collection of elements that should be added
|
||||
* @return true if elements were added into the collection
|
||||
*/
|
||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||
* @param e the elements that should be added
|
||||
* @return if the collection was modified
|
||||
*/
|
||||
public default boolean addAll(KEY_TYPE... e) { return addAll(e, 0, e.length); }
|
||||
|
||||
/**
|
||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||
* @param e the elements that should be added
|
||||
* @param length how many elements of the array should be added
|
||||
* @return if the collection was modified
|
||||
*/
|
||||
public default boolean addAll(KEY_TYPE[] e, int length) { return addAll(e, 0, length); }
|
||||
|
||||
/**
|
||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||
* @param e the elements that should be added
|
||||
* @param offset where to start within the array
|
||||
* @param length how many elements of the array should be added
|
||||
* @return if the collection was modified
|
||||
*/
|
||||
public default boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
||||
if(length <= 0) return false;
|
||||
SanityChecks.checkArrayCapacity(e.length, offset, length);
|
||||
boolean added = false;
|
||||
for(int i = 0;i<length;i++) {
|
||||
if(add(e[offset+i])) added = true;
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific contains function to reduce (un)boxing
|
||||
* @param o the element that is checked for
|
||||
* @return true if the element is found in the collection
|
||||
*/
|
||||
public boolean contains(KEY_TYPE o);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific containsAll function to reduce (un)boxing
|
||||
* @param c the collection of elements that should be tested for
|
||||
* @return true if all the element is found in the collection
|
||||
*/
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific containsAny function to reduce (un)boxing
|
||||
* @param c the collection of elements that should be tested for
|
||||
* @return true if any element was found
|
||||
*/
|
||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* Returns true if any element of the Collection is found in the provided collection.
|
||||
* A Small Optimization function to find out of any element is present when comparing collections and not all of them.
|
||||
* @param c the collection of elements that should be tested for
|
||||
* @return true if any element was found.
|
||||
*/
|
||||
@Primitive
|
||||
public boolean containsAny(Collection<?> c);
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type-Specific remove function that reduces (un)boxing.
|
||||
* @param o the element that should be removed
|
||||
* @return true if the element was removed
|
||||
* @see Collection#remove(Object)
|
||||
*/
|
||||
public boolean REMOVE_KEY(KEY_TYPE o);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||
* @param c the collection of elements that should be removed
|
||||
* @return true if any element was removed
|
||||
* @see Collection#removeAll(Collection)
|
||||
*/
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||
* It also notifies the remover of which exact element is going to be removed.
|
||||
* @param c the collection of elements that should be removed
|
||||
* @param r elements that got removed
|
||||
* @return true if any element was removed
|
||||
* @see Collection#removeAll(Collection)
|
||||
*/
|
||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||
|
||||
/**
|
||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||
* @param c the collection of elements that should be kept
|
||||
* @return true if any element was removed
|
||||
* @see Collection#retainAll(Collection)
|
||||
*/
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||
* It also notifies the remover of which exact element is going to be removed.
|
||||
* @param c the collection of elements that should be kept
|
||||
* @param r elements that got removed
|
||||
* @return true if any element was removed
|
||||
* @see Collection#retainAll(Collection)
|
||||
*/
|
||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||
* @param collection that the elements should be inserted to
|
||||
* @param <E> the collection type
|
||||
* @return the input with the desired elements
|
||||
*/
|
||||
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||
collection.addAll(this);
|
||||
return collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Function that does a shallow clone of the Collection itself.
|
||||
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
||||
* It can be compared to Cloneable but with less exception risk
|
||||
* @return a Shallow Copy of the collection
|
||||
* @note Wrappers and view collections will not support this feature
|
||||
*/
|
||||
public COLLECTION KEY_GENERIC_TYPE copy();
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that simplifies the process of creating a new Array.
|
||||
* @param action the array creation function
|
||||
* @param <E> the returning arrayType
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray(Object[])
|
||||
*/
|
||||
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||
return TO_ARRAY(action.apply(size()));
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray()
|
||||
*/
|
||||
public KEY_TYPE[] TO_ARRAY();
|
||||
|
||||
/**
|
||||
* A Type-Specific toArray function that reduces (un)boxing.
|
||||
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray(Object[])
|
||||
*/
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a);
|
||||
|
||||
#if PRIMITIVES
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||
return remIf(v -> filter.test(KEY_TO_OBJ(SanityChecks.SANITY_CAST(v))));
|
||||
#else
|
||||
return remIf(v -> filter.test(KEY_TO_OBJ(v)));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type-Specific removeIf function to reduce (un)boxing.
|
||||
* <p>Removes elements that were selected by the filter
|
||||
* @see Collection#removeIf(Predicate)
|
||||
* @param filter Filters the elements that should be removed
|
||||
* @return true if the collection was modified
|
||||
* @throws java.lang.NullPointerException if filter is null
|
||||
*/
|
||||
public default boolean remIf(JAVA_PREDICATE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
boolean removed = false;
|
||||
final ITERATOR each = iterator();
|
||||
while (each.hasNext()) {
|
||||
if (filter.test(each.NEXT())) {
|
||||
each.remove();
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
#endif
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(CLASS_TYPE o) { return add(OBJ_TO_KEY(o)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) { return o != null && contains(CLASS_TO_KEY(o)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) { return o != null && REMOVE_KEY(CLASS_TO_KEY(o)); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Returns a Type-Specific Iterator to reduce (un)boxing
|
||||
* @return a iterator of the collection
|
||||
* @see Collection#iterator()
|
||||
*/
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Collection that is Synchronized
|
||||
* @return a new Collection that is synchronized
|
||||
* @see COLLECTIONS#synchronize
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE synchronize() { return COLLECTIONS.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Collection that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new Collection Wrapper that is synchronized
|
||||
* @see COLLECTIONS#synchronize
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE synchronize(Object mutex) { return COLLECTIONS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped Collection that is unmodifiable
|
||||
* @return a new Collection Wrapper that is unmodifiable
|
||||
* @see COLLECTIONS#unmodifiable
|
||||
*/
|
||||
public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); }
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
* @return a Stream of the closest java type
|
||||
*/
|
||||
default JAVA_STREAM primitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), false); }
|
||||
|
||||
/**
|
||||
* Returns a Java-Type-Specific Parallel Stream to reduce boxing/unboxing.
|
||||
* @return a Stream of the closest java type
|
||||
*/
|
||||
default JAVA_STREAM parallelPrimitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), true); }
|
||||
|
||||
#endif
|
||||
#if STREAM_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
+457
-456
@@ -1,457 +1,458 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
#else
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.Comparator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if ARRAY_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||
#endif
|
||||
#endif
|
||||
#if SET_MODULE && !TYPE_BOOLEAN
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if LINKED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_CUSTOM_HASH_SET;
|
||||
#else if SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||
#else if CUSTOM_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.CUSTOM_HASH_SET;
|
||||
#else if RB_TREE_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.RB_TREE_SET;
|
||||
#else if AVL_TREE_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.AVL_TREE_SET;
|
||||
#else if ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.ARRAY_SET;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#if ASYNC_MODULE
|
||||
import speiger.src.collections.PACKAGE.utils.ASYNC_BUILDER;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if !LINKED_HASH_SET_FEATURE && LINKED_CUSTOM_HASH_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
#endif
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
|
||||
/**
|
||||
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
{
|
||||
/**
|
||||
* Returns an iterator over elements of type {@code T}.
|
||||
*
|
||||
* @return an Iterator.
|
||||
*/
|
||||
@Override
|
||||
ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific foreach function that reduces (un)boxing
|
||||
*
|
||||
* @implSpec
|
||||
* <p>The default implementation behaves as if:
|
||||
* <pre>{@code
|
||||
* iterator().forEachRemaining(action);
|
||||
* }</pre>
|
||||
*
|
||||
* @param action The action to be performed for each element
|
||||
* @throws NullPointerException if the specified action is null
|
||||
* @see Iterable#forEach(Consumer)
|
||||
*/
|
||||
default void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterator().forEachRemaining(action);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
default void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterator().forEachRemaining(action);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
|
||||
* @param action The action to be performed for each element
|
||||
* @throws java.lang.NullPointerException if the specified action is null
|
||||
*/
|
||||
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();action.accept(index++, iter.NEXT()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
|
||||
* @param input the object that should be included
|
||||
* @param action The action to be performed for each element
|
||||
* @param <E> the generic type of the Object
|
||||
* @throws java.lang.NullPointerException if the specified action is null
|
||||
*/
|
||||
default <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterator().forEachRemaining(input, action);
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
|
||||
|
||||
#endif
|
||||
#if ASYNC_MODULE
|
||||
/**
|
||||
* Creates a Async Builder for moving work of the thread.
|
||||
* It is not designed to split the work to multithreaded work, so using this keep it singlethreaded, but it allows to be moved to another thread.
|
||||
* @see ASYNC_BUILDER
|
||||
* @return a AsyncBuilder
|
||||
*/
|
||||
default ASYNC_BUILDER KEY_GENERIC_TYPE asAsync() {
|
||||
return new ASYNC_BUILDERBRACES(this);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||
* @param mapper the mapping function
|
||||
* @param <E> The return type.
|
||||
* @return a new Iterable that returns the desired result
|
||||
*/
|
||||
default <E> ObjectIterable<E> map(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||
return ITERABLES.map(this, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||
* @param mapper the flatMapping function
|
||||
* @param <V> The return type supplier.
|
||||
* @param <E> The return type.
|
||||
* @return a new Iterable that returns the desired result
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||
return ITERABLES.flatMap(this, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||
* @param mapper the flatMapping function
|
||||
* @param <E> The return type.
|
||||
* @return a new Iterable that returns the desired result
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default <E> ObjectIterable<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||
return ITERABLES.arrayFlatMap(this, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
|
||||
* @param filter the elements that should be kept.
|
||||
* @return a Iterable that filtered out all unwanted elements
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
return ITERABLES.filter(this, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to filter out duplicated elements
|
||||
* @return a Iterable that filtered out all duplicated elements
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
||||
return ITERABLES.distinct(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to repeat elements a desired amount of times
|
||||
* @param repeats how many times the elements should be repeated
|
||||
* @return a Iterable that is repeating multiple times
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE repeat(int repeats) {
|
||||
return ITERABLES.repeat(this, repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to limit the amount of elements
|
||||
* @param limit the amount of elements it should be limited to
|
||||
* @return a Iterable that is limited in length
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE limit(long limit) {
|
||||
return ITERABLES.limit(this, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to sort the elements
|
||||
* @param sorter that sorts the elements.
|
||||
* @return a Iterable that is sorted
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return ITERABLES.sorted(this, sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to preview elements before they are iterated through
|
||||
* @param action the action that should be applied
|
||||
* @return a Peeked Iterable
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE peek(CONSUMER KEY_GENERIC_TYPE action) {
|
||||
return ITERABLES.peek(this, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||
* @param collection that the elements should be inserted to
|
||||
* @param <E> the collection type
|
||||
* @return the input with the desired elements
|
||||
*/
|
||||
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||
ITERATORS.pour(iterator(), collection);
|
||||
return collection;
|
||||
}
|
||||
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a ArrayList
|
||||
* @return a new ArrayList of all elements
|
||||
*/
|
||||
default LIST KEY_GENERIC_TYPE pourAsList() {
|
||||
#if ARRAY_LIST_FEATURE
|
||||
return pour(new ARRAY_LISTBRACES());
|
||||
#else
|
||||
return pour(new LINKED_LISTBRACES());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN && SET_MODULE
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a LinkedHashSet
|
||||
* @return a new LinkedHashSet of all elements
|
||||
*/
|
||||
default SET KEY_GENERIC_TYPE pourAsSet() {
|
||||
#if LINKED_SET_FEATURE
|
||||
return pour(new LINKED_HASH_SETBRACES());
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
return pour(new LINKED_CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||
#else if SET_FEATURE
|
||||
return pour(new HASH_SETBRACES());
|
||||
#else if CUSTOM_SET_FEATURE
|
||||
return pour(new CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||
#else if RB_TREE_SET_FEATURE
|
||||
return pour(new RB_Tree_SETBRACES());
|
||||
#else if AVL_TREE_SET_FEATURE
|
||||
return pour(new AVL_Tree_SETBRACES());
|
||||
#else if ARRAY_SET_FEATURE
|
||||
return pour(new ARRAY_SETBRACES());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a Array
|
||||
* @param action is the creator function of said Array to ensure type is kept.
|
||||
* @return a new Array of all elements
|
||||
*/
|
||||
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||
ISizeProvider prov = ISizeProvider.of(this);
|
||||
if(prov != null) {
|
||||
int size = prov.size();
|
||||
if(size >= 0) {
|
||||
E[] array = action.apply(size);
|
||||
ITERATORS.unwrap(array, iterator());
|
||||
return array;
|
||||
}
|
||||
}
|
||||
return ARRAYS.pour(iterator(), action);
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a Array
|
||||
* @return a new Array of all elements
|
||||
*/
|
||||
default KEY_TYPE[] TO_ARRAY() {
|
||||
ISizeProvider prov = ISizeProvider.of(this);
|
||||
if(prov != null) {
|
||||
int size = prov.size();
|
||||
if(size >= 0) {
|
||||
KEY_TYPE[] array = NEW_KEY_ARRAY(size);
|
||||
ITERATORS.unwrap(array, iterator());
|
||||
return array;
|
||||
}
|
||||
}
|
||||
return ARRAYS.pour(iterator());
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to filter for any matches.
|
||||
* @param filter that should be applied
|
||||
* @return true if any matches were found
|
||||
*/
|
||||
default boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.test(iter.NEXT())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to filter for no matches.
|
||||
* @param filter that should be applied
|
||||
* @return true if no matches were found
|
||||
*/
|
||||
default boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.test(iter.NEXT())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to filter for all matches.
|
||||
* @param filter that should be applied
|
||||
* @return true if all matches.
|
||||
*/
|
||||
default boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(!filter.test(iter.NEXT())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to filter for the first match.
|
||||
* @param filter that should be applied
|
||||
* @return the found value or the null equivalent variant.
|
||||
*/
|
||||
default KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE entry = iter.NEXT();
|
||||
if(filter.test(entry)) return entry;
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||
* elements of this Iterable
|
||||
* @param operator the operation that should be applied
|
||||
* @param identity the start value
|
||||
* @return the reduction result, returns identity if nothing was found
|
||||
*/
|
||||
default KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||
* elements of this Iterable
|
||||
* @param operator the operation that should be applied
|
||||
* @param identity the start value
|
||||
* @Type(E)
|
||||
* @return the reduction result, returns identity if nothing was found
|
||||
*/
|
||||
default <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||
* elements of this Iterable
|
||||
* @param operator the operation that should be applied
|
||||
* @return the reduction result, returns null value if nothing was found
|
||||
*/
|
||||
default KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = iter.NEXT();
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to count the valid elements.
|
||||
* @param filter that should be applied
|
||||
* @return the amount of Valid Elements
|
||||
*/
|
||||
default int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.test(iter.NEXT())) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
#else
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.Comparator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if ARRAY_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||
#endif
|
||||
#endif
|
||||
#if SET_MODULE && !TYPE_BOOLEAN
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if LINKED_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_CUSTOM_HASH_SET;
|
||||
#else if SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||
#else if CUSTOM_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.CUSTOM_HASH_SET;
|
||||
#else if RB_TREE_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.RB_TREE_SET;
|
||||
#else if AVL_TREE_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.AVL_TREE_SET;
|
||||
#else if ARRAY_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.sets.ARRAY_SET;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#if ASYNC_MODULE
|
||||
import speiger.src.collections.PACKAGE.utils.ASYNC_BUILDER;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#if !LINKED_HASH_SET_FEATURE && LINKED_CUSTOM_HASH_SET_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
#endif
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
|
||||
/**
|
||||
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
{
|
||||
/**
|
||||
* Returns an iterator over elements of type {@code T}.
|
||||
*
|
||||
* @return an Iterator.
|
||||
*/
|
||||
@Override
|
||||
ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific foreach function that reduces (un)boxing
|
||||
*
|
||||
* @implSpec
|
||||
* <p>The default implementation behaves as if:
|
||||
* <pre>{@code
|
||||
* iterator().forEachRemaining(action);
|
||||
* }</pre>
|
||||
*
|
||||
* @param action The action to be performed for each element
|
||||
* @throws NullPointerException if the specified action is null
|
||||
* @see Iterable#forEach(Consumer)
|
||||
*/
|
||||
default void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterator().forEachRemaining(action);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
default void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterator().forEachRemaining(action);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
|
||||
* @param action The action to be performed for each element
|
||||
* @throws java.lang.NullPointerException if the specified action is null
|
||||
*/
|
||||
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
int index = 0;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();action.accept(index++, iter.NEXT()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
|
||||
* @param input the object that should be included
|
||||
* @param action The action to be performed for each element
|
||||
* @param <E> the generic type of the Object
|
||||
* @throws java.lang.NullPointerException if the specified action is null
|
||||
*/
|
||||
default <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterator().forEachRemaining(input, action);
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
|
||||
|
||||
#endif
|
||||
#if ASYNC_MODULE
|
||||
/**
|
||||
* Creates a Async Builder for moving work of the thread.
|
||||
* It is not designed to split the work to multithreaded work, so using this keep it singlethreaded, but it allows to be moved to another thread.
|
||||
* @see ASYNC_BUILDER
|
||||
* @return a AsyncBuilder
|
||||
*/
|
||||
default ASYNC_BUILDER KEY_GENERIC_TYPE asAsync() {
|
||||
return new ASYNC_BUILDERBRACES(this);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||
* @param mapper the mapping function
|
||||
* @param <E> The return type.
|
||||
* @return a new Iterable that returns the desired result
|
||||
*/
|
||||
default <E> ObjectIterable<E> map(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||
return ITERABLES.map(this, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||
* @param mapper the flatMapping function
|
||||
* @param <V> The return type supplier.
|
||||
* @param <E> The return type.
|
||||
* @return a new Iterable that returns the desired result
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||
return ITERABLES.flatMap(this, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||
* @param mapper the flatMapping function
|
||||
* @param <E> The return type.
|
||||
* @return a new Iterable that returns the desired result
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default <E> ObjectIterable<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||
return ITERABLES.arrayFlatMap(this, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
|
||||
* @param filter the elements that should be kept.
|
||||
* @return a Iterable that filtered out all unwanted elements
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
return ITERABLES.filter(this, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to filter out duplicated elements
|
||||
* @return a Iterable that filtered out all duplicated elements
|
||||
* @note does not support TO_ARRAY optimizations.
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
||||
return ITERABLES.distinct(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to repeat elements a desired amount of times
|
||||
* @param repeats how many times the elements should be repeated
|
||||
* @return a Iterable that is repeating multiple times
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE repeat(int repeats) {
|
||||
return ITERABLES.repeat(this, repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to limit the amount of elements
|
||||
* @param limit the amount of elements it should be limited to
|
||||
* @return a Iterable that is limited in length
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE limit(long limit) {
|
||||
return ITERABLES.limit(this, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to sort the elements
|
||||
* @param sorter that sorts the elements.
|
||||
* @return a Iterable that is sorted
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return ITERABLES.sorted(this, sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to preview elements before they are iterated through
|
||||
* @param action the action that should be applied
|
||||
* @return a Peeked Iterable
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE peek(CONSUMER KEY_GENERIC_TYPE action) {
|
||||
return ITERABLES.peek(this, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||
* @param collection that the elements should be inserted to
|
||||
* @param <E> the collection type
|
||||
* @return the input with the desired elements
|
||||
*/
|
||||
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||
ITERATORS.pour(iterator(), collection);
|
||||
return collection;
|
||||
}
|
||||
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a ArrayList
|
||||
* @return a new ArrayList of all elements
|
||||
*/
|
||||
default LIST KEY_GENERIC_TYPE pourAsList() {
|
||||
#if ARRAY_LIST_FEATURE
|
||||
return pour(new ARRAY_LISTBRACES());
|
||||
#else
|
||||
return pour(new LINKED_LISTBRACES());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN && SET_MODULE
|
||||
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a LinkedHashSet
|
||||
* @return a new LinkedHashSet of all elements
|
||||
*/
|
||||
default SET KEY_GENERIC_TYPE pourAsSet() {
|
||||
#if LINKED_SET_FEATURE
|
||||
return pour(new LINKED_HASH_SETBRACES());
|
||||
#else if LINKED_CUSTOM_SET_FEATURE
|
||||
return pour(new LINKED_CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||
#else if SET_FEATURE
|
||||
return pour(new HASH_SETBRACES());
|
||||
#else if CUSTOM_SET_FEATURE
|
||||
return pour(new CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||
#else if RB_TREE_SET_FEATURE
|
||||
return pour(new RB_Tree_SETBRACES());
|
||||
#else if AVL_TREE_SET_FEATURE
|
||||
return pour(new AVL_Tree_SETBRACES());
|
||||
#else if ARRAY_SET_FEATURE
|
||||
return pour(new ARRAY_SETBRACES());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a Array
|
||||
* @param action is the creator function of said Array to ensure type is kept.
|
||||
* @param <E> the returning arrayType
|
||||
* @return a new Array of all elements
|
||||
*/
|
||||
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||
ISizeProvider prov = ISizeProvider.of(this);
|
||||
if(prov != null) {
|
||||
int size = prov.size();
|
||||
if(size >= 0) {
|
||||
E[] array = action.apply(size);
|
||||
ITERATORS.unwrap(array, iterator());
|
||||
return array;
|
||||
}
|
||||
}
|
||||
return ARRAYS.pour(iterator(), action);
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* A Helper function that reduces the usage of streams and allows to collect all elements as a Array
|
||||
* @return a new Array of all elements
|
||||
*/
|
||||
default KEY_TYPE[] TO_ARRAY() {
|
||||
ISizeProvider prov = ISizeProvider.of(this);
|
||||
if(prov != null) {
|
||||
int size = prov.size();
|
||||
if(size >= 0) {
|
||||
KEY_TYPE[] array = NEW_KEY_ARRAY(size);
|
||||
ITERATORS.unwrap(array, iterator());
|
||||
return array;
|
||||
}
|
||||
}
|
||||
return ARRAYS.pour(iterator());
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to filter for any matches.
|
||||
* @param filter that should be applied
|
||||
* @return true if any matches were found
|
||||
*/
|
||||
default boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.test(iter.NEXT())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to filter for no matches.
|
||||
* @param filter that should be applied
|
||||
* @return true if no matches were found
|
||||
*/
|
||||
default boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.test(iter.NEXT())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to filter for all matches.
|
||||
* @param filter that should be applied
|
||||
* @return true if all matches.
|
||||
*/
|
||||
default boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(!filter.test(iter.NEXT())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to filter for the first match.
|
||||
* @param filter that should be applied
|
||||
* @return the found value or the null equivalent variant.
|
||||
*/
|
||||
default KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE entry = iter.NEXT();
|
||||
if(filter.test(entry)) return entry;
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||
* elements of this Iterable
|
||||
* @param operator the operation that should be applied
|
||||
* @param identity the start value
|
||||
* @return the reduction result, returns identity if nothing was found
|
||||
*/
|
||||
default KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = identity;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||
* elements of this Iterable
|
||||
* @param operator the operation that should be applied
|
||||
* @param identity the start value
|
||||
* @Type(E)
|
||||
* @return the reduction result, returns identity if nothing was found
|
||||
*/
|
||||
default <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_SPECIAL_TYPE state = identity;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||
* elements of this Iterable
|
||||
* @param operator the operation that should be applied
|
||||
* @return the reduction result, returns null value if nothing was found
|
||||
*/
|
||||
default KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||
Objects.requireNonNull(operator);
|
||||
KEY_TYPE state = EMPTY_VALUE;
|
||||
boolean empty = true;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(empty) {
|
||||
empty = false;
|
||||
state = iter.NEXT();
|
||||
continue;
|
||||
}
|
||||
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to reduce stream usage that allows to count the valid elements.
|
||||
* @param filter that should be applied
|
||||
* @return the amount of Valid Elements
|
||||
*/
|
||||
default int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
if(filter.test(iter.NEXT())) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+69
-69
@@ -1,70 +1,70 @@
|
||||
package speiger.src.collections.PACKAGE.functions;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Type-Specific Class for Comparator to reduce (un)boxing
|
||||
*/
|
||||
public interface COMPARATOR extends Comparator<CLASS_TYPE>
|
||||
{
|
||||
/**
|
||||
* Type-Specific compare function to reduce (un)boxing
|
||||
* @param o1 the first object to be compared.
|
||||
* @param o2 the second object to be compared.
|
||||
* @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
|
||||
* @see Comparator#compare(Object, Object)
|
||||
*/
|
||||
int compare(KEY_TYPE o1, KEY_TYPE o2);
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default int compare(CLASS_TYPE o1, CLASS_TYPE o2) {
|
||||
return compare(OBJ_TO_KEY(o1), OBJ_TO_KEY(o2));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Wrapper function to convert a Non-Type-Specific Comparator to a Type-Specific-Comparator
|
||||
* @param c comparator to convert
|
||||
* @return the wrapper of the comparator
|
||||
* @throws NullPointerException if the comparator is null
|
||||
*/
|
||||
public static COMPARATOR of(Comparator<CLASS_TYPE> c) {
|
||||
Objects.requireNonNull(c);
|
||||
return (K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V));
|
||||
}
|
||||
|
||||
@Override
|
||||
public default COMPARATOR reversed() {
|
||||
return new Reversed(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Reversed Comparator to reduce boxing/unboxing
|
||||
*/
|
||||
static class Reversed implements COMPARATOR
|
||||
{
|
||||
COMPARATOR original;
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
* @param original that is going to be reversed
|
||||
*/
|
||||
public Reversed(COMPARATOR original) {
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
public int compare(KEY_TYPE o1, KEY_TYPE o2) {
|
||||
return original.compare(o2, o1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR reversed() {
|
||||
return original;
|
||||
}
|
||||
}
|
||||
package speiger.src.collections.PACKAGE.functions;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Type-Specific Class for Comparator to reduce (un)boxing
|
||||
*/
|
||||
public interface COMPARATOR extends Comparator<CLASS_TYPE>
|
||||
{
|
||||
/**
|
||||
* Type-Specific compare function to reduce (un)boxing
|
||||
* @param o1 the first object to be compared.
|
||||
* @param o2 the second object to be compared.
|
||||
* @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
|
||||
* @see Comparator#compare(Object, Object)
|
||||
*/
|
||||
int compare(KEY_TYPE o1, KEY_TYPE o2);
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default int compare(CLASS_TYPE o1, CLASS_TYPE o2) {
|
||||
return compare(OBJ_TO_KEY(o1), OBJ_TO_KEY(o2));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Wrapper function to convert a Non-Type-Specific Comparator to a Type-Specific-Comparator
|
||||
* @param c comparator to convert
|
||||
* @return the wrapper of the comparator
|
||||
* @throws NullPointerException if the comparator is null
|
||||
*/
|
||||
public static COMPARATOR of(Comparator<CLASS_TYPE> c) {
|
||||
Objects.requireNonNull(c);
|
||||
return (K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V));
|
||||
}
|
||||
|
||||
@Override
|
||||
public default COMPARATOR reversed() {
|
||||
return new Reversed(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Reversed Comparator to reduce boxing/unboxing
|
||||
*/
|
||||
static class Reversed implements COMPARATOR
|
||||
{
|
||||
COMPARATOR original;
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
* @param original that is going to be reversed
|
||||
*/
|
||||
public Reversed(COMPARATOR original) {
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
public int compare(KEY_TYPE o1, KEY_TYPE o2) {
|
||||
return original.compare(o2, o1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR reversed() {
|
||||
return original;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-18
@@ -1,19 +1,19 @@
|
||||
package speiger.src.collections.PACKAGE.functions;
|
||||
|
||||
/**
|
||||
* Type-Specific Supplier interface that reduces (un)boxing and allows to merge other consumer types into this interface
|
||||
* @Type(T)
|
||||
*/
|
||||
#if TYPE_OBJECT
|
||||
public interface SUPPLIER KEY_GENERIC_TYPE extends java.util.function.Supplier<KEY_TYPE>
|
||||
#else if JDK_TYPE && !TYPE_BOOLEAN
|
||||
public interface SUPPLIER KEY_GENERIC_TYPE extends JAVA_SUPPLIER
|
||||
#else
|
||||
public interface SUPPLIER KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* @return the supplied value
|
||||
*/
|
||||
public KEY_TYPE SUPPLY_GET();
|
||||
package speiger.src.collections.PACKAGE.functions;
|
||||
|
||||
/**
|
||||
* Type-Specific Supplier interface that reduces (un)boxing and allows to merge other consumer types into this interface
|
||||
* @Type(T)
|
||||
*/
|
||||
#if TYPE_OBJECT
|
||||
public interface SUPPLIER KEY_GENERIC_TYPE extends java.util.function.Supplier<KEY_TYPE>
|
||||
#else if JDK_TYPE && !TYPE_BOOLEAN
|
||||
public interface SUPPLIER KEY_GENERIC_TYPE extends JAVA_SUPPLIER
|
||||
#else
|
||||
public interface SUPPLIER KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* @return the supplied value
|
||||
*/
|
||||
public KEY_TYPE SUPPLY_GET();
|
||||
}
|
||||
+91
-91
@@ -1,92 +1,92 @@
|
||||
package speiger.src.collections.PACKAGE.functions;
|
||||
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
* A Type Specific Task interface that allows you to keep track of the task that is currently running.<br>
|
||||
* It extends Runnable future and supports said functions but also provides quality of life functions like:<br>
|
||||
*
|
||||
* - isSuccesfull: which allows to detect if the task was completed properly and not interrupted or crashed.
|
||||
* - pause/resume: which allows to pause/resume the task at any moment, making it easier to create thread-safe actions.
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface TASK KEY_GENERIC_TYPE extends RunnableFuture<CLASS_TYPE> {
|
||||
/**
|
||||
* Helper function to detect if the task is currently paused.
|
||||
* @return true if paused
|
||||
*/
|
||||
public boolean isPaused();
|
||||
|
||||
/**
|
||||
* Pauses the task, which lets the thread finish without completing the task.
|
||||
* Tasks are written in the way where they can pause without any issues.
|
||||
* This won't be instant, as this function is applied asynchronous and doesn't check if the thread paused.
|
||||
* So make sure it had the time to pause.
|
||||
*/
|
||||
public void pause();
|
||||
|
||||
/**
|
||||
* Pauses the task, which lets the thread finish without completing the task.
|
||||
* Tasks are written in the way where they can pause without any issues.
|
||||
* This won't be instant, as this function is applied asynchronous.
|
||||
* It will await the pausing of the task.
|
||||
*/
|
||||
public void awaitPausing();
|
||||
|
||||
/**
|
||||
* Continues the task if it wasn't already completed.
|
||||
* This is done by resubmitting the task to the executor provided.
|
||||
*/
|
||||
public void resume();
|
||||
|
||||
/**
|
||||
* Quality of life function that allows to detect if no cancellation/exception was applied to this task and it completed on its own.
|
||||
* @return true if it was properly completed
|
||||
*/
|
||||
public boolean isSuccessful();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific get method that allows to reduce (un)boxing of primtives.
|
||||
*
|
||||
* Waits if necessary for the computation to complete, and then
|
||||
* retrieves its result.
|
||||
*
|
||||
* @return the computed result as primitive
|
||||
* @throws CancellationException if the computation was cancelled
|
||||
* @throws ExecutionException if the computation threw an exception
|
||||
* @throws InterruptedException if the current thread was interrupted
|
||||
* while waiting
|
||||
*/
|
||||
public KEY_TYPE GET_KEY() throws InterruptedException, ExecutionException;
|
||||
|
||||
/**
|
||||
* Waits if necessary for at most the given time for the computation
|
||||
* to complete, and then retrieves its result, if available.
|
||||
*
|
||||
* @param timeout the maximum time to wait
|
||||
* @param unit the time unit of the timeout argument
|
||||
* @return the computed result as primitive
|
||||
* @throws CancellationException if the computation was cancelled
|
||||
* @throws ExecutionException if the computation threw an exception
|
||||
* @throws InterruptedException if the current thread was interrupted while waiting
|
||||
* @throws TimeoutException if the wait timed out
|
||||
*/
|
||||
public KEY_TYPE GET_KEY(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE get() throws InterruptedException, ExecutionException { return KEY_TO_OBJ(GET_KEY()); }
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return KEY_TO_OBJ(GET_KEY(timeout, unit)); }
|
||||
#endif
|
||||
package speiger.src.collections.PACKAGE.functions;
|
||||
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
#if !TYPE_OBJECT
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
* A Type Specific Task interface that allows you to keep track of the task that is currently running.<br>
|
||||
* It extends Runnable future and supports said functions but also provides quality of life functions like:<br>
|
||||
*
|
||||
* - isSuccesfull: which allows to detect if the task was completed properly and not interrupted or crashed.
|
||||
* - pause/resume: which allows to pause/resume the task at any moment, making it easier to create thread-safe actions.
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface TASK KEY_GENERIC_TYPE extends RunnableFuture<CLASS_TYPE> {
|
||||
/**
|
||||
* Helper function to detect if the task is currently paused.
|
||||
* @return true if paused
|
||||
*/
|
||||
public boolean isPaused();
|
||||
|
||||
/**
|
||||
* Pauses the task, which lets the thread finish without completing the task.
|
||||
* Tasks are written in the way where they can pause without any issues.
|
||||
* This won't be instant, as this function is applied asynchronous and doesn't check if the thread paused.
|
||||
* So make sure it had the time to pause.
|
||||
*/
|
||||
public void pause();
|
||||
|
||||
/**
|
||||
* Pauses the task, which lets the thread finish without completing the task.
|
||||
* Tasks are written in the way where they can pause without any issues.
|
||||
* This won't be instant, as this function is applied asynchronous.
|
||||
* It will await the pausing of the task.
|
||||
*/
|
||||
public void awaitPausing();
|
||||
|
||||
/**
|
||||
* Continues the task if it wasn't already completed.
|
||||
* This is done by resubmitting the task to the executor provided.
|
||||
*/
|
||||
public void resume();
|
||||
|
||||
/**
|
||||
* Quality of life function that allows to detect if no cancellation/exception was applied to this task and it completed on its own.
|
||||
* @return true if it was properly completed
|
||||
*/
|
||||
public boolean isSuccessful();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific get method that allows to reduce (un)boxing of primtives.
|
||||
*
|
||||
* Waits if necessary for the computation to complete, and then
|
||||
* retrieves its result.
|
||||
*
|
||||
* @return the computed result as primitive
|
||||
* @throws CancellationException if the computation was cancelled
|
||||
* @throws ExecutionException if the computation threw an exception
|
||||
* @throws InterruptedException if the current thread was interrupted
|
||||
* while waiting
|
||||
*/
|
||||
public KEY_TYPE GET_KEY() throws InterruptedException, ExecutionException;
|
||||
|
||||
/**
|
||||
* Waits if necessary for at most the given time for the computation
|
||||
* to complete, and then retrieves its result, if available.
|
||||
*
|
||||
* @param timeout the maximum time to wait
|
||||
* @param unit the time unit of the timeout argument
|
||||
* @return the computed result as primitive
|
||||
* @throws CancellationException if the computation was cancelled
|
||||
* @throws ExecutionException if the computation threw an exception
|
||||
* @throws InterruptedException if the current thread was interrupted while waiting
|
||||
* @throws TimeoutException if the wait timed out
|
||||
*/
|
||||
public KEY_TYPE GET_KEY(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE get() throws InterruptedException, ExecutionException { return KEY_TO_OBJ(GET_KEY()); }
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return KEY_TO_OBJ(GET_KEY(timeout, unit)); }
|
||||
#endif
|
||||
}
|
||||
+133
-133
@@ -1,134 +1,134 @@
|
||||
package speiger.src.collections.PACKAGE.functions.function;
|
||||
|
||||
#if VALUE_BOOLEAN || SAME_TYPE
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
@FunctionalInterface
|
||||
#if JDK_FUNCTION
|
||||
public interface FUNCTION KEY_VALUE_GENERIC_TYPE extends JAVA_FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
#else
|
||||
public interface FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* Type Specific get function to reduce boxing/unboxing
|
||||
* @param k the value that should be processed
|
||||
* @return the result of the function
|
||||
*/
|
||||
public VALUE_TYPE APPLY(KEY_TYPE k);
|
||||
|
||||
#if SAME_TYPE
|
||||
/**
|
||||
* Creates a Default function that returns the input provided.
|
||||
* @Type(T)
|
||||
* @return a input returning function
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES FUNCTION KEY_SAME_GENERIC_TYPE identity() {
|
||||
return T -> T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed function that first applies the {@code before}
|
||||
* function to its input, and then applies this function to the result.
|
||||
* If evaluation of either function throws an exception, it is relayed to
|
||||
* the caller of the composed function.
|
||||
*
|
||||
* @Type(I)
|
||||
* @param before the function that should be used first
|
||||
* @return a composed function with a different starting function.
|
||||
*/
|
||||
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION SV_GENERIC_TYPE<I> compose(FUNCTION SK_GENERIC_TYPE<I> before) {
|
||||
Objects.requireNonNull(before);
|
||||
return T -> APPLY(before.APPLY(T));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed function that first applies this function to
|
||||
* its input, and then applies the {@code after} function to the result.
|
||||
* If evaluation of either function throws an exception, it is relayed to
|
||||
* the caller of the composed function.
|
||||
*
|
||||
* @Type(I)
|
||||
* @param after the function that should be used last
|
||||
* @return a composed function with a different starting function.
|
||||
*/
|
||||
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION KS_GENERIC_TYPE<I> andThen(FUNCTION VS_GENERIC_TYPE<I> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return T -> after.APPLY(APPLY(T));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if VALUE_BOOLEAN
|
||||
/**
|
||||
* Creates a Always true function that may be useful if you don't need to process information or just want a default.
|
||||
* @Type(T)
|
||||
* @return a default returning function
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES FUNCTION KEY_GENERIC_TYPE alwaysTrue() {
|
||||
return T -> true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Always false function that may be useful if you don't need to process information or just want a default.
|
||||
* @Type(T)
|
||||
* @return a default returning function
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES FUNCTION KEY_GENERIC_TYPE alwaysFalse() {
|
||||
return T -> false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type specific and-function helper function that reduces boxing/unboxing
|
||||
* @param other the other function that should be merged with.
|
||||
* @return a function that compares values in a and comparason
|
||||
*/
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE andType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> APPLY(T) && other.APPLY(T);
|
||||
}
|
||||
|
||||
#if JDK_FUNCTION
|
||||
@Override
|
||||
@Deprecated
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE and(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> APPLY(T) && other.APPLY(T);
|
||||
}
|
||||
|
||||
@Override
|
||||
#else
|
||||
/**
|
||||
* A type specific inverter function
|
||||
* @return the same function but inverts the result
|
||||
*/
|
||||
#endif
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE negate() {
|
||||
return T -> !APPLY(T);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type specific or-function helper function that reduces boxing/unboxing
|
||||
* @param other the other function that should be merged with.
|
||||
* @return a function that compares values in a or comparason
|
||||
*/
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE orType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> APPLY(T) || other.APPLY(T);
|
||||
}
|
||||
|
||||
#if JDK_FUNCTION
|
||||
@Override
|
||||
@Deprecated
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE or(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> APPLY(T) || other.APPLY(T);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
package speiger.src.collections.PACKAGE.functions.function;
|
||||
|
||||
#if VALUE_BOOLEAN || SAME_TYPE
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
@FunctionalInterface
|
||||
#if JDK_FUNCTION
|
||||
public interface FUNCTION KEY_VALUE_GENERIC_TYPE extends JAVA_FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
#else
|
||||
public interface FUNCTION KEY_VALUE_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* Type Specific get function to reduce boxing/unboxing
|
||||
* @param k the value that should be processed
|
||||
* @return the result of the function
|
||||
*/
|
||||
public VALUE_TYPE APPLY(KEY_TYPE k);
|
||||
|
||||
#if SAME_TYPE
|
||||
/**
|
||||
* Creates a Default function that returns the input provided.
|
||||
* @Type(T)
|
||||
* @return a input returning function
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES FUNCTION KEY_SAME_GENERIC_TYPE identity() {
|
||||
return T -> T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed function that first applies the {@code before}
|
||||
* function to its input, and then applies this function to the result.
|
||||
* If evaluation of either function throws an exception, it is relayed to
|
||||
* the caller of the composed function.
|
||||
*
|
||||
* @Type(I)
|
||||
* @param before the function that should be used first
|
||||
* @return a composed function with a different starting function.
|
||||
*/
|
||||
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION SV_GENERIC_TYPE<I> compose(FUNCTION SK_GENERIC_TYPE<I> before) {
|
||||
Objects.requireNonNull(before);
|
||||
return T -> APPLY(before.APPLY(T));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed function that first applies this function to
|
||||
* its input, and then applies the {@code after} function to the result.
|
||||
* If evaluation of either function throws an exception, it is relayed to
|
||||
* the caller of the composed function.
|
||||
*
|
||||
* @Type(I)
|
||||
* @param after the function that should be used last
|
||||
* @return a composed function with a different starting function.
|
||||
*/
|
||||
public default GENERIC_SPECIAL_VALUE_BRACES<I> FUNCTION KS_GENERIC_TYPE<I> andThen(FUNCTION VS_GENERIC_TYPE<I> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return T -> after.APPLY(APPLY(T));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if VALUE_BOOLEAN
|
||||
/**
|
||||
* Creates a Always true function that may be useful if you don't need to process information or just want a default.
|
||||
* @Type(T)
|
||||
* @return a default returning function
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES FUNCTION KEY_GENERIC_TYPE alwaysTrue() {
|
||||
return T -> true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Always false function that may be useful if you don't need to process information or just want a default.
|
||||
* @Type(T)
|
||||
* @return a default returning function
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES FUNCTION KEY_GENERIC_TYPE alwaysFalse() {
|
||||
return T -> false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type specific and-function helper function that reduces boxing/unboxing
|
||||
* @param other the other function that should be merged with.
|
||||
* @return a function that compares values in a and comparason
|
||||
*/
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE andType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> APPLY(T) && other.APPLY(T);
|
||||
}
|
||||
|
||||
#if JDK_FUNCTION
|
||||
@Override
|
||||
@Deprecated
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE and(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> APPLY(T) && other.APPLY(T);
|
||||
}
|
||||
|
||||
@Override
|
||||
#else
|
||||
/**
|
||||
* A type specific inverter function
|
||||
* @return the same function but inverts the result
|
||||
*/
|
||||
#endif
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE negate() {
|
||||
return T -> !APPLY(T);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type specific or-function helper function that reduces boxing/unboxing
|
||||
* @param other the other function that should be merged with.
|
||||
* @return a function that compares values in a or comparason
|
||||
*/
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE orType(FUNCTION KEY_VALUE_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> APPLY(T) || other.APPLY(T);
|
||||
}
|
||||
|
||||
#if JDK_FUNCTION
|
||||
@Override
|
||||
@Deprecated
|
||||
public default FUNCTION KEY_VALUE_GENERIC_TYPE or(JAVA_FUNCTION KEY_VALUE_SUPER_GENERIC_TYPE other) {
|
||||
Objects.requireNonNull(other);
|
||||
return T -> APPLY(T) || other.APPLY(T);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
+1199
-1197
File diff suppressed because it is too large
Load Diff
+2190
-2188
File diff suppressed because it is too large
Load Diff
+1378
-1376
File diff suppressed because it is too large
Load Diff
+2526
-2524
File diff suppressed because it is too large
Load Diff
+1513
-1511
File diff suppressed because it is too large
Load Diff
+1555
-1553
File diff suppressed because it is too large
Load Diff
+1512
-1510
File diff suppressed because it is too large
Load Diff
+1510
-1508
File diff suppressed because it is too large
Load Diff
+1407
-1405
File diff suppressed because it is too large
Load Diff
+1457
-1455
File diff suppressed because it is too large
Load Diff
+738
-738
File diff suppressed because it is too large
Load Diff
+963
-963
File diff suppressed because it is too large
Load Diff
+2918
-2916
File diff suppressed because it is too large
Load Diff
+2990
-2988
File diff suppressed because it is too large
Load Diff
+94
-94
@@ -1,95 +1,95 @@
|
||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A type specific ConcurrentMap interface that reduces boxing/unboxing.
|
||||
* Since the interface adds nothing new. It is there just for completion sake.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public interface CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE extends ConcurrentMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE compute(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.compute(key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE computeIfAbsent(CLASS_TYPE key, Function<? super CLASS_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.computeIfAbsent(key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE computeIfPresent(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.computeIfPresent(key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) {
|
||||
MAP.super.forEach(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE merge(CLASS_TYPE key, CLASS_VALUE_TYPE value, BiFunction<? super CLASS_VALUE_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.merge(key, value, mappingFunction);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue);
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||
@Override
|
||||
public boolean remove(Object key, Object value);
|
||||
@Override
|
||||
public boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue);
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||
|
||||
#else
|
||||
@Primitive
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
|
||||
return MAP.super.getOrDefault(key, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||
return MAP.super.putIfAbsent(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object key, Object value) {
|
||||
return MAP.super.remove(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue) {
|
||||
return MAP.super.replace(key, oldValue, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||
return MAP.super.replace(key, value);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public default void replaceAll(BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
MAP.super.replaceAll(mappingFunction);
|
||||
}
|
||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A type specific ConcurrentMap interface that reduces boxing/unboxing.
|
||||
* Since the interface adds nothing new. It is there just for completion sake.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public interface CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE extends ConcurrentMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE compute(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.compute(key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE computeIfAbsent(CLASS_TYPE key, Function<? super CLASS_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.computeIfAbsent(key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE computeIfPresent(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.computeIfPresent(key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) {
|
||||
MAP.super.forEach(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE merge(CLASS_TYPE key, CLASS_VALUE_TYPE value, BiFunction<? super CLASS_VALUE_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.merge(key, value, mappingFunction);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue);
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||
@Override
|
||||
public boolean remove(Object key, Object value);
|
||||
@Override
|
||||
public boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue);
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||
|
||||
#else
|
||||
@Primitive
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
|
||||
return MAP.super.getOrDefault(key, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||
return MAP.super.putIfAbsent(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object key, Object value) {
|
||||
return MAP.super.remove(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue) {
|
||||
return MAP.super.replace(key, oldValue, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||
return MAP.super.replace(key, value);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public default void replaceAll(BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
MAP.super.replaceAll(mappingFunction);
|
||||
}
|
||||
}
|
||||
+46
-46
@@ -1,46 +1,46 @@
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Helper class that implements all the essential methods for the PriorityQueues
|
||||
* @Type(T)
|
||||
*/
|
||||
public abstract class ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof PRIORITY_QUEUE) {
|
||||
PRIORITY_QUEUE KEY_GENERIC_TYPE queue = (PRIORITY_QUEUE KEY_GENERIC_TYPE)obj;
|
||||
if(queue.size() != size()) return false;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(KEY_EQUALS_NOT(queue.peek(i), peek(i))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
result = 31 * result + KEY_TO_HASH(peek(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(isEmpty()) return "[]";
|
||||
StringJoiner joiner = new StringJoiner(", ", "[", "]");
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
joiner.add(KEY_TO_STRING(peek(i)));
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Helper class that implements all the essential methods for the PriorityQueues
|
||||
* @Type(T)
|
||||
*/
|
||||
public abstract class ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof PRIORITY_QUEUE) {
|
||||
PRIORITY_QUEUE KEY_GENERIC_TYPE queue = (PRIORITY_QUEUE KEY_GENERIC_TYPE)obj;
|
||||
if(queue.size() != size()) return false;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(KEY_EQUALS_NOT(queue.peek(i), peek(i))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
result = 31 * result + KEY_TO_HASH(peek(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(isEmpty()) return "[]";
|
||||
StringJoiner joiner = new StringJoiner(", ", "[", "]");
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
joiner.add(KEY_TO_STRING(peek(i)));
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
||||
|
||||
+195
-194
@@ -1,195 +1,196 @@
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.IntFunction;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if QUEUES_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
/**
|
||||
* @return true if the PriorityQueue is empty
|
||||
*/
|
||||
public default boolean isEmpty() { return size() <= 0; }
|
||||
/**
|
||||
* @return the amount of elements that are stored in the PriorityQueue
|
||||
*/
|
||||
public int size();
|
||||
/**
|
||||
* clears all elements within the PriorityQueue,
|
||||
* this does not resize the backing arrays
|
||||
*/
|
||||
public void clear();
|
||||
|
||||
/**
|
||||
* Method to insert a element into the PriorityQueue
|
||||
* @param e the element that should be inserted
|
||||
*/
|
||||
public void enqueue(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE... e) {
|
||||
enqueueAll(e, 0, e.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE[] e, int length) {
|
||||
enqueueAll(e, 0, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
* @param offset the offset where in the array should be started
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE[] e, int offset, int length) {
|
||||
for(int i = 0;i<length;i++)
|
||||
enqueue(e[i+offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
enqueue(iter.NEXT());
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* This method exists to add support for Java Collections to make it more useable
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAll(Collection<? extends CLASS_TYPE> c) {
|
||||
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
||||
enqueue(iter.next());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Method to extract a element from the PriorityQueue
|
||||
* @return a element from the Queue
|
||||
* @throws java.util.NoSuchElementException if no element is present
|
||||
*/
|
||||
public KEY_TYPE dequeue();
|
||||
|
||||
/**
|
||||
* Peeking function to see whats inside the queue.
|
||||
* @param index of the element that is requested to be viewed.
|
||||
* @return the element that is requested
|
||||
*/
|
||||
public KEY_TYPE peek(int index);
|
||||
/**
|
||||
* Shows the element that is to be returned next
|
||||
* @return the first element in the Queue
|
||||
*/
|
||||
public default KEY_TYPE first() { return peek(0); }
|
||||
|
||||
/**
|
||||
* Removes the first found element in the queue
|
||||
* @param e the element that should be removed
|
||||
* @return if a searched element was removed
|
||||
*/
|
||||
public boolean removeFirst(KEY_TYPE e);
|
||||
/**
|
||||
* Removes the last found element in the queue
|
||||
* @param e the element that should be removed
|
||||
* @return if a searched element was removed
|
||||
*/
|
||||
public boolean removeLast(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Allows to notify the Queue to be revalidate its data
|
||||
*/
|
||||
public void onChanged();
|
||||
|
||||
/**
|
||||
* A Function that does a shallow clone of the PriorityQueue itself.
|
||||
* This function is more optimized then a copy constructor since the PriorityQueue does not have to be unsorted/resorted.
|
||||
* It can be compared to Cloneable but with less exception risk
|
||||
* @return a Shallow Copy of the PriorityQueue
|
||||
* @note Wrappers and view PriorityQueues will not support this feature
|
||||
*/
|
||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy();
|
||||
|
||||
/**
|
||||
* @return the sorter of the Queue, can be null
|
||||
*/
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator();
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* @return draining iterator of the PriorityQueue
|
||||
*/
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
#endif
|
||||
#if QUEUES_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||
* @return a new PriorityQueue that is synchronized
|
||||
* @see PRIORITY_QUEUES#synchronize
|
||||
*/
|
||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new PriorityQueue Wrapper that is synchronized
|
||||
* @see PRIORITY_QUEUES#synchronize
|
||||
*/
|
||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A method to drop the contents of the Queue without clearing the queue
|
||||
* @Type(E)
|
||||
* @return the contents of the queue into a seperate array.
|
||||
*/
|
||||
public default GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_SPECIAL_KEY_ARRAY(size())); }
|
||||
/**
|
||||
* A method to drop the contents of the Queue without clearing the queue
|
||||
* @param input where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
|
||||
* @Type(E)
|
||||
* @return the contents of the queue into a seperate array.
|
||||
* @note if the Type is generic then a Object Array is created instead of a Type Array
|
||||
*/
|
||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input);
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that simplifies the process of creating a new Array.
|
||||
* @param action the array creation function
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray(Object[])
|
||||
*/
|
||||
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||
return TO_ARRAY(action.apply(size()));
|
||||
}
|
||||
#endif
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.IntFunction;
|
||||
#else
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if QUEUES_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
/**
|
||||
* @return true if the PriorityQueue is empty
|
||||
*/
|
||||
public default boolean isEmpty() { return size() <= 0; }
|
||||
/**
|
||||
* @return the amount of elements that are stored in the PriorityQueue
|
||||
*/
|
||||
public int size();
|
||||
/**
|
||||
* clears all elements within the PriorityQueue,
|
||||
* this does not resize the backing arrays
|
||||
*/
|
||||
public void clear();
|
||||
|
||||
/**
|
||||
* Method to insert a element into the PriorityQueue
|
||||
* @param e the element that should be inserted
|
||||
*/
|
||||
public void enqueue(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE... e) {
|
||||
enqueueAll(e, 0, e.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE[] e, int length) {
|
||||
enqueueAll(e, 0, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param e the elements that should be inserted
|
||||
* @param offset the offset where in the array should be started
|
||||
* @param length the amount of elements that should be inserted
|
||||
*/
|
||||
public default void enqueueAll(KEY_TYPE[] e, int offset, int length) {
|
||||
for(int i = 0;i<length;i++)
|
||||
enqueue(e[i+offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||
enqueue(iter.NEXT());
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* Method to mass insert elements into the PriorityQueue
|
||||
* This method exists to add support for Java Collections to make it more useable
|
||||
* @param c the elements that should be inserted from the Collection
|
||||
*/
|
||||
public default void enqueueAll(Collection<? extends CLASS_TYPE> c) {
|
||||
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
||||
enqueue(iter.next());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Method to extract a element from the PriorityQueue
|
||||
* @return a element from the Queue
|
||||
* @throws java.util.NoSuchElementException if no element is present
|
||||
*/
|
||||
public KEY_TYPE dequeue();
|
||||
|
||||
/**
|
||||
* Peeking function to see whats inside the queue.
|
||||
* @param index of the element that is requested to be viewed.
|
||||
* @return the element that is requested
|
||||
*/
|
||||
public KEY_TYPE peek(int index);
|
||||
/**
|
||||
* Shows the element that is to be returned next
|
||||
* @return the first element in the Queue
|
||||
*/
|
||||
public default KEY_TYPE first() { return peek(0); }
|
||||
|
||||
/**
|
||||
* Removes the first found element in the queue
|
||||
* @param e the element that should be removed
|
||||
* @return if a searched element was removed
|
||||
*/
|
||||
public boolean removeFirst(KEY_TYPE e);
|
||||
/**
|
||||
* Removes the last found element in the queue
|
||||
* @param e the element that should be removed
|
||||
* @return if a searched element was removed
|
||||
*/
|
||||
public boolean removeLast(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Allows to notify the Queue to be revalidate its data
|
||||
*/
|
||||
public void onChanged();
|
||||
|
||||
/**
|
||||
* A Function that does a shallow clone of the PriorityQueue itself.
|
||||
* This function is more optimized then a copy constructor since the PriorityQueue does not have to be unsorted/resorted.
|
||||
* It can be compared to Cloneable but with less exception risk
|
||||
* @return a Shallow Copy of the PriorityQueue
|
||||
* @note Wrappers and view PriorityQueues will not support this feature
|
||||
*/
|
||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy();
|
||||
|
||||
/**
|
||||
* @return the sorter of the Queue, can be null
|
||||
*/
|
||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator();
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* @return draining iterator of the PriorityQueue
|
||||
*/
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
|
||||
#endif
|
||||
#if QUEUES_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||
* @return a new PriorityQueue that is synchronized
|
||||
* @see PRIORITY_QUEUES#synchronize
|
||||
*/
|
||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
||||
|
||||
/**
|
||||
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||
* @param mutex is the controller of the synchronization block
|
||||
* @return a new PriorityQueue Wrapper that is synchronized
|
||||
* @see PRIORITY_QUEUES#synchronize
|
||||
*/
|
||||
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A method to drop the contents of the Queue without clearing the queue
|
||||
* @Type(E)
|
||||
* @return the contents of the queue into a seperate array.
|
||||
*/
|
||||
public default GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_SPECIAL_KEY_ARRAY(size())); }
|
||||
/**
|
||||
* A method to drop the contents of the Queue without clearing the queue
|
||||
* @param input where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
|
||||
* @Type(E)
|
||||
* @return the contents of the queue into a seperate array.
|
||||
* @note if the Type is generic then a Object Array is created instead of a Type Array
|
||||
*/
|
||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input);
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that simplifies the process of creating a new Array.
|
||||
* @param action the array creation function
|
||||
* @param <E> the returning arrayType
|
||||
* @return an array containing all of the elements in this collection
|
||||
* @see Collection#toArray(Object[])
|
||||
*/
|
||||
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||
return TO_ARRAY(action.apply(size()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+50
-50
@@ -1,50 +1,50 @@
|
||||
package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.Set;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
/**
|
||||
* Abstract Type Specific Set that reduces boxing/unboxing
|
||||
* @Type(T)
|
||||
*/
|
||||
public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||
{
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
@Override
|
||||
public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 0;
|
||||
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
||||
while(i.hasNext())
|
||||
hashCode += KEY_TO_HASH(i.NEXT());
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Set))
|
||||
return false;
|
||||
Set<?> l = (Set<?>)o;
|
||||
if(l.size() != size()) return false;
|
||||
try {
|
||||
return containsAll(l);
|
||||
} catch (ClassCastException | NullPointerException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.Set;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
/**
|
||||
* Abstract Type Specific Set that reduces boxing/unboxing
|
||||
* @Type(T)
|
||||
*/
|
||||
public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||
{
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
@Override
|
||||
public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 0;
|
||||
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
||||
while(i.hasNext())
|
||||
hashCode += KEY_TO_HASH(i.NEXT());
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (!(o instanceof Set))
|
||||
return false;
|
||||
Set<?> l = (Set<?>)o;
|
||||
if(l.size() != size()) return false;
|
||||
try {
|
||||
return containsAll(l);
|
||||
} catch (ClassCastException | NullPointerException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1655
-1655
File diff suppressed because it is too large
Load Diff
+1036
-1037
File diff suppressed because it is too large
Load Diff
+587
-587
File diff suppressed because it is too large
Load Diff
+1119
-1119
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+1179
-1179
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user