18 Commits
Author SHA1 Message Date
Speiger ffc34a131f New Features and Bugfixes.
- Fixed: ObjectArrayList.of was causing crashes because of a Poor
implementation.
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they
were modified during a rehash.
- Added: Array/Collection version of enqueue and enqueueFirst to
PriorityQueues.
- Added: fillBuffer function into PrimitiveLists which allow to optimize
JavaNio buffers if needed.
2021-10-11 19:05:54 +02:00
Speiger a38e7b069a More Consistency and more features.
- Added: Wrapper now support the Optimized Lambda replacer functions to
improve performance.
- Added: FIFO Queue has now a minimum capacity and that is now checked
more consistently.
- Added: Changelog & Version Bump
2021-10-07 14:50:52 +02:00
Speiger 9c15980e68 Version Bump 2021-10-06 20:53:19 +02:00
Speiger a05689017e Update information 2021-10-06 20:33:11 +02:00
Speiger 54c9660145 New Tests & BugFixes
-Added: Tests for the Copying of Collections.
-Fixed: PriorityQueues didn't have hashCode/equals/toString implemented
2021-10-06 20:23:40 +02:00
Speiger 0c4ef7f6c4 Queues are now copyable 2021-10-06 18:47:15 +02:00
Speiger 61d7a88c82 Maps are now copyable too 2021-10-06 18:32:10 +02:00
Speiger dff173222d Collections are now copyable 2021-10-06 17:48:37 +02:00
Speiger 6eded1f4be Sets are now Copyable 2021-10-06 17:43:46 +02:00
Speiger 07b715dd4c Start of adding copyable collections. Starting with Lists. 2021-10-06 16:30:53 +02:00
Speiger 1f1aa995df Release of 0.4.1 2021-09-29 02:11:29 +02:00
Speiger 1e2703acf2 ChangelogUpdate 2021-09-28 13:23:41 +02:00
Speiger 07abba6312 New Features
-Added: Count method for Iterable
-Fixed: A couple of bugs with the new stream removers not working well in LinkedCollections
2021-09-28 13:20:05 +02:00
Speiger 3f872463b6 Fixed a Rule Break with the new ComputeIfAbsent function 2021-09-28 12:26:44 +02:00
Speiger 531443531d New Features.
-Added: Suppliers.
-Added: ComputeIfAbsent but value generator is a supplier
2021-09-28 12:06:51 +02:00
Speiger 49c5e9eadd Changes.
-Added: New Changes to Changelog
-Fixed: Missing Autogenerated Type
-Cleanup: Gradle file got cleaned up from things it no longer needs.
-Changed: Upgraded to SCG 1.0.5 for incoming new features.
2021-09-28 04:43:04 +02:00
Speiger 3c5769e0e2 Added java type support for Stream replacer functions. 2021-09-28 03:34:53 +02:00
Speiger 0e061921e9 New Features and improvements
-Added: addAll array function.
-Fixed: forEach with input now puts the input at the key instead of value
2021-09-28 03:23:21 +02:00
62 changed files with 1998 additions and 208 deletions
+1 -1
View File
@@ -38,7 +38,7 @@
<attribute name="gradle_used_by_scope" value="builder"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
+23
View File
@@ -1,5 +1,28 @@
# Changelog of versions
### Version 0.4.4
- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation.
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash.
- Added: Array/Collection version of enqueue and enqueueFirst to PriorityQueues.
- Added: fillBuffer function into PrimitiveLists which allow to optimize JavaNio buffers if needed.
### Version 0.4.3
- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance.
- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently.
### Version 0.4.2
- Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function.
Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function.
- Fixed: PriorityQueues didn't implement: hashCode/equals/toString
### Version 0.4.1
- Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly
- Added: addAll with Array-types in collections.
- Added: Java Iterator/Iterable support for Stream replacing methods
- Added: Suppliers.
- Added: SupplyIfAbsent. It is ComputeIfAbsent but using suppliers
- Added: Count feature into Iterable
- Fixed: A couple bugs with the new StreamReplacing functions in LinkedCollections Iterating to Infinity
### Version 0.4.0
- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables
+13 -2
View File
@@ -15,19 +15,25 @@ But its focus is a different one.
- SplitIterators
- Iterators
- Pairs
- Unary/Functions
- Suppliers
- Bi/Consumers
## Specialized Functions
New Specialized functions that were added to increase performance or reduce allocations or Quality Of life.
To highlight things that may be wanted.
- Iterable:
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map()
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map().
- findFirst: Allows to find the first element of a Predicated Iterable.
- filter: Allows to filter unwanted elements for wrapped Iterable
- matchAny/matchNone/matchAll: Allows to find elements in a collection.
- count: counts all valid elements in a collection.
- forEach: Allows to input a second element into a forEach move allowing for more flexibility for Method References
- Collection:
- containsAny: Allows to test if another collection contains an of the elements of the tested collection.
- primitiveStream: Provides access to the closest Java Stream Type.
- copy: shallowCopies the collection, used instead of clone because this is better to use.
(subCollections/synchronized/unmodifiable not supported for obvious reasons)
- List:
- add/get/removeElements (From FastUtil): Allows to add/get/remove an Array into/from a list. Just with less overhead
- extractElements: Allows to remove a Range of elements from the List and get what was removed.
@@ -43,6 +49,7 @@ To highlight things that may be wanted.
- addToAll: Same as addTo but bulkVersion.
- removeOrDefault: removes a Element and if not present returns the default value instead of the present value.
- mergeAll: BulkVersion of Merge function.
- supplyIfAbsent: A Supplier based computeIfAbsent
- Sorted Map:
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted Map.
- moveToFirst/Last: Moves the desired element at the first/last position of the Map.
@@ -65,13 +72,17 @@ repositories {
}
}
dependencies {
compile 'de.speiger:Primitive-Collections:0.4.0'
compile 'de.speiger:Primitive-Collections:0.4.4'
}
```
Direct:
| Version | Jar | Sources | Java Doc |
|--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- |
| 0.4.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-javadoc.jar) |
| 0.4.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-javadoc.jar) |
| 0.4.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-javadoc.jar) |
| 0.4.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-javadoc.jar) |
| 0.4.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-javadoc.jar) |
| 0.3.6 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-javadoc.jar) |
| 0.3.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5-javadoc.jar) |
+3 -15
View File
@@ -18,7 +18,7 @@ repositories {
}
archivesBaseName = 'Primitive Collections'
version = '0.4.0';
version = '0.4.4';
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
@@ -30,21 +30,9 @@ eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
file {
whenMerged {
//Enforce a custom container and allowing access to the sun.misc package which is nessesary for EnumMaps
entries.find{ it.kind == 'con' && it.path.startsWith('org.eclipse.jdt')}.path = 'org.eclipse.jdt.launching.JRE_CONTAINER';
}
}
}
}
compileJava {
options.compilerArgs << '-XDignore.symbol.file'
options.fork = true
options.forkOptions.executable = 'javac' // may not needed on 1.8
}
sourceSets {
builder
}
@@ -54,8 +42,8 @@ configurations {
}
dependencies {
builderCompile 'de.speiger:Simple-Code-Generator:1.0.4'
runtimeOnly 'de.speiger:Simple-Code-Generator:1.0.4'
builderCompile 'de.speiger:Simple-Code-Generator:1.0.5'
runtimeOnly 'de.speiger:Simple-Code-Generator:1.0.5'
testImplementation 'junit:junit:4.12'
}
@@ -147,11 +147,13 @@ public class GlobalVariables
{
addSimpleMapper("JAVA_PREDICATE", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Predicate");
addSimpleMapper("JAVA_CONSUMER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Consumer");
addSimpleMapper("JAVA_SUPPLIER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Supplier");
addSimpleMapper("JAVA_FUNCTION", type.getFunctionClass(valueType));
addSimpleMapper("JAVA_BINARY_OPERATOR", type == ClassType.BOOLEAN ? "" : (type.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+type.getCustomJDKType().getFileType()+"BinaryOperator"));
addSimpleMapper("JAVA_UNARY_OPERATOR", type.isObject() ? "BinaryOperator" : type == ClassType.BOOLEAN ? "" : type.getCustomJDKType().getFileType()+"UnaryOperator");
addSimpleMapper("JAVA_SPLIT_ITERATOR", type.isPrimitiveBlocking() ? "Spliterator" : "Of"+type.getCustomJDKType().getFileType());
addSimpleMapper("JAVA_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Stream");
addSimpleMapper("JAVA_BUFFER", type.getFileType()+"Buffer");
//Final Classes
addClassMapper("ARRAY_LIST", "ArrayList");
@@ -183,6 +185,7 @@ public class GlobalVariables
//Abstract Classes
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
addAbstractMapper("ABSTRACT_PRIORITY_QUEUE", "Abstract%sPriorityQueue");
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
@@ -203,7 +206,8 @@ public class GlobalVariables
addClassMapper("LIST_ITERATOR", "ListIterator");
addClassMapper("BI_ITERATOR", "BidirectionalIterator");
addBiClassMapper("BI_CONSUMER", "Consumer", "");
addClassMapper("BI_OBJECT_CONSUMER", "ObjectConsumer");
addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer");
addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer");
addClassMapper("SPLIT_ITERATOR", "Splititerator");
addClassMapper("ITERATOR", "Iterator");
addClassMapper("ITERABLE", "Iterable");
@@ -224,6 +228,7 @@ public class GlobalVariables
addClassMapper("SET", "Set");
addClassMapper("STRATEGY", "Strategy");
addClassMapper("STACK", "Stack");
addClassMapper("SUPPLIER", "Supplier");
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
if(type.isObject())
{
@@ -274,6 +279,7 @@ public class GlobalVariables
addFunctionMapper("GET_KEY", "get");
if(type.isObject()) addFunctionValueMapper("GET_VALUE", valueType.isObject() ? "getObject" : "get");
else addSimpleMapper("GET_VALUE", "get");
addSimpleMapper("GET_JAVA", type.isObject() ? "get" : "getAs"+type.getCustomJDKType().getNonFileType());
addFunctionMapper("LAST_KEY", "last");
addFunctionValueMapper("MERGE", "merge");
addFunctionMapper("NEXT", "next");
@@ -286,6 +292,7 @@ public class GlobalVariables
addFunctionValueMappers("REPLACE_VALUES", valueType.isObject() ? "replaceObjects" : "replace%ss");
addFunctionMappers("REPLACE", type.isObject() ? "replaceObjects" : "replace%ss");
addFunctionMappers("SORT", "sort%ss");
addFunctionValueMappers("SUPPLY_IF_ABSENT", "supply%sIfAbsent");
addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get");
addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get");
addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream");
@@ -78,6 +78,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
nameRemapper.put("IArray", "I%sArray");
nameRemapper.put("AbstractMap", "Abstract%sMap");
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
nameRemapper.put("AbstractPriorityQueue", "Abstract%sPriorityQueue");
nameRemapper.put("AbstractSet", "Abstract%sSet");
nameRemapper.put("AbstractList", "Abstract%sList");
nameRemapper.put("EnumMap", "Enum2%sMap");
@@ -35,6 +35,9 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
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.
@@ -9,11 +9,8 @@ import java.util.stream.JAVA_STREAM;
import java.util.stream.StreamSupport;
#endif
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
import speiger.src.collections.utils.SanityChecks;
#endif
/**
* A Type-Specific {@link Collection} that reduces (un)boxing
* @Type(T)
@@ -36,6 +33,38 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
*/
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
@@ -94,6 +123,15 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
*/
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
/**
* 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 Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
@@ -8,7 +8,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.collections.ObjectIterable;
#endif
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
@@ -66,7 +66,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
* @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_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
default <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
iterator().forEachRemaining(input, action);
}
@@ -170,4 +170,18 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
}
return EMPTY_VALUE;
}
/**
* 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_VALUE(iter.NEXT())) result++;
}
return result;
}
}
@@ -8,7 +8,7 @@ import java.util.function.Consumer;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
/**
* A Type-Specific {@link Iterator} that reduces (un)boxing
@@ -74,9 +74,9 @@ public interface ITERATOR KEY_GENERIC_TYPE extends Iterator<CLASS_TYPE>
* @param <E> the generic type of the Object
* @throws java.lang.NullPointerException if the specified action is null
*/
default <E> void forEachRemaining(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
default <E> void forEachRemaining(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
while(hasNext()) { action.accept(NEXT(), input); }
while(hasNext()) { action.accept(input, NEXT()); }
}
/**
@@ -0,0 +1,26 @@
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 GET_KEY();
#if JDK_TYPE && PRIMITIVE
@Override
public default KEY_TYPE GET_JAVA() {
return GET_KEY();
}
#endif
}
@@ -229,6 +229,8 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
while(size < size()) REMOVE(size() - 1);
}
public ABSTRACT_LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
private class SUB_LIST extends ABSTRACT_LIST KEY_GENERIC_TYPE {
ABSTRACT_LIST KEY_GENERIC_TYPE l;
int offset;
@@ -280,6 +282,14 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
return true;
}
@Override
public boolean addAll(KEY_TYPE[] e, int offset, int length) {
if(length <= 0) return false;
l.addElements(this.offset, e, offset, length);
offset += length;
return true;
}
@Override
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
checkRange(from);
@@ -15,6 +15,7 @@ import java.util.function.UnaryOperator;
#if PRIMITIVES
import java.util.function.JAVA_PREDICATE;
import java.util.function.JAVA_UNARY_OPERATOR;
import java.nio.JAVA_BUFFER;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION;
@@ -26,7 +27,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.utils.ARRAYS;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
@@ -181,7 +182,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
*/
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c) {
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
list.data = (KEY_TYPE[])ObjectArrays.newArray(c.getClass().getComponentType(), 0);
list.data = (KEY_TYPE[])ObjectArrays.newArray(c, 0);
return list;
}
@@ -282,6 +283,16 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return true;
}
@Override
public boolean addAll(KEY_TYPE[] e, int offset, int length) {
if(length <= 0) return false;
SanityChecks.checkArrayCapacity(e.length, offset, length);
grow(size + length);
System.arraycopy(e, offset, data, size, length);
size+=length;
return true;
}
/**
* Appends the specified array elements to the index of the list.
* @param from the index where to append the elements to
@@ -378,9 +389,15 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
size -= length;
return a;
}
#endif
#if PRIMITIVES
@Override
public void fillBuffer(JAVA_BUFFER buffer) {
buffer.put(data, 0, size);
}
#endif
/**
* A function to find if the Element is present in this list.
* @param o the element that is searched for
@@ -591,10 +608,10 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;i++)
action.accept(data[i], input);
action.accept(input, data[i]);
}
@Override
@@ -633,6 +650,16 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0;i<size;i++) {
if(filter.TEST_VALUE(data[i])) result++;
}
return result;
}
/**
* A Type-Specific set function to reduce (un)boxing
* @param index the index of the element to set
@@ -995,6 +1022,14 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
grow(size);
}
@Override
public ARRAY_LIST KEY_GENERIC_TYPE copy() {
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
list.data = Arrays.copyOf(data, data.length);
list.size = size;
return list;
}
protected void grow(int capacity) {
if(capacity < data.length) return;
data = Arrays.copyOf(data, data == ARRAYS.EMPTY_ARRAY ? Math.max(DEFAULT_ARRAY_SIZE, capacity) : (int)Math.max(Math.min((long)data.length + (data.length >> 1), SanityChecks.MAX_ARRAY_SIZE), capacity));
@@ -22,7 +22,7 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.utils.ARRAYS;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
@@ -120,6 +120,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
@Override
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
@Override
public boolean addAll(KEY_TYPE[] e, int offset, int length) { throw new UnsupportedOperationException(); }
@Override
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { throw new UnsupportedOperationException(); }
@Override
@@ -259,6 +261,11 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
return data[index];
}
@Override
public IMMUTABLE_LIST KEY_GENERIC_TYPE copy() {
return new IMMUTABLE_LISTBRACES(Arrays.copyOf(data, data.length));
}
/**
* A Type Specific foreach function that reduces (un)boxing
*
@@ -281,10 +288,10 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(int i = 0,m=data.length;i<m;i++)
action.accept(data[i], input);
action.accept(input, data[i]);
}
@Override
@@ -323,6 +330,16 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0,m=data.length;i<m;i++) {
if(filter.TEST_VALUE(data[i])) result++;
}
return result;
}
@Override
public KEY_TYPE set(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); }
@Override
@@ -2,6 +2,8 @@ package speiger.src.collections.PACKAGE.lists;
#if TYPE_OBJECT
import java.util.Comparator;
#else if PRIMITIVES
import java.nio.JAVA_BUFFER;
#endif
import java.util.Collection;
import java.util.Iterator;
@@ -17,7 +19,7 @@ import java.util.function.UnaryOperator;
import java.util.function.JAVA_PREDICATE;
import java.util.function.JAVA_UNARY_OPERATOR;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.collections.COLLECTION;
#if !TYPE_OBJECT
@@ -241,6 +243,14 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
add(e);
}
@Override
public boolean addAll(KEY_TYPE[] e, int offset, int length) {
if(length <= 0) return false;
SanityChecks.checkArrayCapacity(e.length, offset, length);
for(int i = 0;i<length;i++) linkLast(e[offset+i]);
return true;
}
@Override
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
SanityChecks.checkArrayCapacity(a.length, offset, length);
@@ -402,10 +412,10 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next)
action.accept(entry.value, input);
action.accept(input, entry.value);
}
@Override
@@ -444,6 +454,16 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
if(filter.TEST_VALUE(entry.value)) result++;
}
return result;
}
@Override
public KEY_TYPE set(int index, KEY_TYPE e) {
checkRange(index);
@@ -619,6 +639,14 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
return d;
}
#endif
#if PRIMITIVES
@Override
public void fillBuffer(JAVA_BUFFER buffer) {
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next)
buffer.put(entry.value);
}
#endif
@Override
@Primitive
@@ -802,6 +830,23 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
size = 0;
}
@Override
public LINKED_LIST KEY_GENERIC_TYPE copy() {
LINKED_LIST KEY_GENERIC_TYPE list = new LINKED_LISTBRACES();
list.size = size;
if(first != null) {
list.first = new EntryBRACES(first.value, null, null);
Entry KEY_GENERIC_TYPE lastReturned = list.first;
for(Entry KEY_GENERIC_TYPE entry = first.next;entry != null;entry = entry.next) {
Entry KEY_GENERIC_TYPE next = new EntryBRACES(entry.value, lastReturned, null);
lastReturned.next = next;
lastReturned = next;
}
list.last = lastReturned;
}
return list;
}
protected Entry KEY_GENERIC_TYPE getNode(int index) {
if(index < size >> 2) {
Entry KEY_GENERIC_TYPE x = first;
@@ -1,5 +1,8 @@
package speiger.src.collections.PACKAGE.lists;
#if PRIMITIVES
import java.nio.JAVA_BUFFER;
#endif
import java.util.List;
#if !TYPE_OBJECT && !TYPE_BOOLEAN
import java.util.Objects;
@@ -169,7 +172,6 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
* @param offset the start index of the array should be read from
* @param length how many elements should be read from
* @throws IndexOutOfBoundsException if from is outside of the lists range
* @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length
*/
public void addElements(int from, KEY_TYPE[] a, int offset, int length);
@@ -256,6 +258,14 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
*/
public KEY_TYPE[] extractElements(int from, int to);
#if PRIMITIVES
/**
* Helper function that allows to fastFill a buffer reducing the duplication requirement
* @param buffer where the data should be stored in.
*/
public default void fillBuffer(JAVA_BUFFER buffer) { buffer.put(TO_ARRAY()); }
#endif
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
@@ -340,6 +350,8 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
*/
public void size(int size);
@Override
public LIST KEY_GENERIC_TYPE copy();
#if !TYPE_OBJECT
/** {@inheritDoc}
@@ -18,6 +18,7 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.objects.collections.ObjectIterator;
#endif
@@ -46,6 +47,11 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
return this;
}
@Override
public MAP KEY_VALUE_GENERIC_TYPE copy() {
throw new UnsupportedOperationException();
}
#if !TYPE_OBJECT || !VALUE_OBJECT
@Override
@Deprecated
@@ -189,6 +195,20 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
return value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
VALUE_TYPE value;
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
put(key, newValue);
return newValue;
}
}
return value;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -1,5 +1,6 @@
package speiger.src.collections.PACKAGE.maps.impl.customHash;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -10,9 +11,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
#if !TYPE_OBJECT || VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@@ -41,7 +40,10 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
#endif
#endif
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT
@@ -335,6 +337,23 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
return values[index];
}
@Override
public LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_CUSTOM_HASH_MAPKV_BRACES(0, loadFactor, strategy);
map.minCapacity = minCapacity;
map.mask = mask;
map.maxFill = maxFill;
map.nullIndex = nullIndex;
map.containsNull = containsNull;
map.size = size;
map.keys = Arrays.copyOf(keys, keys.length);
map.values = Arrays.copyOf(values, values.length);
map.links = Arrays.copyOf(links, links.length);
map.firstIndex = firstIndex;
map.lastIndex = lastIndex;
return map;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() {
return null;
@@ -652,6 +671,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
return new FastEntryIterator(fromElement);
}
@Override
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
int index = firstIndex;
@@ -673,12 +695,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int index = firstIndex;
while(index != -1) {
action.accept(new BasicEntryKV_BRACES(keys[index], values[index]), input);
action.accept(input, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
}
@@ -739,6 +761,21 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
int result = 0;
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.getBoolean(entry)) result++;
index = (int)links[index];
}
return result;
}
@Override
@Deprecated
public boolean contains(Object o) {
@@ -845,6 +882,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
return new KeyIterator(fromElement);
}
@Override
public KeySet copy() { throw new UnsupportedOperationException(); }
@Override
public int size() {
return LINKED_CUSTOM_HASH_MAP.this.size();
@@ -885,12 +925,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int index = firstIndex;
while(index != -1){
action.accept(keys[index], input);
action.accept(input, keys[index]);
index = (int)links[index];
}
}
@@ -943,6 +983,19 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
return EMPTY_KEY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
int index = firstIndex;
while(index != -1){
if(filter.TEST_VALUE(keys[index])) result++;
index = (int)links[index];
}
return result;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
@@ -1001,12 +1054,12 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int index = firstIndex;
while(index != -1){
action.accept(values[index], input);
action.accept(input, values[index]);
index = (int)links[index];
}
}
@@ -1058,6 +1111,19 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
}
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
int index = firstIndex;
while(index != -1){
if(filter.VALUE_TEST_VALUE(values[index])) result++;
index = (int)links[index];
}
return result;
}
}
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -1,6 +1,7 @@
package speiger.src.collections.PACKAGE.maps.impl.customHash;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
@@ -9,13 +10,11 @@ import java.util.function.Consumer;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
@@ -31,6 +30,7 @@ import speiger.src.collections.PACKAGE.sets.SET;
import speiger.src.collections.PACKAGE.utils.STRATEGY;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#if !VALUE_OBJECT
@@ -47,7 +47,10 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
#endif
#endif
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
import speiger.src.collections.objects.collections.ObjectIterator;
@@ -421,6 +424,20 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
}
#endif
@Override
public CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new CUSTOM_HASH_MAPKV_BRACES(0, loadFactor, strategy);
map.minCapacity = minCapacity;
map.mask = mask;
map.maxFill = maxFill;
map.nullIndex = nullIndex;
map.containsNull = containsNull;
map.size = size;
map.keys = Arrays.copyOf(keys, keys.length);
map.values = Arrays.copyOf(values, values.length);
return map;
}
@Override
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
if(entrySet == null) entrySet = new MapEntrySet();
@@ -494,6 +511,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
}
return values[index];
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
return values[index];
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
@@ -639,7 +668,10 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
VALUE_TYPE[] newValues = NEW_VALUE_ARRAY(newSize + 1);
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
while(strategy.equals(keys[--i], EMPTY_KEY_VALUE));
while(true) {
if(--i < 0) throw new ConcurrentModificationException("Map was modified during rehash");
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) break;
}
if(!strategy.equals(newKeys[pos = HashUtil.mix(strategy.hashCode(keys[i])) & newMask], EMPTY_KEY_VALUE))
while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_KEY_VALUE));
newKeys[pos] = keys[i];
@@ -779,12 +811,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]), input);
if(containsNull) action.accept(input, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]), input);
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, new BasicEntryKV_BRACES(keys[i], values[i]));
}
}
@@ -860,6 +892,25 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
int result = 0;
if(containsNull) {
entry.set(keys[nullIndex], values[nullIndex]);
if(filter.getBoolean(entry)) result++;
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) {
entry.set(keys[i], values[i]);
if(filter.getBoolean(entry)) result++;
}
}
return result;
}
@Override
public int size() {
return CUSTOM_HASH_MAP.this.size();
@@ -931,6 +982,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return new KeyIterator();
}
@Override
public KeySet copy() { throw new UnsupportedOperationException(); }
@Override
public int size() {
return CUSTOM_HASH_MAP.this.size();
@@ -949,12 +1003,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(keys[nullIndex], input);
if(containsNull) action.accept(input, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i], input);
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, keys[i]);
}
}
@@ -1001,6 +1055,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
}
return EMPTY_KEY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) result++;
}
return result;
}
}
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
@@ -1045,12 +1111,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(values[nullIndex], input);
if(containsNull) action.accept(input, values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(values[i], input);
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, values[i]);
}
}
@@ -1097,6 +1163,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
}
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) result++;
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.VALUE_TEST_VALUE(values[i])) result++;
}
return result;
}
}
private class FastEntryIterator extends MapIterator implements ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -1,5 +1,6 @@
package speiger.src.collections.PACKAGE.maps.impl.hash;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -10,9 +11,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
#if !TYPE_OBJECT || VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@@ -40,7 +39,10 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
#endif
#endif
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT
@@ -312,6 +314,23 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
return values[index];
}
@Override
public LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_HASH_MAPKV_BRACES(0, loadFactor);
map.minCapacity = minCapacity;
map.mask = mask;
map.maxFill = maxFill;
map.nullIndex = nullIndex;
map.containsNull = containsNull;
map.size = size;
map.keys = Arrays.copyOf(keys, keys.length);
map.values = Arrays.copyOf(values, values.length);
map.links = Arrays.copyOf(links, links.length);
map.firstIndex = firstIndex;
map.lastIndex = lastIndex;
return map;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() {
return null;
@@ -629,6 +648,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
return new FastEntryIterator(fromElement);
}
@Override
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
int index = firstIndex;
@@ -650,12 +672,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int index = firstIndex;
while(index != -1) {
action.accept(new BasicEntryKV_BRACES(keys[index], values[index]), input);
action.accept(input, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
}
@@ -716,6 +738,21 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.getBoolean(entry)) result++;
index = (int)links[index];
}
return result;
}
@Override
@Deprecated
public boolean contains(Object o) {
@@ -822,6 +859,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
return new KeyIterator(fromElement);
}
@Override
public KeySet copy() { throw new UnsupportedOperationException(); }
@Override
public int size() {
return LINKED_HASH_MAP.this.size();
@@ -862,12 +902,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int index = firstIndex;
while(index != -1){
action.accept(keys[index], input);
action.accept(input, keys[index]);
index = (int)links[index];
}
}
@@ -920,6 +960,19 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
return EMPTY_KEY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
int index = firstIndex;
while(index != -1){
if(filter.TEST_VALUE(keys[index])) return result++;
index = (int)links[index];
}
return result;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
@@ -979,12 +1032,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int index = firstIndex;
while(index != -1){
action.accept(values[index], input);
action.accept(input, values[index]);
index = (int)links[index];
}
}
@@ -1036,6 +1089,19 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
}
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
int index = firstIndex;
while(index != -1){
if(filter.VALUE_TEST_VALUE(values[index])) result++;
index = (int)links[index];
}
return result;
}
}
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -1,6 +1,7 @@
package speiger.src.collections.PACKAGE.maps.impl.hash;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
@@ -9,13 +10,11 @@ import java.util.function.Consumer;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
@@ -30,8 +29,10 @@ import speiger.src.collections.PACKAGE.sets.SET;
#endif
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#if !VALUE_OBJECT
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
@@ -46,7 +47,9 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
#endif
#endif
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
import speiger.src.collections.objects.collections.ObjectIterator;
@@ -381,7 +384,21 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return slot < 0 ? defaultValue : values[slot];
}
#endif
#endif
@Override
public HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
HASH_MAP KEY_VALUE_GENERIC_TYPE map = new HASH_MAPKV_BRACES(0, loadFactor);
map.minCapacity = minCapacity;
map.mask = mask;
map.maxFill = maxFill;
map.nullIndex = nullIndex;
map.containsNull = containsNull;
map.size = size;
map.keys = Arrays.copyOf(keys, keys.length);
map.values = Arrays.copyOf(values, values.length);
return map;
}
@Override
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
if(entrySet == null) entrySet = new MapEntrySet();
@@ -455,7 +472,19 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
}
return values[index];
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
return values[index];
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = findIndex(key);
@@ -599,7 +628,10 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
VALUE_TYPE[] newValues = NEW_VALUE_ARRAY(newSize + 1);
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
while(KEY_EQUALS_NULL(keys[--i]));
while(true) {
if(--i < 0) throw new ConcurrentModificationException("Map was modified during rehash");
if(KEY_EQUALS_NOT_NULL(keys[i])) break;
}
if(KEY_EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask]))
while(KEY_EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)]));
newKeys[pos] = keys[i];
@@ -739,12 +771,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]), input);
if(containsNull) action.accept(input, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]), input);
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, new BasicEntryKV_BRACES(keys[i], values[i]));
}
}
@@ -820,6 +852,25 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
int result = 0;
if(containsNull) {
entry.set(keys[nullIndex], values[nullIndex]);
if(filter.getBoolean(entry)) result++;
}
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) {
entry.set(keys[i], values[i]);
if(filter.getBoolean(entry)) result++;
}
}
return result;
}
@Override
public int size() {
return HASH_MAP.this.size();
@@ -901,6 +952,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
HASH_MAP.this.clear();
}
@Override
public KeySet copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
if(containsNull) action.accept(keys[nullIndex]);
@@ -909,12 +963,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(keys[nullIndex], input);
if(containsNull) action.accept(input, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i], input);
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, keys[i]);
}
}
@@ -961,6 +1015,18 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
}
return EMPTY_KEY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) result++;
}
return result;
}
}
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
@@ -1005,12 +1071,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(values[nullIndex], input);
if(containsNull) action.accept(input, values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(values[i], input);
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, values[i]);
}
}
@@ -1057,6 +1123,18 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
}
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
if(containsNull && filter.VALUE_TEST_VALUE(values[nullIndex])) result++;
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.VALUE_TEST_VALUE(values[i])) result++;
}
return result;
}
}
private class FastEntryIterator extends MapIterator implements ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -1,7 +1,8 @@
package speiger.src.collections.PACKAGE.maps.impl.immutable;
import java.util.Map;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer;
@@ -10,9 +11,7 @@ import java.util.function.Consumer;
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@@ -38,7 +37,10 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
#endif
#endif
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT
@@ -48,6 +50,7 @@ import speiger.src.collections.PACKAGE.sets.SET;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#if !VALUE_OBJECT
@@ -101,6 +104,10 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
/** Amount of Elements stored in the HashMap */
protected int size;
/**
* Helper constructor for copying the Map
*/
protected IMMUTABLE_HASH_MAP() {}
#if !TYPE_OBJECT || !VALUE_OBJECT
/**
@@ -410,6 +417,21 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
return valuesC;
}
@Override
public IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new IMMUTABLE_HASH_MAPKV_BRACES();
map.mask = mask;
map.nullIndex = nullIndex;
map.containsNull = containsNull;
map.size = size;
map.keys = Arrays.copyOf(keys, keys.length);
map.values = Arrays.copyOf(values, values.length);
map.links = Arrays.copyOf(links, links.length);
map.firstIndex = firstIndex;
map.lastIndex = lastIndex;
return map;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
@Override
@@ -439,7 +461,10 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@@ -584,6 +609,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
return new FastEntryIterator(fromElement);
}
@Override
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
int index = firstIndex;
@@ -605,12 +633,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int index = firstIndex;
while(index != -1) {
action.accept(new BasicEntryKV_BRACES(keys[index], values[index]), input);
action.accept(input, new BasicEntryKV_BRACES(keys[index], values[index]));
index = (int)links[index];
}
}
@@ -624,6 +652,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.getBoolean(entry)) return true;
index = (int)links[index];
}
return false;
}
@@ -637,6 +666,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.getBoolean(entry)) return false;
index = (int)links[index];
}
return true;
}
@@ -650,6 +680,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
while(index != -1) {
entry.set(keys[index], values[index]);
if(!filter.getBoolean(entry)) return false;
index = (int)links[index];
}
return true;
}
@@ -663,10 +694,26 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.getBoolean(entry)) return entry;
index = (int)links[index];
}
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
int result = 0;
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.getBoolean(entry)) result++;
index = (int)links[index];
}
return result;
}
@Override
@Deprecated
public boolean contains(Object o) {
@@ -749,6 +796,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
return new KeyIterator(fromElement);
}
@Override
public KeySet copy() { throw new UnsupportedOperationException(); }
@Override
public int size() {
return IMMUTABLE_HASH_MAP.this.size();
@@ -783,12 +833,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int index = firstIndex;
while(index != -1){
action.accept(keys[index], input);
action.accept(input, keys[index]);
index = (int)links[index];
}
}
@@ -841,6 +891,19 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
return EMPTY_KEY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int index = firstIndex;
int result = 0;
while(index != -1){
if(filter.TEST_VALUE(keys[index])) result++;
index = (int)links[index];
}
return result;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
@@ -897,12 +960,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
int index = firstIndex;
while(index != -1){
action.accept(values[index], input);
action.accept(input, values[index]);
index = (int)links[index];
}
}
@@ -954,6 +1017,19 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
}
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
int index = firstIndex;
while(index != -1){
if(filter.VALUE_TEST_VALUE(values[index])) result++;
index = (int)links[index];
}
return result;
}
}
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -11,9 +11,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@@ -32,6 +30,7 @@ import speiger.src.collections.PACKAGE.utils.maps.MAPS;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#if !VALUE_OBJECT
@@ -48,7 +47,10 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
#endif
#endif
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
#if !VALUE_OBJECT
@@ -485,7 +487,19 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
return values[index];
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
int index = findIndex(key);
if(index == -1) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insertIndex(size++, key, newValue);
return newValue;
}
return values[index];
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = findIndex(key);
@@ -540,6 +554,14 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
size = 0;
}
public ARRAY_MAP KEY_VALUE_GENERIC_TYPE copy() {
ARRAY_MAP KEY_VALUE_GENERIC_TYPE map = new ARRAY_MAPKV_BRACES();
map.size = size;
map.keys = Arrays.copyOf(keys, keys.length);
map.values = Arrays.copyOf(values, keys.length);
return map;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() {
return null;
@@ -967,6 +989,11 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return entrySet;
}
@Override
public SubMap copy() {
throw new UnsupportedOperationException();
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() {
return null;
@@ -1119,6 +1146,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return new SubFastEntryIterator(fromElement);
}
@Override
public SubMapEntrySet copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@@ -1138,10 +1168,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
for(int i = 0;i<length;i++)
action.accept(new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]), input);
action.accept(input, new BasicEntryKV_BRACES(keys[offset+i], values[offset+i]));
}
@Override
@@ -1192,6 +1222,19 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
for(int i = 0;i<length;i++) {
entry.set(keys[offset+i], values[offset+i]);
if(filter.getBoolean(entry)) result++;
}
return result;
}
@Override
@Deprecated
public boolean contains(Object o) {
@@ -1289,6 +1332,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
@Override
public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
@Override
public SubKeySet copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
Objects.requireNonNull(action);
@@ -1296,10 +1342,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
for(int i = 0;i<length;action.accept(keys[offset+i], input));
for(int i = 0;i<length;action.accept(input, keys[offset+i]));
}
@@ -1343,6 +1389,17 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return EMPTY_KEY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
for(int i = 0;i<length;i++) {
if(filter.TEST_VALUE(keys[i+offset])) result++;
}
return result;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
@Override
@@ -1394,9 +1451,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(int i = 0;i<length;action.accept(values[offset+i], input));
for(int i = 0;i<length;action.accept(input, values[offset+i]));
}
@@ -1435,6 +1492,16 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0;i<length;i++) {
if(filter.VALUE_TEST_VALUE(values[offset+i])) result++;
}
return result;
}
}
private class SubFastEntryIterator extends SubMapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -1650,6 +1717,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return new FastEntryIterator(fromElement);
}
@Override
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
@@ -1669,10 +1739,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;i++) {
action.accept(new BasicEntryKV_BRACES(keys[i], values[i]), input);
action.accept(input, new BasicEntryKV_BRACES(keys[i], values[i]));
}
}
@@ -1724,6 +1794,19 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES();
for(int i = 0;i<size;i++) {
entry.set(keys[i], values[i]);
if(filter.getBoolean(entry)) result++;
}
return result;
}
@Override
@Deprecated
public boolean contains(Object o) {
@@ -1821,6 +1904,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
@Override
public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
@Override
public KeySet copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
Objects.requireNonNull(action);
@@ -1828,9 +1914,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;action.accept(keys[i++], input));
for(int i = 0;i<size;action.accept(input, keys[i++]));
}
@@ -1871,6 +1957,16 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return EMPTY_KEY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0;i<size;i++) {
if(filter.TEST_VALUE(keys[i])) result++;
}
return result;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
@Override
@@ -1956,6 +2052,16 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0;i<size;i++) {
if(filter.VALUE_TEST_VALUE(values[i])) result++;
}
return result;
}
}
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -176,6 +176,15 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
}
#endif
@Override
public ENUM_MAP KEY_VALUE_GENERIC_TYPE copy() {
ENUM_MAP KEY_VALUE_GENERIC_TYPE map = new ENUM_MAPKV_BRACES(keyType);
map.size = size;
System.arraycopy(present, 0, map.present, 0, Math.min(present.length, map.present.length));
System.arraycopy(values, 0, map.values, 0, Math.min(values.length, map.values.length));
return map;
}
@Override
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
if(entrySet == null) entrySet = new EntrySet();
@@ -127,6 +127,18 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
return values[index];
}
@Override
public LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE copy() {
LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_ENUM_MAPKV_BRACES(keyType);
map.size = size;
System.arraycopy(present, 0, map.present, 0, Math.min(present.length, map.present.length));
System.arraycopy(values, 0, map.values, 0, Math.min(values.length, map.values.length));
System.arraycopy(links, 0, map.links, 0, Math.min(links.length, map.links.length));
map.firstIndex = firstIndex;
map.lastIndex = lastIndex;
return map;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() {
return null;
@@ -351,6 +363,8 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
return new FastEntryIterator(fromElement);
}
public MapEntrySet copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
int index = firstIndex;
@@ -477,6 +491,8 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
return new KeyIterator(fromElement);
}
public KeySet copy() { throw new UnsupportedOperationException(); }
@Override
public int size() {
return LINKED_ENUM_MAP.this.size();
@@ -12,9 +12,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@@ -35,6 +33,7 @@ import speiger.src.collections.PACKAGE.utils.maps.MAPS;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
@@ -52,7 +51,10 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
#endif
#endif
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT
@@ -528,6 +530,18 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return entry.value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
@@ -596,6 +610,21 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return new KeyIterator(findNode(key));
}
public AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE copy() {
AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE set = new AVL_TREE_MAPKV_BRACES();
set.size = size;
if(tree != null) {
set.tree = tree.copy();
Entry KEY_VALUE_GENERIC_TYPE lastFound = null;
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
set.first = lastFound;
lastFound = null;
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
set.last = lastFound;
}
return set;
}
@Override
public SORTED_SET KEY_GENERIC_TYPE keySet() {
return navigableKeySet();
@@ -1119,7 +1148,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
abstract AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE next(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
abstract AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE previous(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
@Override
public NavigableSubMap KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public abstract NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap();
@Override
@@ -1487,10 +1517,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value), input);
action.accept(input, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
@@ -1540,6 +1570,19 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
}
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
subEntry.set(entry.key, entry.value);
if(filter.getBoolean(subEntry)) result++;
}
return result;
}
}
final class SubMapValues extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
@@ -1580,10 +1623,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(entry.value, input);
action.accept(input, entry.value);
}
@Override
@@ -1617,6 +1660,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
return result;
}
}
final class SubMapEntrySetIterator extends SubMapEntryIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -1799,10 +1851,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value), input);
action.accept(input, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
@@ -1916,6 +1968,9 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
}
#endif
@Override
public KeySet KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
return new KeySetKV_BRACES(m.subMap(fromElement, fromInclusive, toElement, toInclusive));
@@ -1992,10 +2047,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
action.accept(entry.key, input);
action.accept(input, entry.key);
}
@Override
@@ -2029,6 +2084,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
if(filter.TEST_VALUE(entry.key)) return entry.key;
return EMPTY_KEY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
if(filter.TEST_VALUE(entry.key)) result++;
return result;
}
}
final class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
@@ -2070,10 +2134,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(entry.value, input);
action.accept(input, entry.value);
}
@Override
@@ -2107,6 +2171,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(AVL_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
return result;
}
}
final class EntryIterator extends MapEntryIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -2266,6 +2339,22 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
this.parent = parent;
}
Entry KEY_VALUE_GENERIC_TYPE copy() {
Entry KEY_VALUE_GENERIC_TYPE entry = new EntryKV_BRACES(key, value, null);
entry.state = state;
if(left != null) {
Entry KEY_VALUE_GENERIC_TYPE newLeft = left.copy();
entry.left = newLeft;
newLeft.parent = entry;
}
if(right != null) {
Entry KEY_VALUE_GENERIC_TYPE newRight = right.copy();
entry.right = newRight;
newRight.parent = entry;
}
return entry;
}
@Override
public KEY_TYPE ENTRY_KEY() {
return key;
@@ -12,9 +12,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#endif
#if !TYPE_OBJECT && !VALUE_BOOLEAN
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
@@ -35,6 +33,7 @@ import speiger.src.collections.PACKAGE.utils.maps.MAPS;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
@@ -52,7 +51,10 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
#endif
#endif
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.consumer.VALUE_BI_OBJECT_CONSUMER;
#if !TYPE_OBJECT
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
#endif
#if !TYPE_OBJECT && !VALUE_OBJECT
@@ -527,6 +529,18 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return entry.value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
@@ -595,6 +609,21 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return new KeyIterator(findNode(key));
}
public RB_TREE_MAP KEY_VALUE_GENERIC_TYPE copy() {
RB_TREE_MAP KEY_VALUE_GENERIC_TYPE set = new RB_TREE_MAPKV_BRACES();
set.size = size;
if(tree != null) {
set.tree = tree.copy();
Entry KEY_VALUE_GENERIC_TYPE lastFound = null;
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
set.first = lastFound;
lastFound = null;
for(Entry KEY_VALUE_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
set.last = lastFound;
}
return set;
}
@Override
public SORTED_SET KEY_GENERIC_TYPE keySet() {
return navigableKeySet();
@@ -1173,6 +1202,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
abstract RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE next(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
abstract RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE previous(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry);
@Override
public NavigableSubMap KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public abstract NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap();
@Override
@@ -1540,10 +1571,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value), input);
action.accept(input, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
@@ -1593,6 +1624,19 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
subEntry.set(entry.key, entry.value);
if(filter.getBoolean(subEntry)) result++;
}
return result;
}
}
final class SubMapValues extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
@@ -1633,10 +1677,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
action.accept(entry.value, input);
action.accept(input, entry.value);
}
@Override
@@ -1670,6 +1714,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = findLowest(), last = findHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
return result;
}
}
final class SubMapEntrySetIterator extends SubMapEntryIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -1852,10 +1905,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
@Override
public <E> void forEach(E input, ObjectObjectConsumer<MAP.Entry KEY_VALUE_GENERIC_TYPE, E> action) {
public <E> void forEach(E input, ObjectObjectConsumer<E, MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
Objects.requireNonNull(action);
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(new BasicEntryKV_BRACES(entry.key, entry.value), input);
action.accept(input, new BasicEntryKV_BRACES(entry.key, entry.value));
}
@Override
@@ -1905,6 +1958,19 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
return null;
}
@Override
public int count(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
BasicEntry KEY_VALUE_GENERIC_TYPE subEntry = new BasicEntryKV_BRACES();
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
subEntry.set(entry.key, entry.value);
if(filter.getBoolean(subEntry)) result++;
}
return result;
}
}
static final class KeySet KEY_VALUE_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements NAVIGABLE_SET KEY_GENERIC_TYPE {
@@ -1969,6 +2035,9 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
#endif
@Override
public KeySet KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
return new KeySetKV_BRACES(m.subMap(fromElement, fromInclusive, toElement, toInclusive));
@@ -2045,10 +2114,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
action.accept(entry.key, input);
action.accept(input, entry.key);
}
@Override
@@ -2082,6 +2151,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
if(filter.TEST_VALUE(entry.key)) return entry.key;
return EMPTY_KEY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
if(filter.TEST_VALUE(entry.key)) result++;
return result;
}
}
final class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
@@ -2123,10 +2201,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
@Override
public <E> void forEach(E input, VALUE_BI_OBJECT_CONSUMER VVS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, VALUE_BI_FROM_OBJECT_CONSUMER VSV_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(entry.value, input);
action.accept(input, entry.value);
}
@Override
@@ -2160,6 +2238,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
if(filter.VALUE_TEST_VALUE(entry.value)) return entry.value;
return EMPTY_VALUE;
}
@Override
public int count(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(RB_TREE_MAP.Entry KEY_VALUE_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
if(filter.VALUE_TEST_VALUE(entry.value)) result++;
return result;
}
}
final class EntryIterator extends MapEntryIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
@@ -2321,6 +2408,22 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
this.parent = parent;
}
Entry KEY_VALUE_GENERIC_TYPE copy() {
Entry KEY_VALUE_GENERIC_TYPE entry = new EntryKV_BRACES(key, value, null);
entry.state = state;
if(left != null) {
Entry KEY_VALUE_GENERIC_TYPE newLeft = left.copy();
entry.left = newLeft;
newLeft.parent = entry;
}
if(right != null) {
Entry KEY_VALUE_GENERIC_TYPE newRight = right.copy();
entry.right = newRight;
newRight.parent = entry;
}
return entry;
}
@Override
public KEY_TYPE ENTRY_KEY() {
return key;
@@ -33,6 +33,7 @@ import speiger.src.collections.PACKAGE.sets.SET;
#if !SAME_TYPE
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
#endif
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
import speiger.src.collections.objects.collections.ObjectIterator;
#if !TYPE_OBJECT
import speiger.src.collections.objects.sets.ObjectSet;
@@ -58,6 +59,15 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
*/
public MAP KEY_VALUE_GENERIC_TYPE setDefaultReturnValue(VALUE_TYPE v);
/**
* A Function that does a shallow clone of the Map itself.
* This function is more optimized then a copy constructor since the Map does not have to be unsorted/resorted.
* It can be compared to Cloneable but with less exception risk
* @return a Shallow Copy of the Map
* @note Wrappers and view Maps will not support this feature
*/
public MAP KEY_VALUE_GENERIC_TYPE copy();
/**
* Type Specific method to reduce boxing/unboxing of values
* @param key the key that should be inserted,
@@ -267,6 +277,14 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
* @return the result of the computed value or present value
*/
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
* @param key the key that should be computed
* @param valueProvider the value if not present
* @return the result of the computed value or present value
*/
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
/**
* A Type Specific compute method to reduce boxing/unboxing
* @param key the key that should be computed
@@ -10,6 +10,8 @@ import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
*/
public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VALUE_GENERIC_TYPE, NavigableMap<CLASS_TYPE, CLASS_VALUE_TYPE>
{
@Override
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy();
/** @return a Type Specific desendingMap */
@Override
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap();
@@ -75,6 +75,9 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator();
@Override
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy();
@Override
public SET KEY_GENERIC_TYPE keySet();
@Override
@@ -0,0 +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();
}
}
@@ -1,7 +1,7 @@
package speiger.src.collections.PACKAGE.queues;
#if TYPE_OBJECT
import java.util.Arrays;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.Consumer;
#endif
@@ -13,7 +13,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.utils.ITrimmable;
@@ -22,7 +22,7 @@ import speiger.src.collections.utils.ITrimmable;
* Its specific implementation uses a backing array that grows and shrinks as it is needed.
* @Type(T)
*/
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
{
/** Max Possible ArraySize without the JVM Crashing */
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
@@ -34,6 +34,8 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
protected int first;
/** The Last Index pointer */
protected int last;
/** The Minimum Capacity of the Queue **/
protected int minCapacity;
/**
* Constructor using a initial array
@@ -62,7 +64,9 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
*/
public ARRAY_FIFO_QUEUE(KEY_TYPE[] values, int offset, int size) {
if (values.length < size) throw new IllegalArgumentException("Initial array (" + values.length + ") is smaller then the expected size (" + size + ")");
if(values.length <= 0) values = NEW_KEY_ARRAY(1);
if(values.length <= 0) values = NEW_KEY_ARRAY(MIN_CAPACITY);
else if(values.length < MIN_CAPACITY) values = Arrays.copyOf(values, MIN_CAPACITY);
minCapacity = MIN_CAPACITY;
array = values;
first = offset;
last = (offset + size) % array.length;
@@ -76,7 +80,8 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
*/
public ARRAY_FIFO_QUEUE(int capacity) {
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
array = NEW_KEY_ARRAY(Math.max(1, capacity));
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity));
minCapacity = array.length;
}
/**
@@ -222,6 +227,16 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
@Override
public void onChanged() {}
@Override
public ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE copy() {
ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_FIFO_QUEUEBRACES();
queue.first = first;
queue.last = last;
queue.minCapacity = minCapacity;
queue.array = Arrays.copyOf(array, array.length);
return queue;
}
@Override
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { return null; }
@@ -235,11 +250,11 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(first == last) return;
for(int i = 0,m=size();i<m;i++)
action.accept(array[(first + i) % array.length], input);
action.accept(input, array[(first + i) % array.length]);
clearAndTrim(0);
}
@@ -284,9 +299,19 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0,m=size();i<m;i++) {
if(filter.TEST_VALUE(array[(first + i) % array.length])) result++;
}
return result;
}
@Override
public boolean trim(int size) {
int newSize = Math.max(size, size());
int newSize = Math.max(Math.max(size, size()), minCapacity);
if(newSize >= array.length) return false;
KEY_TYPE[] newArray = NEW_KEY_ARRAY(newSize);
if(first <= last) System.arraycopy(array, first, newArray, 0, last - first);
@@ -307,7 +332,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
*/
@Override
public void clearAndTrim(int size) {
int newSize = Math.max(MIN_CAPACITY, size);
int newSize = Math.max(minCapacity, size);
if(array.length <= newSize) {
clear();
return;
@@ -329,7 +354,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G
protected void reduce() {
final int size = size();
if (array.length > MIN_CAPACITY && size <= array.length / 4) resize(size, array.length / 2);
if (array.length > minCapacity && size <= array.length / 4) resize(size, Math.max(array.length / 2, minCapacity));
}
protected void expand() {
@@ -14,7 +14,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.utils.ARRAYS;
@@ -24,7 +24,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
* It is highly suggested to use HeapPriorityQueue otherwise, unless you know why you need this specific implementation
* @Type(T)
*/
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
{
/** The Backing Array */
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
@@ -262,9 +262,9 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(int i = 0,m=size;i<m;i++) action.accept(dequeue(), input);
for(int i = 0,m=size;i<m;i++) action.accept(input, dequeue());
}
@Override
@@ -307,11 +307,31 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0;i<size;i++) {
if(filter.TEST_VALUE(array[i])) result++;
}
return result;
}
@Override
public ITERATOR KEY_GENERIC_TYPE iterator() {
return new Iter();
}
@Override
public ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES();
queue.firstIndex = firstIndex;
queue.size = size;
queue.comparator = comparator;
queue.array = Arrays.copyOf(array, array.length);
return queue;
}
@Override
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
return comparator;
@@ -14,7 +14,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.utils.ARRAYS;
@@ -23,7 +23,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
* It is a ArrayBased Alternative to TreeSets that has less object allocations
* @Type(T)
*/
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
{
/** The Backing Array */
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
@@ -249,9 +249,9 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(int i = 0,m=size;i<m;i++) action.accept(dequeue(), input);
for(int i = 0,m=size;i<m;i++) action.accept(input, dequeue());
}
@Override
@@ -294,6 +294,16 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0;i<size;i++) {
if(filter.TEST_VALUE(array[i])) result++;
}
return result;
}
protected boolean removeIndex(int index) {
array[index] = array[--size];
#if TYPE_OBJECT
@@ -309,6 +319,15 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_
ARRAYS.shiftDown(array, size, 0, comparator);
}
@Override
public HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() {
HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES();
queue.size = size;
queue.comparator = comparator;
queue.array = Arrays.copyOf(array, array.length);
return queue;
}
@Override
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() {
return comparator;
@@ -1,5 +1,12 @@
package speiger.src.collections.PACKAGE.queues;
#if TYPE_OBJECT
import java.util.Collection;
import java.util.Iterator;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR;
/**
* A Type Speciifc PriorityDeque or Dequeue interface to allow implementations like FIFO queues.
* @Type(T)
@@ -11,6 +18,56 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
* @param e the element that should be inserted into the first place
*/
public void enqueueFirst(KEY_TYPE e);
/**
* Method to mass insert a elements into the first Index of the PriorityDequeue.
* @param e the elements that should be inserted
*/
public default void enqueueAllFirst(KEY_TYPE... e) {
enqueueAllFirst(e, 0, e.length);
}
/**
* Method to mass insert a elements into the first Index of the PriorityDequeue.
* @param e the elements that should be inserted
* @param length the amount of elements that should be inserted
*/
public default void enqueueAllFirst(KEY_TYPE[] e, int length) {
enqueueAllFirst(e, 0, length);
}
/**
* Method to mass insert a elements into the first Index of the PriorityDequeue.
* @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 enqueueAllFirst(KEY_TYPE[] e, int offset, int length) {
for(int i = 0;i<length;i++)
enqueueFirst(e[i+offset]);
}
/**
* Method to mass insert elements into first Index of the PriorityDequeue.
* @param c the elements that should be inserted from the Collection
*/
public default void enqueueAllFirst(COLLECTION KEY_GENERIC_TYPE c) {
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
enqueueFirst(iter.NEXT());
}
#if TYPE_OBJECT
/**
* Method to mass insert elements into first Index of the PriorityDequeue.
* 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 enqueueAllFirst(Collection<? extends CLASS_TYPE> c) {
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
enqueueFirst(iter.next());
}
#endif
/**
* A Method to remove a element from the last place instead of the first
* @return the last element inserted
@@ -22,4 +79,7 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
* @return the Last Element within the dequeue without deleting it
*/
public default KEY_TYPE last() { return peek(size()-1); }
@Override
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
}
@@ -2,11 +2,14 @@ package speiger.src.collections.PACKAGE.queues;
#if TYPE_OBJECT
import java.util.Comparator;
import speiger.src.collections.objects.collections.ObjectIterator;
import java.util.Collection;
import java.util.Iterator;
#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;
/**
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
@@ -33,6 +36,57 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
* @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
@@ -70,6 +124,15 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
*/
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
*/
@@ -13,7 +13,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR;
@@ -304,10 +304,10 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(entry.key, input);
action.accept(input, entry.key);
}
@Override
@@ -346,6 +346,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
if(filter.TEST_VALUE(entry.key)) result++;
}
return result;
}
protected Entry KEY_GENERIC_TYPE findNode(KEY_TYPE o) {
Entry KEY_GENERIC_TYPE node = tree;
int compare;
@@ -528,6 +538,21 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
tree = null;
}
public AVL_TREE_SET KEY_GENERIC_TYPE copy() {
AVL_TREE_SET KEY_GENERIC_TYPE set = new AVL_TREE_SETBRACES();
set.size = size;
if(tree != null) {
set.tree = tree.copy();
Entry KEY_GENERIC_TYPE lastFound = null;
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
set.first = lastFound;
lastFound = null;
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
set.last = lastFound;
}
return set;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
@@ -999,6 +1024,9 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
}
@Override
public SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
Objects.requireNonNull(action);
@@ -1008,10 +1036,10 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry))
action.accept(entry.key, input);
action.accept(input, entry.key);
}
@Override
@@ -1050,6 +1078,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
if(filter.TEST_VALUE(entry.key)) result++;
}
return result;
}
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE previous;
@@ -1230,6 +1268,22 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
this.parent = parent;
}
Entry KEY_GENERIC_TYPE copy() {
Entry KEY_GENERIC_TYPE entry = new EntryBRACES(key, null);
entry.state = state;
if(left != null) {
Entry KEY_GENERIC_TYPE newLeft = left.copy();
entry.left = newLeft;
newLeft.parent = entry;
}
if(right != null) {
Entry KEY_GENERIC_TYPE newRight = right.copy();
entry.right = newRight;
newRight.parent = entry;
}
return entry;
}
int getHeight() { return state; }
void updateHeight() { state = (1 + Math.max(left == null ? -1 : left.getHeight(), right == null ? -1 : right.getHeight())); }
@@ -15,6 +15,8 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
{
@Override
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
@Override
public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public int hashCode() {
@@ -16,7 +16,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
@@ -350,10 +350,10 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;i++)
action.accept(data[i], input);
action.accept(input, data[i]);
}
@Override
@@ -392,6 +392,16 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0;i<size;i++) {
if(filter.TEST_VALUE(data[i])) result++;
}
return result;
}
#if !TYPE_OBJECT
protected int findIndex(KEY_TYPE o) {
for(int i = size-1;i>=0;i--)
@@ -440,6 +450,13 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
return new SubSet(fromIndex, size - fromIndex);
}
public ARRAY_SET KEY_GENERIC_TYPE copy() {
ARRAY_SET KEY_GENERIC_TYPE set = new ARRAY_SETBRACES();
set.data = Arrays.copyOf(data, data.length);
set.size = size;
return set;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() {
return null;
@@ -665,7 +682,10 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
if(index != -1) return new SetIterator(index);
throw new NoSuchElementException();
}
@Override
public SubSet copy() { throw new UnsupportedOperationException(); }
@Override
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
int fromIndex = findIndex(fromElement);
@@ -4,6 +4,7 @@ package speiger.src.collections.PACKAGE.sets;
import java.util.Comparator;
import java.util.function.Consumer;
#endif
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -16,7 +17,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.utils.ARRAYS;
@@ -50,6 +51,12 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
/** The Last Index in the Map */
protected int lastIndex = -1;
/**
* Helper constructor to optimize the copying
* Only accessible through implementations
*/
protected IMMUTABLE_HASH_SET() {}
/**
* Helper constructor that allow to create a set from unboxed values
* @param array the elements that should be put into the set
@@ -297,11 +304,11 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
int index = firstIndex;
while(index != -1) {
action.accept(keys[index], input);
action.accept(input, keys[index]);
index = (int)links[index];
}
}
@@ -312,6 +319,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) return true;
index = (int)links[index];
}
return false;
}
@@ -322,6 +330,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) return false;
index = (int)links[index];
}
return true;
}
@@ -332,6 +341,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
int index = firstIndex;
while(index != -1) {
if(!filter.TEST_VALUE(keys[index])) return false;
index = (int)links[index];
}
return true;
}
@@ -342,10 +352,23 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) return keys[index];
index = (int)links[index];
}
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) result++;
index = (int)links[index];
}
return result;
}
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
return new SetIterator();
@@ -356,6 +379,20 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
return new SetIterator(fromElement);
}
@Override
public IMMUTABLE_HASH_SET KEY_GENERIC_TYPE copy() {
IMMUTABLE_HASH_SET KEY_GENERIC_TYPE set = new IMMUTABLE_HASH_SETBRACES();
set.containsNull = containsNull;
set.firstIndex = firstIndex;
set.lastIndex = lastIndex;
set.size = size;
set.mask = mask;
set.nullIndex = nullIndex;
set.keys = Arrays.copyOf(keys, keys.length);
set.links = Arrays.copyOf(links, links.length);
return set;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
@@ -4,6 +4,7 @@ package speiger.src.collections.PACKAGE.sets;
import java.util.Comparator;
import java.util.function.Consumer;
#endif
import java.util.Arrays;
import java.util.Objects;
import java.util.Collection;
import java.util.Iterator;
@@ -22,7 +23,7 @@ import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.utils.STRATEGY;
import speiger.src.collections.utils.HashUtil;
@@ -534,11 +535,11 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
int index = firstIndex;
while(index != -1) {
action.accept(keys[index], input);
action.accept(input, keys[index]);
index = (int)links[index];
}
}
@@ -549,6 +550,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) return true;
index = (int)links[index];
}
return false;
}
@@ -559,6 +561,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) return false;
index = (int)links[index];
}
return true;
}
@@ -569,6 +572,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
int index = firstIndex;
while(index != -1) {
if(!filter.TEST_VALUE(keys[index])) return false;
index = (int)links[index];
}
return true;
}
@@ -579,10 +583,23 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) return keys[index];
index = (int)links[index];
}
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) result++;
index = (int)links[index];
}
return result;
}
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
return new SetIterator();
@@ -593,6 +610,22 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
return new SetIterator(fromElement);
}
@Override
public LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE copy() {
LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE set = new LINKED_CUSTOM_HASH_SETBRACES(0, loadFactor, strategy);
set.minCapacity = minCapacity;
set.mask = mask;
set.maxFill = maxFill;
set.nullIndex = nullIndex;
set.containsNull = containsNull;
set.size = size;
set.keys = Arrays.copyOf(keys, keys.length);
set.links = Arrays.copyOf(links, links.length);
set.firstIndex = firstIndex;
set.lastIndex = lastIndex;
return set;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
@@ -3,6 +3,7 @@ package speiger.src.collections.PACKAGE.sets;
#if TYPE_OBJECT
import java.util.Comparator;
#endif
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -20,7 +21,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
#if !TYPE_OBJECT
@@ -389,11 +390,11 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
int index = firstIndex;
while(index != -1) {
action.accept(keys[index], input);
action.accept(input, keys[index]);
index = (int)links[index];
}
}
@@ -404,6 +405,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) return true;
index = (int)links[index];
}
return false;
}
@@ -414,6 +416,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) return false;
index = (int)links[index];
}
return true;
}
@@ -424,6 +427,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
int index = firstIndex;
while(index != -1) {
if(!filter.TEST_VALUE(keys[index])) return false;
index = (int)links[index];
}
return true;
}
@@ -434,10 +438,23 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) return keys[index];
index = (int)links[index];
}
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
int index = firstIndex;
while(index != -1) {
if(filter.TEST_VALUE(keys[index])) result++;
index = (int)links[index];
}
return result;
}
@Override
protected void onNodeAdded(int pos) {
if(size == 0) {
@@ -564,6 +581,22 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
return new SetIterator(fromElement);
}
@Override
public LINKED_HASH_SET KEY_GENERIC_TYPE copy() {
LINKED_HASH_SET KEY_GENERIC_TYPE set = new LINKED_HASH_SETBRACES(0, loadFactor);
set.minCapacity = minCapacity;
set.mask = mask;
set.maxFill = maxFill;
set.nullIndex = nullIndex;
set.containsNull = containsNull;
set.size = size;
set.keys = Arrays.copyOf(keys, keys.length);
set.links = Arrays.copyOf(links, links.length);
set.firstIndex = firstIndex;
set.lastIndex = lastIndex;
return set;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
@@ -115,6 +115,8 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
/** @return a Type Specific desendingSet */
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet();
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE copy();
/**
* A Type Specific Type Splititerator to reduce boxing/unboxing
@@ -2,6 +2,7 @@ package speiger.src.collections.PACKAGE.sets;
import java.util.Arrays;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
@@ -17,7 +18,7 @@ import speiger.src.collections.PACKAGE.lists.LIST;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.utils.STRATEGY;
@@ -429,7 +430,10 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
int newMask = newSize - 1;
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
while(strategy.equals(keys[--i], EMPTY_KEY_VALUE));
while(true) {
if(--i < 0) throw new ConcurrentModificationException("Set was modified during rehash");
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) break;
}
if(!strategy.equals(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask], EMPTY_KEY_VALUE))
while(!strategy.equals(newKeys[pos = (++pos & newMask)], EMPTY_KEY_VALUE));
newKeys[pos] = keys[i];
@@ -445,6 +449,19 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
return new SetIterator();
}
@Override
public CUSTOM_HASH_SET KEY_GENERIC_TYPE copy() {
CUSTOM_HASH_SET KEY_GENERIC_TYPE set = new CUSTOM_HASH_SETBRACES(0, loadFactor, strategy);
set.minCapacity = minCapacity;
set.mask = mask;
set.maxFill = maxFill;
set.nullIndex = nullIndex;
set.containsNull = containsNull;
set.size = size;
set.keys = Arrays.copyOf(keys, keys.length);
return set;
}
@Override
public void clear() {
if(size == 0) return;
@@ -468,12 +485,12 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(keys[nullIndex], input);
if(containsNull) action.accept(input, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i], input);
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, keys[i]);
}
}
@@ -521,6 +538,18 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) result++;
}
return result;
}
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
int pos = nullIndex;
int lastReturned = -1;
@@ -2,6 +2,7 @@ package speiger.src.collections.PACKAGE.sets;
import java.util.Arrays;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
@@ -17,7 +18,7 @@ import speiger.src.collections.PACKAGE.lists.LIST;
import speiger.src.collections.PACKAGE.utils.ITERATORS;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.utils.HashUtil;
import speiger.src.collections.utils.ITrimmable;
@@ -337,12 +338,12 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
if(size() <= 0) return;
if(containsNull) action.accept(keys[nullIndex], input);
if(containsNull) action.accept(input, keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(keys[i], input);
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, keys[i]);
}
}
@@ -390,6 +391,18 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
int result = 0;
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
for(int i = nullIndex-1;i>=0;i--) {
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) result++;
}
return result;
}
private void ensureCapacity(int newCapacity) {
int size = HashUtil.arraySize(newCapacity, loadFactor);
if(size > nullIndex) rehash(size);
@@ -449,7 +462,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
int newMask = newSize - 1;
KEY_TYPE[] newKeys = NEW_KEY_ARRAY(newSize + 1);
for(int i = nullIndex, pos = 0, j = (size - (containsNull ? 1 : 0));j-- != 0;) {
while(KEY_EQUALS_NULL(keys[--i]));
while(true) {
if(--i < 0) throw new ConcurrentModificationException("Set was modified during rehash");
if(KEY_EQUALS_NOT_NULL(keys[i])) break;
}
if(KEY_EQUALS_NOT_NULL(newKeys[pos = HashUtil.mix(KEY_TO_HASH(keys[i])) & newMask]))
while(KEY_EQUALS_NOT_NULL(newKeys[pos = (++pos & newMask)]));
newKeys[pos] = keys[i];
@@ -465,6 +481,19 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
return new SetIterator();
}
@Override
public HASH_SET KEY_GENERIC_TYPE copy() {
HASH_SET KEY_GENERIC_TYPE set = new HASH_SETBRACES(0, loadFactor);
set.minCapacity = minCapacity;
set.mask = mask;
set.maxFill = maxFill;
set.nullIndex = nullIndex;
set.containsNull = containsNull;
set.size = size;
set.keys = Arrays.copyOf(keys, keys.length);
return set;
}
@Override
public void clear() {
if(size == 0) return;
@@ -13,7 +13,7 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.consumer.BI_OBJECT_CONSUMER;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR;
@@ -304,10 +304,10 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next())
action.accept(entry.key, input);
action.accept(input, entry.key);
}
@Override
@@ -346,6 +346,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
if(filter.TEST_VALUE(entry.key)) result++;
}
return result;
}
protected Entry KEY_GENERIC_TYPE findNode(KEY_TYPE o) {
Entry KEY_GENERIC_TYPE node = tree;
int compare;
@@ -530,6 +540,21 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
tree = null;
}
public RB_TREE_SET KEY_GENERIC_TYPE copy() {
RB_TREE_SET KEY_GENERIC_TYPE set = new RB_TREE_SETBRACES();
set.size = size;
if(tree != null) {
set.tree = tree.copy();
Entry KEY_GENERIC_TYPE lastFound = null;
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry;
set.first = lastFound;
lastFound = null;
for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry;
set.last = lastFound;
}
return set;
}
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
@@ -1060,6 +1085,9 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
}
@Override
public SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
Objects.requireNonNull(action);
@@ -1069,10 +1097,10 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
@Override
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
Objects.requireNonNull(action);
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry))
action.accept(entry.key, input);
action.accept(input, entry.key);
}
@Override
@@ -1111,6 +1139,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return EMPTY_VALUE;
}
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
Objects.requireNonNull(filter);
int result = 0;
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
if(filter.TEST_VALUE(entry.key)) result++;
}
return result;
}
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE previous;
@@ -1294,6 +1332,22 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
this.parent = parent;
}
Entry KEY_GENERIC_TYPE copy() {
Entry KEY_GENERIC_TYPE entry = new EntryBRACES(key, null);
entry.state = state;
if(left != null) {
Entry KEY_GENERIC_TYPE newLeft = left.copy();
entry.left = newLeft;
newLeft.parent = entry;
}
if(right != null) {
Entry KEY_GENERIC_TYPE newRight = right.copy();
entry.right = newRight;
newRight.parent = entry;
}
return entry;
}
boolean isBlack() {
return (state & BLACK) != 0;
}
@@ -12,10 +12,13 @@ import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
* @Type(T)
*/
public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GENERIC_TYPE
{
{
@Override
public ITERATOR KEY_GENERIC_TYPE iterator();
@Override
public SET KEY_GENERIC_TYPE copy();
#if !TYPE_OBJECT
/**
* A Type Specific remove function to reduce boxing/unboxing
@@ -60,6 +60,9 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator();
@Override
public SORTED_SET KEY_GENERIC_TYPE copy();
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
/**
@@ -15,7 +15,8 @@ import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.utils.ARRAYS;
#endif
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
/**
* A Helper class for Collections
*/
@@ -92,18 +93,16 @@ public class COLLECTIONS
public boolean add(KEY_TYPE o) { synchronized(mutex) { return c.add(o); } }
@Override
public boolean addAll(Collection<? extends CLASS_TYPE> c) { synchronized(mutex) { return this.c.addAll(c); } }
@Override
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.addAll(c); } }
@Override
public boolean addAll(KEY_TYPE[] e, int offset, int length) { synchronized(mutex) { return c.addAll(e, offset, length); } }
#if !TYPE_OBJECT
@Override
public boolean contains(KEY_TYPE o) { synchronized(mutex) { return c.contains(o); } }
#else
@Override
public boolean contains(Object o) { synchronized(mutex) { return c.contains(o); } }
#endif
@Override
@Primitive
@@ -130,6 +129,9 @@ public class COLLECTIONS
return c.iterator();
}
@Override
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
@Primitive
public boolean remove(Object o) { synchronized(mutex) { return c.remove(o); } }
@@ -179,6 +181,18 @@ public class COLLECTIONS
public boolean equals(Object obj) { synchronized(mutex) { return c.equals(obj); } }
@Override
public String toString() { synchronized(mutex) { return c.toString(); } }
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { synchronized(mutex) { c.forEach(input, action); } }
@Override
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAny(filter); } }
@Override
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesNone(filter); } }
@Override
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAll(filter); } }
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } }
}
/**
@@ -198,6 +212,8 @@ public class COLLECTIONS
public boolean addAll(Collection<? extends CLASS_TYPE> c) { throw new UnsupportedOperationException(); }
@Override
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
@Override
public boolean addAll(KEY_TYPE[] e, int offset, int length) { throw new UnsupportedOperationException(); }
#if !TYPE_OBJECT
@Override
public boolean contains(KEY_TYPE o) { return c.contains(o); }
@@ -222,6 +238,8 @@ public class COLLECTIONS
@Override
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(c.iterator()); }
@Override
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean remove(Object o) { throw new UnsupportedOperationException(); }
@Override
@@ -273,6 +291,18 @@ public class COLLECTIONS
public boolean equals(Object obj) { return c.equals(obj); }
@Override
public String toString() { return c.toString(); }
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { c.forEach(input, action); }
@Override
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAny(filter); }
@Override
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesNone(filter); }
@Override
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAll(filter); }
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) { return c.count(filter); }
}
/**
@@ -285,6 +315,8 @@ public class COLLECTIONS
@Override
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
@Override
public boolean addAll(KEY_TYPE[] e, int offset, int length) { throw new UnsupportedOperationException(); }
#if !TYPE_OBJECT
@Override
@@ -356,5 +388,7 @@ public class COLLECTIONS
public void clear() {}
@Override
public int size() { return 0; }
@Override
public EmptyCollection KEY_GENERIC_TYPE copy() { return this; }
}
}
@@ -14,6 +14,18 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
*/
public class ITERABLES
{
/**
* A Helper function that maps a Java-Iterable into a new Type.
* @param iterable the iterable that should be mapped
* @param mapper the function that decides what the result turns into.
* @Type(T)
* @param <E> The return type.
* @return a iterable that is mapped to a new result
*/
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> map(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
return new MappedIterable<>(wrap(iterable), mapper);
}
/**
* A Helper function that maps a Iterable into a new Type.
* @param iterable the iterable that should be mapped
@@ -26,6 +38,19 @@ public class ITERABLES
return new MappedIterable<>(iterable, mapper);
}
/**
* A Helper function that flatMaps a Java-Iterable into a new Type.
* @param iterable the iterable that should be flatMapped
* @param mapper the function that decides what the result turns into.
* @Type(T)
* @param <V> The return type supplier.
* @param <E> The return type.
* @return a iterable that is flatMapped to a new result
*/
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterable<E> flatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
return new FlatMappedIterable<>(wrap(iterable), mapper);
}
/**
* A Helper function that flatMaps a Iterable into a new Type.
* @param iterable the iterable that should be flatMapped
@@ -39,6 +64,18 @@ public class ITERABLES
return new FlatMappedIterable<>(iterable, mapper);
}
/**
* A Helper function that flatMaps a Java-Iterable into a new Type.
* @param iterable the iterable that should be flatMapped
* @param mapper the function that decides what the result turns into.
* @Type(T)
* @param <E> The return type.
* @return a iterable that is flatMapped to a new result
*/
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> arrayFlatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
return new FlatMappedArrayIterable<>(wrap(iterable), mapper);
}
/**
* A Helper function that flatMaps a Iterable into a new Type.
* @param iterable the iterable that should be flatMapped
@@ -51,6 +88,17 @@ public class ITERABLES
return new FlatMappedArrayIterable<>(iterable, mapper);
}
/**
* A Helper function that filters out all desired elements from a Java-Iterable
* @param iterable that should be filtered.
* @param filter the filter that decides that should be let through
* @Type(T)
* @return a filtered iterable
*/
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE filter(Iterable<? extends CLASS_TYPE> iterable, PREDICATE KEY_GENERIC_TYPE filter) {
return new FilteredIterableBRACES(wrap(iterable), filter);
}
/**
* A Helper function that filters out all desired elements
* @param iterable that should be filtered.
@@ -62,6 +110,29 @@ public class ITERABLES
return new FilteredIterableBRACES(iterable, filter);
}
/**
* A Wrapper function that wraps a Java-Iterable into a Type Specific Iterable
* @param iterable that should be wrapped
* @Type(T)
* @return a type specific iterable
*/
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE wrap(Iterable<? extends CLASS_TYPE> iterable) {
return new WrappedIterableBRACES(iterable);
}
private static class WrappedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
{
Iterable<? extends CLASS_TYPE> iterable;
public WrappedIterable(Iterable<? extends CLASS_TYPE> iterable) {
this.iterable = iterable;
}
public ITERATOR KEY_GENERIC_TYPE iterator() {
return ITERATORS.wrap(iterable.iterator());
}
}
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
{
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
@@ -89,6 +89,18 @@ public class ITERATORS
return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator);
}
/**
* A Helper function that maps a Java-Iterator into a new Type.
* @param iterator that should be mapped
* @param mapper the function that decides what the result turns into.
* @Type(T)
* @param <E> The return type.
* @return a iterator that is mapped to a new result
*/
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterator<E> map(Iterator<? extends CLASS_TYPE> iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
return new MappedIterator<>(wrap(iterator), mapper);
}
/**
* A Helper function that maps a Iterator into a new Type.
* @param iterator that should be mapped
@@ -101,6 +113,19 @@ public class ITERATORS
return new MappedIterator<>(iterator, mapper);
}
/**
* A Helper function that flatMaps a Java-Iterator into a new Type.
* @param iterator that should be flatMapped
* @param mapper the function that decides what the result turns into.
* @Type(T)
* @param <V> The return type supplier.
* @param <E> The return type.
* @return a iterator that is flatMapped to a new result
*/
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterator<E> flatMap(Iterator<? extends CLASS_TYPE> iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
return new FlatMappedIterator<>(wrap(iterator), mapper);
}
/**
* A Helper function that flatMaps a Iterator into a new Type.
* @param iterator that should be flatMapped
@@ -114,6 +139,18 @@ public class ITERATORS
return new FlatMappedIterator<>(iterator, mapper);
}
/**
* A Helper function that flatMaps a Java-Iterator into a new Type.
* @param iterator that should be flatMapped
* @param mapper the function that decides what the result turns into.
* @Type(T)
* @param <E> The return type.
* @return a iterator that is flatMapped to a new result
*/
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterator<E> arrayFlatMap(Iterator<? extends CLASS_TYPE> iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
return new FlatMappedArrayIterator<>(wrap(iterator), mapper);
}
/**
* A Helper function that flatMaps a Iterator into a new Type.
* @param iterator that should be flatMapped
@@ -126,6 +163,17 @@ public class ITERATORS
return new FlatMappedArrayIterator<>(iterator, mapper);
}
/**
* A Helper function that filters out all desired elements from a Java-Iterator
* @param iterator that should be filtered.
* @param filter the filter that decides that should be let through
* @Type(T)
* @return a filtered iterator
*/
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE filter(Iterator<? extends CLASS_TYPE> iterator, PREDICATE KEY_GENERIC_TYPE filter) {
return new FilteredIteratorBRACES(wrap(iterator), filter);
}
/**
* A Helper function that filters out all desired elements
* @param iterator that should be filtered.
@@ -5,6 +5,9 @@ import java.util.Objects;
import java.util.Random;
import java.util.RandomAccess;
import java.util.function.Consumer;
#if PRIMITIVES
import java.nio.JAVA_BUFFER;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION;
#if !TYPE_OBJECT
@@ -204,7 +207,11 @@ public class LISTS
a[offset] = element;
return a;
}
#if PRIMITIVES
@Override
public void fillBuffer(JAVA_BUFFER buffer) { buffer.put(element); }
#endif
@Override
public void removeElements(int from, int to) { throw new UnsupportedOperationException(); }
#if TYPE_OBJECT
@@ -216,6 +223,9 @@ public class LISTS
#endif
@Override
public int size() { return 1; }
@Override
public SingletonList KEY_GENERIC_TYPE copy() { return new SingletonListBRACES(element); }
}
private static class SynchronizedArrayList KEY_GENERIC_TYPE extends SynchronizedList KEY_GENERIC_TYPE implements IARRAY KEY_GENERIC_TYPE
@@ -354,6 +364,9 @@ public class LISTS
@Override
public <K> K[] extractElements(int from, int to, Class<K> clz) { synchronized(mutex) { return l.extractElements(from, to, clz); } }
#endif
#if PRIMITIVES
public void fillBuffer(JAVA_BUFFER buffer) { synchronized(mutex) { l.fillBuffer(buffer); } }
#endif
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
@@ -372,6 +385,9 @@ public class LISTS
@Override
public void size(int size) { synchronized(mutex) { l.size(size); } }
@Override
public LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
}
private static class UnmodifiableRandomList KEY_GENERIC_TYPE extends UnmodifiableList KEY_GENERIC_TYPE implements RandomAccess
@@ -463,6 +479,10 @@ public class LISTS
@Override
public <K> K[] extractElements(int from, int to, Class<K> clz) { throw new UnsupportedOperationException(); }
#endif
#if PRIMITIVES
public void fillBuffer(JAVA_BUFFER buffer) { l.fillBuffer(buffer); }
#endif
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
@@ -481,6 +501,9 @@ public class LISTS
@Override
public void size(int size) { throw new UnsupportedOperationException(); }
@Override
public LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
}
private static class EmptyList KEY_GENERIC_TYPE extends COLLECTIONS.EmptyCollection KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
@@ -563,5 +586,8 @@ public class LISTS
@Override
public void size(int size) { throw new UnsupportedOperationException(); }
@Override
public EmptyList KEY_GENERIC_TYPE copy() { return this; }
}
}
@@ -1,15 +1,23 @@
package speiger.src.collections.PACKAGE.utils;
#if TYPE_OBJECT
import java.util.Collection;
import java.util.Comparator;
import java.util.function.Consumer;
#endif
import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.collections.COLLECTION;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
/**
* A Helper class for PriorityQueues
@@ -86,6 +94,14 @@ public class PRIORITY_QUEUES
public void clear() { synchronized(mutex) { queue.clear(); } }
@Override
public void enqueue(KEY_TYPE e) { synchronized(mutex) { queue.enqueue(e); } }
@Override
public void enqueueAll(KEY_TYPE[] e, int offset, int length) { synchronized(mutex) { queue.enqueueAll(e, offset, length); } }
@Override
public void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { queue.enqueueAll(c); } }
#if TYPE_OBJECT
@Override
public void enqueueAll(Collection<? extends CLASS_TYPE> c) { synchronized(mutex) { queue.enqueueAll(c); } }
#endif
@Override
public KEY_TYPE dequeue() { synchronized(mutex) { return queue.dequeue(); } }
@Override
@@ -100,6 +116,22 @@ public class PRIORITY_QUEUES
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { synchronized(mutex) { return queue.comparator(); } }
@Override
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } }
@Override
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(action); } }
@Override
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { synchronized(mutex) { queue.forEach(input, action); } }
@Override
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAny(filter); } }
@Override
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesNone(filter); } }
@Override
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAll(filter); } }
@Override
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.findFirst(filter); } }
@Override
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
}
/**
@@ -121,7 +153,17 @@ public class PRIORITY_QUEUES
@Override
public void enqueueFirst(KEY_TYPE e) { synchronized(mutex) { dequeue.enqueueFirst(e); } }
@Override
public void enqueueAllFirst(KEY_TYPE[] e, int offset, int length) { synchronized(mutex) { dequeue.enqueueAllFirst(e, offset, length); } }
@Override
public void enqueueAllFirst(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { dequeue.enqueueAllFirst(c); } }
#if TYPE_OBJECT
@Override
public void enqueueAllFirst(Collection<? extends CLASS_TYPE> c) { synchronized(mutex) { dequeue.enqueueAllFirst(c); } }
#endif
@Override
public KEY_TYPE dequeueLast() { synchronized(mutex) { return dequeue.dequeueLast(); } }
@Override
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
}
}
@@ -190,6 +190,9 @@ public class SETS
}
@Override
public int size() { return 1; }
@Override
public SingletonSet KEY_GENERIC_TYPE copy() { return new SingletonSetBRACES(element); }
}
private static class EmptySet KEY_GENERIC_TYPE extends EmptyCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
@@ -198,6 +201,8 @@ public class SETS
@Override
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
#endif
@Override
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
}
#if !TYPE_BOOLEAN
@@ -245,6 +250,9 @@ public class SETS
public KEY_TYPE getDefaultMinValue() { return n.getDefaultMinValue(); }
#endif
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
@@ -300,6 +308,9 @@ public class SETS
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
@Override
public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(s.subSet(fromElement, toElement)); }
@@ -336,6 +347,9 @@ public class SETS
s = c;
}
@Override
public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
#if !TYPE_OBJECT
@Override
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@@ -412,6 +426,9 @@ public class SETS
public KEY_TYPE getDefaultMinValue() { synchronized(mutex) { return n.getDefaultMinValue(); } }
#endif
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } }
@@ -492,7 +509,10 @@ public class SETS
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
@Override
public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.subSet(fromElement, toElement), mutex); } }
@@ -556,6 +576,9 @@ public class SETS
#endif
}
@Override
public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
#if !TYPE_OBJECT
@Override
public boolean remove(KEY_TYPE o) { synchronized(mutex) { return s.remove(o); } }
@@ -277,6 +277,8 @@ public class MAPS
@Override
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EQUALS_KEY_TYPE(key, this.key) ? value : defaultValue; }
#endif
@Override
public SingletonMap KEY_VALUE_GENERIC_TYPE copy() { return new SingletonMapKV_BRACES(key, value); }
@Override
public SET KEY_GENERIC_TYPE keySet() {
if(keySet == null) keySet = SETS.singleton(key);
@@ -329,6 +331,8 @@ public class MAPS
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() { return VALUE_COLLECTIONS.empty(); }
@Override
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() { return ObjectSets.empty(); }
@Override
public EmptyMap KEY_VALUE_GENERIC_TYPE copy() { return this; }
}
/**
@@ -415,6 +419,8 @@ public class MAPS
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { return unmodifiable(map.floorEntry(key)); }
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return unmodifiable(map.ceilingEntry(key)); }
@Override
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
}
/**
@@ -462,6 +468,8 @@ public class MAPS
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
@Override
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
@Override
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
}
/**
@@ -501,6 +509,8 @@ public class MAPS
@Override
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
#endif
@Override
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public SET KEY_GENERIC_TYPE keySet() {
@@ -614,7 +624,9 @@ public class MAPS
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { synchronized(mutex) { return map.floorEntry(key); } }
@Override
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { synchronized(mutex) { return map.ceilingEntry(key); } }
#if !TYPE_OBJECT
@Override
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
#if !TYPE_OBJECT
@Override
@Deprecated
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
@@ -718,6 +730,8 @@ public class MAPS
public VALUE_TYPE FIRST_ENTRY_VALUE() { synchronized(mutex) { return map.FIRST_ENTRY_VALUE(); } }
@Override
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
@Override
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
#if !TYPE_OBJECT
@Override
@Deprecated
@@ -831,6 +845,8 @@ public class MAPS
@Override
public int size() { synchronized(mutex) { return super.size(); } }
@Override
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
@Override
public SET KEY_GENERIC_TYPE keySet() {
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
return keys;
@@ -135,6 +135,16 @@ public abstract class BaseInt2IntMapTest
Assert.assertTrue(map.remove(PUT_VALUE_ARRAY[51], PUT_ARRAY[51]));
}
@Test
public void testSort()
{
if(!getValidMapTests().contains(MapTests.COPY)) return;
Int2IntMap map = createMap(TEST_ARRAY, TEST_ARRAY);
Int2IntMap copy = map.copy();
Assert.assertFalse(map == copy);
Assert.assertEquals(map, copy);
}
public static class Strategy implements IntStrategy
{
@Override
@@ -178,4 +178,13 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
Assert.assertEquals(base, IntCollections.synchronize(collection).toString());
Assert.assertEquals(base, IntCollections.unmodifiable(collection).toString());
}
@Test
public void testCopy() {
if(!getValidCollectionTests().contains(CollectionTest.COPY)) return;
IntCollection collection = create(BULK_ADD_ARRAY);
IntCollection copy = collection.copy();
Assert.assertFalse(collection == copy);
Assert.assertEquals(collection, copy);
}
}
@@ -120,4 +120,13 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
}
}
}
@Test
public void testCopy() {
if(!getValidPriorityQueueTests().contains(PriorityQueueTest.COPY)) return;
IntPriorityQueue queue = create(TEST_ARRAY);
IntPriorityQueue copy = queue.copy();
Assert.assertFalse(queue == copy);
Assert.assertEquals(queue, copy);
}
}
@@ -22,6 +22,13 @@ public class ObjectArrayListTest
testCastable(ObjectArrayList.wrap("Test", "Testing", "Testing stuff"), true);
}
@Test
public void testEmptyCreation()
{
ObjectArrayList<String> test = ObjectArrayList.of(String.class);
Assert.assertTrue(test.isCastable());
}
public <T> void testCastable(IObjectArray<T> castable, boolean result)
{
Assert.assertTrue(castable.isCastable() == result);
@@ -15,5 +15,6 @@ public enum CollectionTest
TO_ARRAY,
CLEAR,
WRAPPER,
TO_STRING;
TO_STRING,
COPY;
}
@@ -11,5 +11,6 @@ public enum MapTests
MERGE,
GET,
ITERATORS,
REMOVE;
REMOVE,
COPY;
}
@@ -7,4 +7,5 @@ public enum PriorityQueueTest
PEEK,
REMOVE,
TO_ARRAY,
COPY;
}