4 Commits
Author SHA1 Message Date
Speiger 6afed5e174 Version Bump 2023-06-29 22:52:44 +02:00
Speiger 640a1a8161 Fixed tests and added missing changelog 2023-06-29 20:04:45 +02:00
Speiger 274d37c4d6 New Features.
-Added: List.indexedIterator which allows you to create a iterator with a customized iteration indecies. Useful if you want to transform lists output.
-Added: PriorityQueue.contains is now a function
-Added: Iterators/Async Builders now support MapToPrimitiveType function on the object variant. So more processing can be done. (Will be expanded upon later versions)
-Updated: SimpleCodeGenerator 1.3.0 is now being used which allows for iterative code support.
2023-06-29 18:30:22 +02:00
Speiger a89c812c06 Added Infinite Iterators 2023-06-17 01:22:56 +02:00
2147 changed files with 3482 additions and 1667771 deletions
+9 -1
View File
@@ -20,7 +20,15 @@ gradle-app.setting
/bin/
/storage/
#Generated Code
/src/main/java/speiger/src/collections/booleans/*
/src/main/java/speiger/src/collections/bytes/*
/src/main/java/speiger/src/collections/shorts/*
/src/main/java/speiger/src/collections/chars/*
/src/main/java/speiger/src/collections/ints/*
/src/main/java/speiger/src/collections/longs/*
/src/main/java/speiger/src/collections/floats/*
/src/main/java/speiger/src/collections/doubles/*
/src/main/java/speiger/src/collections/objects/*
#Generated Tests
/src/test/java/speiger/src/testers/booleans/*
+6
View File
@@ -6,8 +6,14 @@
- Added: ToArray/pushTop functions to Stack.class.
- Added: ComputeNonDefault functions which will contain the current behavior of the Compute function, while the Compute will be changed to be more java compliant!
- Added: List.reversed, which returns a SubList that has all elements in reversed order and also inserts reversed.
- Added: Iterators.infinite as an option that will create a Infinite Iterator based on the inputed one.
- Added: List.indexedIterator which allows you to create a iterator with a customized iteration indecies. Useful if you want to transform lists output.
- Added: PriorityQueue.contains is now a function
- Added: Iterators/Async Builders now support MapToPrimitiveType function on the object variant. So more processing can be done. (Will be expanded upon later versions)
- Fixed: SetValue wasn't working on forEach implementations.
- Fixed: Compute functions now perform with primitives more java compliant. Meaning that getDefaultReturnValue function no longer is seen as null.
- Fixed: Supplier was using the wrong dataType in their function name.
- Updated: SimpleCodeGenerator 1.3.0 is now being used which allows for iterative code support.
### Version 0.8.0
- Added: getFirst/getLast/removeFirst/removeLast to Lists
+1 -1
View File
@@ -50,7 +50,7 @@ repositories {
}
}
dependencies {
implementation 'com.github.Speiger:Primitive-Collections:0.7.0'
implementation 'com.github.Speiger:Primitive-Collections:0.9.0'
}
```
+2 -2
View File
@@ -19,7 +19,7 @@ repositories {
}
archivesBaseName = 'Primitive Collections'
version = '0.8.0';
version = '0.9.0';
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
@@ -46,7 +46,7 @@ configurations {
dependencies {
builderImplementation 'com.google.code.gson:gson:2.10'
builderImplementation 'de.speiger:Simple-Code-Generator:1.2.2'
builderImplementation 'de.speiger:Simple-Code-Generator:1.3.0'
testImplementation 'junit:junit:4.12'
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
@@ -45,23 +45,19 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
SettingsManager manager = new SettingsManager();
int flags;
public PrimitiveCollectionsBuilder()
{
public PrimitiveCollectionsBuilder() {
this(false);
}
public PrimitiveCollectionsBuilder(boolean silencedSuccess)
{
public PrimitiveCollectionsBuilder(boolean silencedSuccess) {
super(silencedSuccess, Paths.get("src/builder/resources/speiger/assets/collections/templates/"), Paths.get("src/main/java/speiger/src/collections/"), Paths.get("src/builder/resources/speiger/assets/collections/"));
}
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
{
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder) {
this(false, sourceFolder, outputFolder, dataFolder);
}
public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder)
{
public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder) {
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
}
@@ -88,42 +84,24 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
}
@Override
protected boolean isFileValid(Path fileName)
{
return true;
}
protected boolean isFileValid(Path fileName) { return true; }
@Override
protected boolean relativePackages() { return true; }
@Override
protected boolean debugUnusedMappers() { return false; }
@Override
protected boolean relativePackages()
{
return true;
}
@Override
protected boolean debugUnusedMappers()
{
return false;
}
@Override
protected void afterFinish()
{
if((flags & SPECIAL) == 0 && getVersion() > 8)
{
protected void afterFinish() {
if((flags & SPECIAL) == 0 && getVersion() > 8) {
Path basePath = Paths.get("src/main/java");
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
{
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java"))) {
writer.write(getModuleInfo(basePath));
}
catch(Exception e)
{
e.printStackTrace();
}
catch(Exception e) { e.printStackTrace(); }
}
}
public List<BaseModule> createModules()
{
public List<BaseModule> createModules() {
List<BaseModule> modules = new ArrayList<>();
modules.add(JavaModule.INSTANCE);
modules.add(FunctionModule.INSTANCE);
@@ -139,38 +117,31 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
@Override
protected void init()
{
protected void init() {
prepPackages();
//Init Modules here
addModules(createModules());
finishPackages();
}
public void addModules(List<BaseModule> modules)
{
public void addModules(List<BaseModule> modules) {
for(int i = 0,m=modules.size();i<m;i++) {
modules.get(i).setManager(manager);
}
for(int i = 0,m=modules.size();i<m;i++) {
biPackages.forEach(modules.get(i)::init);
}
for(int i = 0,m=modules.size();i<m;i++) {
modules.get(i).cleanup();
}
modules.forEach(BaseModule::cleanup);
}
private void finishPackages()
{
private void finishPackages() {
biPackages.forEach(ModulePackage::finish);
if((flags & SAVE) != 0) manager.save();
}
private void prepPackages()
{
private void prepPackages() {
if((flags & LOAD) != 0) manager.load();
for(ModulePackage entry : ModulePackage.createPackages(globalFlags))
{
for(ModulePackage entry : ModulePackage.createPackages(globalFlags)) {
entry.setRequirements(requirements::put);
biPackages.add(entry);
if(entry.isSame()) simplePackages.add(entry);
@@ -179,11 +150,9 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
}
@Override
public void createProcesses(String fileName, Consumer<TemplateProcess> process)
{
public void createProcesses(String fileName, Consumer<TemplateProcess> process) {
List<ModulePackage> packages = getPackagesByRequirement(requirements.get(fileName));
for(int i = 0,m=packages.size();i<m;i++)
{
for(int i = 0,m=packages.size();i<m;i++) {
packages.get(i).process(fileName, process);
}
}
@@ -197,8 +166,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
private String getModuleInfo(Path basePath) {
StringJoiner joiner = new StringJoiner("\n", "", "\n");
try(Stream<Path> stream = Files.walk(getOutputFolder()))
{
try(Stream<Path> stream = Files.walk(getOutputFolder())) {
stream.filter(Files::isDirectory)
.filter(this::containsFiles)
.map(basePath::relativize)
@@ -206,8 +174,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
.map(this::sanitize)
.forEach(T -> joiner.add("\texports "+T+";"));
}
catch(Exception e)
{
catch(Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
@@ -218,34 +185,26 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
return builder.toString();
}
private String sanitize(String input)
{
private String sanitize(String input) {
return input.replace("\\", ".").replace("/", ".");
}
private boolean containsFiles(Path path)
{
try(Stream<Path> stream = Files.walk(path, 1))
{
private boolean containsFiles(Path path) {
try(Stream<Path> stream = Files.walk(path, 1)) {
return stream.filter(Files::isRegularFile).findFirst().isPresent();
}
catch(Exception e)
{
e.printStackTrace();
}
catch(Exception e) { e.printStackTrace(); }
return false;
}
private int getVersion()
{
private int getVersion() {
String version = System.getProperty("java.version");
if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3));
int dot = version.indexOf(".");
return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version);
}
public static void main(String...args)
{
public static void main(String...args) {
try
{
Set<String> flags = new HashSet<>(Arrays.asList(args));
@@ -59,6 +59,9 @@ public abstract class BaseModule
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return Collections.emptySet(); }
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; }
public ClassType keyType() { return keyType; }
public ClassType valueType() { return valueType; }
protected boolean isModuleEnabled() {
return manager == null || manager.isModuleEnabled(this, keyType, valueType);
}
@@ -54,8 +54,8 @@ public class FunctionModule extends BaseModule
protected void loadFunctions()
{
addSimpleMapper("APPLY", keyType.getApply(valueType));
addSimpleMapper("SUPPLY_GET", keyType.isObject() ? "get" : "getAs"+keyType.getCustomJDKType().getNonFileType());
addSimpleMapper("VALUE_SUPPLY_GET", valueType.isObject() ? "get" : "getAs"+valueType.getCustomJDKType().getNonFileType());
addSimpleMapper("SUPPLY_GET", keyType.isObject() ? "get" : "getAs"+keyType.getNonFileType());
addSimpleMapper("VALUE_SUPPLY_GET", valueType.isObject() ? "get" : "getAs"+valueType.getNonFileType());
}
@Override
@@ -108,6 +108,9 @@ public class MapModule extends BaseModule
addBlockedFiles("TestOrderedMapGenerator");
addBlockedFilter(T -> T.endsWith("Tester") && (T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap")));
}
if(valueType == ClassType.OBJECT) {
addBlockedFiles("MapComputeIfAbsentNonDefaultTester", "MapComputeIfPresentNonDefaultTester", "MapComputeNonDefaultTester", "MapSupplyIfAbsentNonDefaultTester");
}
}
@Override
@@ -158,6 +161,9 @@ public class MapModule extends BaseModule
addBiRequirement("MapComputeIfAbsentTester");
addBiRequirement("MapComputeIfPresentTester");
addBiRequirement("MapComputeTester");
addBiRequirement("MapComputeIfAbsentNonDefaultTester");
addBiRequirement("MapComputeIfPresentNonDefaultTester");
addBiRequirement("MapComputeNonDefaultTester");
addBiRequirement("MapCopyTester");
addBiRequirement("MapContainsTester");
addBiRequirement("MapContainsKeyTester");
@@ -184,6 +190,7 @@ public class MapModule extends BaseModule
addBiRequirement("MapReplaceTester");
addBiRequirement("MapSizeTester");
addBiRequirement("MapSupplyIfAbsentTester");
addBiRequirement("MapSupplyIfAbsentNonDefaultTester");
addBiRequirement("MapToStringTester");
addBiRequirement("NavigableMapNavigationTester");
addBiRequirement("SortedMapNavigationTester");
@@ -16,6 +16,19 @@ import java.util.function.BiFunction;
import java.util.function.IntFunction;
import java.util.Comparator;
#if BOOLEAN_COLLECTION_MODULE
import speiger.src.collections.booleans.collections.BooleanIterable;
#endif
#iterate
#argument OUTPUT_ITERABLE ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument PACKAGE bytes shorts ints longs floats doubles
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
#if FILTER_TYPE
import speiger.src.collections.objects.functions.function.MAPPER;
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERABLE;
#endif
#enditerate
#endif
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
@@ -165,6 +178,25 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
return ITERABLES.map(this, mapper);
}
#if TYPE_OBJECT
#iterate
#argument OUTPUT_ITERABLE BooleanIterable ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
#if FILTER_TYPE
/**
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
* @param mapper the mapping function
* @return a new Iterable that returns the desired result
*/
default OUTPUT_ITERABLE mapToDATA_TYPE(MAPPER<T> mapper) {
return ITERABLES.mapToDATA_TYPE(this, mapper);
}
#endif
#enditerate
#endif
/**
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
* @param mapper the flatMapping function
@@ -12,6 +12,9 @@ import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
#if INT_LIST_MODULE && !TYPE_INT
import speiger.src.collections.ints.lists.IntList;
#endif
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
import speiger.src.collections.utils.SanityChecks;
@@ -243,6 +246,18 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
return new LIST_ITER(index);
}
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
return new IndexedIterator(indecies);
}
#if INT_LIST_MODULE
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
return new ListIndexedIterator(indecies);
}
#endif
@Override
public void size(int size) {
while(size > size()) add(EMPTY_KEY_VALUE);
@@ -629,6 +644,154 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
}
}
#if INT_LIST_MODULE
private class ListIndexedIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
IntList indecies;
int index;
int lastReturned = -1;
ListIndexedIterator(IntList indecies) {
this.indecies = indecies;
}
@Override
public boolean hasNext() {
return index < indecies.size();
}
@Override
public KEY_TYPE NEXT() {
if(!hasNext()) throw new NoSuchElementException();
int i = index++;
return GET_KEY((lastReturned = indecies.getInt(i)));
}
@Override
public boolean hasPrevious() {
return index > 0;
}
@Override
public KEY_TYPE PREVIOUS() {
if(!hasPrevious()) throw new NoSuchElementException();
index--;
return GET_KEY((lastReturned = indecies.getInt(index)));
}
@Override
public int nextIndex() {
return index;
}
@Override
public int previousIndex() {
return index-1;
}
@Override
public void remove() { throw new UnsupportedOperationException(); }
@Override
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
@Override
public void set(KEY_TYPE e) {
if(lastReturned == -1) throw new IllegalStateException();
ABSTRACT_LIST.this.set(lastReturned, e);
}
@Override
public int skip(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, indecies.size() - index);
index += steps;
if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1);
return steps;
}
@Override
public int back(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, index);
index -= steps;
if(steps > 0) lastReturned = Math.max(index, 0);
return steps;
}
}
#endif
private class IndexedIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
int[] indecies;
int index;
int lastReturned = -1;
IndexedIterator(int[] indecies) {
this.indecies = indecies;
}
@Override
public boolean hasNext() {
return index < indecies.length;
}
@Override
public KEY_TYPE NEXT() {
if(!hasNext()) throw new NoSuchElementException();
int i = index++;
return GET_KEY((lastReturned = indecies[i]));
}
@Override
public boolean hasPrevious() {
return index > 0;
}
@Override
public KEY_TYPE PREVIOUS() {
if(!hasPrevious()) throw new NoSuchElementException();
index--;
return GET_KEY((lastReturned = indecies[index]));
}
@Override
public int nextIndex() {
return index;
}
@Override
public int previousIndex() {
return index-1;
}
@Override
public void remove() { throw new UnsupportedOperationException(); }
@Override
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
@Override
public void set(KEY_TYPE e) {
if(lastReturned == -1) throw new IllegalStateException();
ABSTRACT_LIST.this.set(lastReturned, e);
}
@Override
public int skip(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, indecies.length - index);
index += steps;
if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1);
return steps;
}
@Override
public int back(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, index);
index -= steps;
if(steps > 0) lastReturned = Math.max(index, 0);
return steps;
}
}
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
int index;
int lastReturned = -1;
@@ -706,7 +869,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, index);
index -= steps;
if(steps > 0) lastReturned = Math.min(index, size()-1);
if(steps > 0) lastReturned = Math.max(index, 0);
return steps;
}
}
@@ -24,6 +24,9 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
#if LISTS_FEATURE
import speiger.src.collections.PACKAGE.utils.LISTS;
#endif
#if INT_LIST_MODULE && !TYPE_INT
import speiger.src.collections.ints.lists.IntList;
#endif
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
import speiger.src.collections.utils.SanityChecks;
@@ -425,6 +428,26 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index);
/**
* Creates a Iterator that follows the indecies provided.<br>
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
* @param indecies that should be used for the iteration.
* @return a custom indexed iterator
*/
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies);
#if INT_LIST_MODULE
/**
* Creates a Iterator that follows the indecies provided.<br>
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
* @param indecies that should be used for the iteration.
* @return a custom indexed iterator
*/
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies);
#endif
/**
* A Type-Specific List of subList
* @see java.util.List#subList(int, int)
@@ -218,22 +218,6 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
return newValue;
}
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
VALUE_TYPE value = GET_VALUE(key);
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
if(VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key)) {
remove(key);
return getDefaultReturnValue();
}
return getDefaultReturnValue();
}
put(key, newValue);
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -257,20 +241,6 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
#endif
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
VALUE_TYPE value;
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
put(key, newValue);
return newValue;
}
}
return value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -294,20 +264,6 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
#endif
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(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_SUPPLY_GET();
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);
@@ -331,6 +287,51 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
return getDefaultReturnValue();
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
VALUE_TYPE value = GET_VALUE(key);
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
if(VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key)) {
remove(key);
return getDefaultReturnValue();
}
return getDefaultReturnValue();
}
put(key, newValue);
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
VALUE_TYPE value;
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
put(key, newValue);
return newValue;
}
}
return value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(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_SUPPLY_GET();
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
put(key, newValue);
return newValue;
}
}
return value;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -346,6 +347,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
return getDefaultReturnValue();
}
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -518,13 +518,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
return getSegment(hash).compute(hash, key, mappingFunction);
}
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int hash = getHashCode(key);
return getSegment(hash).computeNonDefault(hash, key, mappingFunction);
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -532,13 +525,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
return getSegment(hash).computeIfAbsent(hash, key, mappingFunction);
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int hash = getHashCode(key);
return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction);
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -546,13 +532,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
return getSegment(hash).supplyIfAbsent(hash, key, valueProvider);
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
int hash = getHashCode(key);
return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider);
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -560,6 +539,28 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
return getSegment(hash).computeIfPresent(hash, key, mappingFunction);
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int hash = getHashCode(key);
return getSegment(hash).computeNonDefault(hash, key, mappingFunction);
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int hash = getHashCode(key);
return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction);
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
int hash = getHashCode(key);
return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider);
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -567,6 +568,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction);
}
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -2269,29 +2271,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
}
}
protected VALUE_TYPE computeNonDefault(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
long stamp = writeLock();
try {
int index = findIndex(hash, key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
values[index] = newValue;
return newValue;
}
finally {
unlockWrite(stamp);
}
}
protected VALUE_TYPE computeIfAbsent(int hash, KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
long stamp = writeLock();
try {
@@ -2319,29 +2298,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
}
}
protected VALUE_TYPE computeIfAbsentNonDefault(int hash, KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
long stamp = writeLock();
try {
int index = findIndex(hash, key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
finally {
unlockWrite(stamp);
}
}
protected VALUE_TYPE supplyIfAbsent(int hash, KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
long stamp = writeLock();
try {
@@ -2369,29 +2325,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
}
}
protected VALUE_TYPE supplyIfAbsentNonDefault(int hash, KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
long stamp = writeLock();
try {
int index = findIndex(hash, key);
if(index < 0) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
finally {
unlockWrite(stamp);
}
}
protected VALUE_TYPE computeIfPresent(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
long stamp = writeLock();
try {
@@ -2415,6 +2348,76 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
}
}
protected VALUE_TYPE computeNonDefault(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
long stamp = writeLock();
try {
int index = findIndex(hash, key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
values[index] = newValue;
return newValue;
}
finally {
unlockWrite(stamp);
}
}
#if !VALUE_OBJECT
protected VALUE_TYPE computeIfAbsentNonDefault(int hash, KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
long stamp = writeLock();
try {
int index = findIndex(hash, key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
finally {
unlockWrite(stamp);
}
}
protected VALUE_TYPE supplyIfAbsentNonDefault(int hash, KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
long stamp = writeLock();
try {
int index = findIndex(hash, key);
if(index < 0) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
finally {
unlockWrite(stamp);
}
}
protected VALUE_TYPE computeIfPresentNonDefault(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
long stamp = writeLock();
try {
@@ -2433,6 +2436,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
}
}
#endif
protected VALUE_TYPE merge(int hash, KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
long stamp = writeLock();
try {
@@ -554,25 +554,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return newValue;
}
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -596,25 +577,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -638,6 +600,64 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
#if !VALUE_OBJECT
if(index < 0) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
#else
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
#endif
values[index] = newValue;
return newValue;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -657,25 +677,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
#if !VALUE_OBJECT
if(index < 0) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
#else
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
#endif
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -690,6 +691,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return newValue;
}
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -514,25 +514,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return newValue;
}
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -556,25 +537,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -598,6 +560,64 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
#if !VALUE_OBJECT
if(index < 0) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
#else
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
#endif
values[index] = newValue;
return newValue;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index < 0) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insert(-index-1, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -617,25 +637,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
#if !VALUE_OBJECT
if(index < 0) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
#else
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
#endif
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -650,6 +651,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return newValue;
}
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -494,20 +494,21 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
@Override
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(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(); }
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(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(); }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@@ -512,25 +512,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return newValue;
}
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index == -1) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insertIndex(size++, key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -554,25 +535,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index == -1) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insertIndex(size++, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -596,6 +558,64 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
#if !VALUE_OBJECT
if(index == -1) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
#else
if(index == -1 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
#endif
values[index] = newValue;
return newValue;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index == -1) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insertIndex(size++, key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
if(index == -1) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
insertIndex(size++, key, newValue);
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -615,25 +635,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
int index = findIndex(key);
#if !VALUE_OBJECT
if(index == -1) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
#else
if(index == -1 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeIndex(index);
return newValue;
}
#endif
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -648,6 +649,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return newValue;
}
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -382,26 +382,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
return newValue;
}
@Override
public VALUE_TYPE COMPUTENonDefault(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = key.ordinal();
if(!isSet(index)) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
set(index);
values[index] = newValue;
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
clear(index);
values[index] = EMPTY_VALUE;
return newValue;
}
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = key.ordinal();
@@ -425,25 +405,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = key.ordinal();
if(!isSet(index)) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
set(index);
values[index] = newValue;
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
int index = key.ordinal();
@@ -467,6 +428,65 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = key.ordinal();
#if !VALUE_OBJECT
if(!isSet(index)) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
#else
if(!isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
clear(index);
values[index] = EMPTY_VALUE;
return newValue;
}
#endif
values[index] = newValue;
return newValue;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = key.ordinal();
if(!isSet(index)) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
set(index);
values[index] = newValue;
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
clear(index);
values[index] = EMPTY_VALUE;
return newValue;
}
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = key.ordinal();
if(!isSet(index)) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
set(index);
values[index] = newValue;
return newValue;
}
VALUE_TYPE newValue = values[index];
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
values[index] = newValue;
}
return newValue;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
int index = key.ordinal();
@@ -486,25 +506,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = key.ordinal();
#if !VALUE_OBJECT
if(!isSet(index)) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
#else
if(!isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
clear(index);
values[index] = EMPTY_VALUE;
return newValue;
}
#endif
values[index] = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
int index = key.ordinal();
@@ -519,6 +520,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
return newValue;
}
#endif
@Override
public VALUE_TYPE MERGE(T key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
int index = key.ordinal();
@@ -567,28 +567,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return newValue;
}
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeNode(entry);
return newValue;
}
entry.value = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -614,27 +592,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return entry.value;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
if(Objects.equals(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -660,27 +617,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return entry.value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -703,6 +639,71 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return newValue;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeNode(entry);
return newValue;
}
entry.value = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
if(Objects.equals(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -720,6 +721,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return newValue;
}
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -1769,6 +1771,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
#endif
if(!inRange(key)) return getDefaultReturnValue();
Node KEY_VALUE_GENERIC_TYPE entry = map.findNode(key);
#if VALUE_OBJECT
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.apply(key, entry.value);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
@@ -1777,6 +1780,11 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
}
entry.value = newValue;
return newValue;
#else
if(entry == null) return getDefaultReturnValue();
entry.value = mappingFunction.apply(key, entry.value);
return entry.value;
#endif
}
@Override
@@ -569,28 +569,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return newValue;
}
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeNode(entry);
return newValue;
}
entry.value = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -616,27 +594,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return entry.value;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
if(Objects.equals(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
@@ -662,27 +619,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return entry.value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -705,6 +641,71 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return newValue;
}
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
removeNode(entry);
return newValue;
}
entry.value = newValue;
return newValue;
}
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
if(Objects.equals(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = mappingFunction.APPLY(key);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
Objects.requireNonNull(valueProvider);
#if TYPE_OBJECT
validate(key);
#endif
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
if(entry == null) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
put(key, newValue);
return newValue;
}
if(VALUE_EQUALS(entry.value, getDefaultReturnValue())) {
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
entry.value = newValue;
}
return entry.value;
}
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -722,6 +723,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return newValue;
}
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
Objects.requireNonNull(mappingFunction);
@@ -1835,6 +1837,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
#endif
if(!inRange(key)) return getDefaultReturnValue();
Node KEY_VALUE_GENERIC_TYPE entry = map.findNode(key);
#if VALUE_OBJECT
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
VALUE_TYPE newValue = mappingFunction.apply(key, entry.value);
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
@@ -1843,6 +1846,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
entry.value = newValue;
return newValue;
#else
if(entry == null) return getDefaultReturnValue();
entry.value = mappingFunction.apply(key, entry.value);
return entry.value;
#endif
}
@Override
@@ -389,6 +389,35 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
* @return the result of the computation
*/
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value if not present
* @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
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @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
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value if present
* @return the result of the default return value or present value
* @note if not present then compute is not executed
*/
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
#if !VALUE_OBJECT
/**
* A Type Specific compute method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
@@ -398,15 +427,6 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
* @return the result of the computation
*/
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value if not present
* @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 Type Specific computeIfAbsent method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
@@ -416,15 +436,6 @@ 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_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @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 Supplier based computeIfAbsent function to fill the most used usecase of this function
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
@@ -434,16 +445,6 @@ 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 SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
/**
* A Type Specific compute method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
* @param key the key that should be computed
* @param mappingFunction the operator that should generate the value if present
* @return the result of the default return value or present value
* @note if not present then compute is not executed
*/
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
/**
* A Type Specific compute method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
@@ -454,6 +455,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
* @note if not present then compute is not executed
*/
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
#endif
/**
* A Type Specific merge method to reduce boxing/unboxing
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
@@ -168,6 +168,15 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
return index >= array.length ? array[index-array.length] : array[index];
}
@Override
public boolean contains(KEY_TYPE e) {
if(first == last) return false;
for(int i = 0,m=size();i<m;i++) {
if(e == array[(first + i) % array.length]) return true;
}
return false;
}
@Override
public boolean removeFirst(KEY_TYPE e) {
if(first == last) return false;
@@ -228,6 +228,13 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
return array[index];
}
@Override
public boolean contains(KEY_TYPE e) {
for(int i = 0;i<size;i++)
if(KEY_EQUALS(e, array[i])) return true;
return false;
}
@Override
public boolean removeFirst(KEY_TYPE e) {
for(int i = 0;i<size;i++)
@@ -236,6 +236,13 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
return array[index];
}
@Override
public boolean contains(KEY_TYPE e) {
for(int i = 0;i<size;i++)
if(KEY_EQUALS(e, array[i])) return true;
return false;
}
@Override
public boolean removeFirst(KEY_TYPE e) {
for(int i = 0;i<size;i++)
@@ -111,6 +111,13 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
*/
public default KEY_TYPE first() { return peek(0); }
/**
* Method to find out if a element is part of the queue
* @param e the element that is searched for
* @return true if the element is in the queue
*/
public boolean contains(KEY_TYPE e);
/**
* Removes the first found element in the queue
* @param e the element that should be removed
@@ -16,6 +16,16 @@ import java.util.function.IntFunction;
import java.util.function.BiFunction;
import java.util.Comparator;
#iterate
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument BUILDER BooleanAsyncBuilder ByteAsyncBuilder ShortAsyncBuilder IntAsyncBuilder LongAsyncBuilder FloatAsyncBuilder DoubleAsyncBuilder
#argument PACKAGE booleans bytes shorts ints longs floats doubles
#argument CHECK BOOLEAN_ASYNC_MODULE BYTE_ASYNC_MODULE SHORT_ASYNC_MODULE INT_ASYNC_MODULE LONG_ASYNC_MODULE FLOAT_ASYNC_MODULE DOUBLE_ASYNC_MODULE
#if CHECK
import speiger.src.collections.objects.functions.function.MAPPER;
import speiger.src.collections.PACKAGE.utils.BUILDER;
#endif
#enditerate
#endif
import speiger.src.collections.PACKAGE.collections.ITERABLE;
#if OBJECT_ASYNC_MODULE
@@ -23,7 +33,9 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
#endif
import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.TASK;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
#if OBJECT_ASYNC_MODULE
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
#endif
@@ -59,7 +71,9 @@ import speiger.src.collections.PACKAGE.sets.ARRAY_SET;
#endif
#endif
#if !TYPE_BOOLEAN && BOOLEAN_ASYNC_MODULE
#if !TYPE_OBJECT
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder;
#endif
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder.BaseBooleanTask;
#endif
#if !TYPE_OBJECT && OBJECT_ASYNC_MODULE
@@ -67,7 +81,9 @@ import speiger.src.collections.objects.utils.ObjectAsyncBuilder;
import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
#endif
#if !TYPE_INT && INT_ASYNC_MODULE
#if !TYPE_OBJECT
import speiger.src.collections.ints.utils.IntAsyncBuilder;
#endif
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
#endif
import speiger.src.collections.utils.ISizeProvider;
@@ -187,6 +203,25 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
return new ObjectAsyncBuilder<>(ITERABLES.arrayFlatMap(iterable, mapper));
}
#endif
#if TYPE_OBJECT
#iterate
#argument BUILDER BooleanAsyncBuilder ByteAsyncBuilder ShortAsyncBuilder IntAsyncBuilder LongAsyncBuilder FloatAsyncBuilder DoubleAsyncBuilder
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument TYPE Boolean Byte Short Int Long Float Double
#argument CHECK BOOLEAN_ASYNC_MODULE BYTE_ASYNC_MODULE SHORT_ASYNC_MODULE INT_ASYNC_MODULE LONG_ASYNC_MODULE FLOAT_ASYNC_MODULE DOUBLE_ASYNC_MODULE
#if CHECK
/**
* Maps the elements to something else
* @param mapper the mapping function
* @return a new Builder Object with the mapped Iterable
*/
public BUILDER mapToTYPE(MAPPER<T> mapper) {
return new BUILDER(ITERABLES.mapToTYPE(iterable, mapper));
}
#endif
#enditerate
#endif
/**
* Filters out the unwanted elements out of the Iterable
@@ -19,6 +19,26 @@ import speiger.src.collections.objects.collections.ObjectIterable;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#else
#if BOOLEAN_COLLECTION_MODULE
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.collections.BooleanIterable;
import speiger.src.collections.booleans.collections.BooleanIterator;
#endif
#iterate
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
#argument CONSUMER ByteConsumer ShortConsumer IntConsumer LongConsumer FloatConsumer DoubleConsumer
#argument OUTPUT_ITERABLE ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
#argument OUTPUT_ITERATOR ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument PACKAGE bytes shorts ints longs floats doubles
#if FILTER_TYPE
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.objects.functions.function.MAPPER;
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERABLE;
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERATOR;
#endif
#enditerate
#endif
import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
@@ -56,6 +76,39 @@ public class ITERABLES
return new MappedIterable<>(iterable, mapper);
}
#if TYPE_OBJECT
#iterate
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
#argument OUTPUT_ITERABLE BooleanIterable ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
#if FILTER_TYPE
/**
* 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)
* @return a iterable that is mapped to a new result
*/
public static <T> OUTPUT_ITERABLE mapToDATA_TYPE(Iterable<? extends CLASS_TYPE> iterable, MAPPER<T> mapper) {
return new MAPPED_TYPEIterable<>(wrap(iterable), mapper);
}
/**
* A Helper function that maps a 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)
* @return a iterable that is mapped to a new result
*/
public static <T> OUTPUT_ITERABLE mapToDATA_TYPE(ITERABLE KEY_GENERIC_TYPE iterable, MAPPER<T> mapper) {
return new MAPPED_TYPEIterable<>(iterable, mapper);
}
#endif
#enditerate
#endif
/**
* A Helper function that flatMaps a Java-Iterable into a new Type.
* @param iterable the iterable that should be flatMapped
@@ -280,6 +333,44 @@ public class ITERABLES
#endif
}
#if TYPE_OBJECT
#iterate
#argument CONSUMER BooleanConsumer ByteConsumer ShortConsumer IntConsumer LongConsumer FloatConsumer DoubleConsumer
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
#argument OUTPUT_ITERABLE BooleanIterable ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
#argument OUTPUT_ITERATOR BooleanIterator ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument APPLY test applyAsByte applyAsShort applyAsInt applyAsLong applyAsFloat applyAsDouble
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
private static class MAPPED_TYPEIterable<E> implements OUTPUT_ITERABLE, ISizeProvider
{
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
MAPPER<E> mapper;
MAPPED_TYPEIterable(ITERABLE<E> iterable, MAPPER<E> mapper) {
this.iterable = iterable;
this.mapper = mapper;
}
public OUTPUT_ITERATOR iterator() {
return ITERATORS.mapToDATA_TYPE(iterable.iterator(), mapper);
}
@Override
public int size() {
ISizeProvider prov = ISizeProvider.of(this);
return prov == null ? -1 : prov.size();
}
@Override
public void forEach(CONSUMER action) {
Objects.requireNonNull(action);
iterable.forEach(E -> action.accept(mapper.APPLY(E)));
}
}
#enditerate
#endif
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>, ISizeProvider
{
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
@@ -4,8 +4,8 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
#if TYPE_OBJECT
import java.util.Comparator;
import java.util.function.CONSUMER;
#endif
import java.util.function.Consumer;
#if JDK_FUNCTION
import java.util.function.PREDICATE;
#endif
@@ -16,8 +16,23 @@ import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.utils.ObjectIterators;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#else
#if BOOLEAN_COLLECTION_MODULE
import speiger.src.collections.booleans.collections.BooleanIterator;
#endif
#iterate
#argument ITERATOR ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
#argument PACKAGE bytes shorts ints longs floats doubles
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
#if BOOLEAN_COLLECTION_MODULE
import speiger.src.collections.objects.functions.function.MAPPER;
import speiger.src.collections.PACKAGE.collections.ITERATOR;
#endif
#enditerate
#endif
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
#if !JDK_FUNCTION
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
#endif
@@ -33,6 +48,7 @@ import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.CollectionWrapper;
/**
* A Helper class for Iterators
@@ -107,6 +123,7 @@ public class ITERATORS
return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator);
}
#if OBJECT_COLLECTION_MODULE
/**
* A Helper function that maps a Java-Iterator into a new Type.
* @param iterator that should be mapped
@@ -131,6 +148,40 @@ public class ITERATORS
return new MappedIterator<>(iterator, mapper);
}
#endif
#if TYPE_OBJECT
#iterate
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
#argument OUTPUT_ITERATOR BooleanIterator ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
#if FILTER_TYPE
/**
* 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)
* @return a iterator that is mapped to a new result
*/
public static <T> OUTPUT_ITERATOR mapToDATA_TYPE(Iterator<? extends CLASS_TYPE> iterator, MAPPER<T> mapper) {
return new MAPPED_TYPEIterator<>(wrap(iterator), mapper);
}
/**
* A Helper function that maps a Iterator into a new Type.
* @param iterator that should be mapped
* @param mapper the function that decides what the result turns into.
* @Type(T)
* @return a iterator that is mapped to a new result
*/
public static <T> OUTPUT_ITERATOR mapToDATA_TYPE(ITERATOR KEY_GENERIC_TYPE iterator, MAPPER<T> mapper) {
return new MAPPED_TYPEIterator<>(iterator, mapper);
}
#endif
#enditerate
#endif
/**
* A Helper function that flatMaps a Java-Iterator into a new Type.
* @param iterator that should be flatMapped
@@ -245,6 +296,26 @@ public class ITERATORS
return new RepeatingIteratorBRACES(wrap(iterator), repeats);
}
/**
* A Helper function that creates a infinitely looping iterator
* @param iterator that should be looping infinitely
* @Type(T)
* @return a infinitely looping iterator
*/
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE infinite(ITERATOR KEY_GENERIC_TYPE iterator) {
return new InfiniteIteratorBRACES(iterator);
}
/**
* A Helper function that creates a infinitely looping iterator from a Java Iterator
* @param iterator that should be looping infinitely
* @Type(T)
* @return a infinitely looping iterator
*/
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE infinite(Iterator<? extends CLASS_TYPE> iterator) {
return new InfiniteIteratorBRACES(wrap(iterator));
}
/**
* A Helper function that hard limits the Iterator to a specific size
* @param iterator that should be limited
@@ -846,6 +917,42 @@ public class ITERATORS
}
}
#if TYPE_OBJECT
#iterate
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
#argument NEXT_TYPE nextBoolean nextByte nextShort nextInt nextLong nextFloat nextDouble
#argument OUTPUT_ITERATOR BooleanIterator ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument APPLY test applyAsByte applyAsShort applyAsInt applyAsLong applyAsFloat applyAsDouble
#argument DATA_TYPE boolean byte short int long float double
private static class MAPPED_TYPEIterator<E> implements OUTPUT_ITERATOR
{
ITERATOR<E> iterator;
MAPPER<E> mapper;
MAPPED_TYPEIterator(ITERATOR KEY_SPECIAL_GENERIC_TYPE<E> iterator, MAPPER<E> mapper) {
this.iterator = iterator;
this.mapper = mapper;
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public DATA_TYPE NEXT_TYPE() {
return mapper.APPLY(iterator.NEXT());
}
@Override
public int skip(int amount) {
return iterator.skip(amount);
}
}
#enditerate
#endif
private static class FlatMappedIterator KSS_GENERIC_TYPE<E, T,[SPACE]V extends Iterable<T>> implements ObjectIterator<T>
{
ITERATOR KEY_SPECIAL_GENERIC_TYPE<E> iterator;
@@ -918,6 +1025,42 @@ public class ITERATORS
}
}
private static class InfiniteIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
{
ITERATOR KEY_GENERIC_TYPE iter;
CollectionWrapper KEY_GENERIC_TYPE looper = COLLECTIONS.wrapper();
int index = 0;
public InfiniteIterator(ITERATOR KEY_GENERIC_TYPE iter) {
this.iter = iter;
}
@Override
public boolean hasNext() {
return true;
}
@Override
public KEY_TYPE NEXT() {
if(iter != null) {
if(iter.hasNext()) {
KEY_TYPE value = iter.NEXT();
looper.add(value);
return value;
}
else iter = null;
}
return looper.GET_KEY((index++) % looper.size());
}
#if !TYPE_OBJECT
@Override
public void forEachRemaining(CONSUMER action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
#endif
public void forEachRemaining(Consumer<? super CLASS_TYPE> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
public <E> void forEachRemaining(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
}
private static class RepeatingIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
{
final int repeats;
@@ -24,6 +24,9 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.lists.ABSTRACT_LIST;
import speiger.src.collections.PACKAGE.lists.LIST;
#if INT_LIST_MODULE && !TYPE_INT
import speiger.src.collections.ints.lists.IntList;
#endif
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.utils.SanityChecks;
@@ -408,6 +411,18 @@ public class LISTS
return l.listIterator(index);
}
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
return l.indexedIterator(indecies);
}
#if INT_LIST_MODULE
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
return l.indexedIterator(indecies);
}
#endif
@Override
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
return LISTS.synchronize(l.subList(from, to));
@@ -535,6 +550,18 @@ public class LISTS
return ITERATORS.unmodifiable(l.listIterator(index));
}
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
return ITERATORS.unmodifiable(l.indexedIterator(indecies));
}
#if INT_LIST_MODULE
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
return ITERATORS.unmodifiable(l.indexedIterator(indecies));
}
#endif
@Override
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
return LISTS.unmodifiable(l.subList(from, to));
@@ -633,6 +660,18 @@ public class LISTS
return ITERATORS.empty();
}
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
return ITERATORS.empty();
}
#if INT_LIST_MODULE
@Override
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
return ITERATORS.empty();
}
#endif
@Override
public int hashCode() { return 1; }
@@ -116,6 +116,8 @@ public class PRIORITY_QUEUES
@Override
public KEY_TYPE peek(int index) { synchronized(mutex) { return queue.peek(index); } }
@Override
public boolean contains(KEY_TYPE e) { synchronized(mutex) { return queue.contains(e); } }
@Override
public boolean removeFirst(KEY_TYPE e) { synchronized(mutex) { return queue.removeFirst(e); } }
@Override
public boolean removeLast(KEY_TYPE e) { synchronized(mutex) { return queue.removeLast(e); } }
@@ -341,19 +341,21 @@ public class MAPS
@Override
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR 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(); }
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR 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 SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
@@ -411,19 +413,21 @@ public class MAPS
@Override
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR 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(); }
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR 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 SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
@@ -670,19 +674,21 @@ public class MAPS
@Override
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR 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(); }
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR 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 SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
@Override
@@ -1110,19 +1116,21 @@ public class MAPS
@Override
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE(key, mappingFunction); } }
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTENonDefault(key, mappingFunction); } }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_ABSENT(key, mappingFunction); } }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_ABSENTNonDefault(key, mappingFunction); } }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); } }
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENT(key, valueProvider); } }
#if !VALUE_OBJECT
@Override
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTENonDefault(key, mappingFunction); } }
@Override
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_ABSENTNonDefault(key, mappingFunction); } }
@Override
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENTNonDefault(key, mappingFunction); } }
@Override
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENT(key, valueProvider); } }
@Override
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENTNonDefault(key, valueProvider); } }
#endif
@Override
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.MERGE(key, value, mappingFunction); } }
@Override
@@ -53,6 +53,11 @@ import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapCl
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester;
#if !VALUE_OBJECT
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentNonDefaultTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentNonDefaultTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeNonDefaultTester;
#endif
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapCopyTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsKeyTester;
@@ -78,6 +83,9 @@ import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRe
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSizeTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester;
#if !VALUE_OBJECT
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentNonDefaultTester;
#endif
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapToStringTester;
import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder;
import speiger.src.testers.objects.generators.TestObjectSetGenerator;
@@ -105,6 +113,12 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder
protected List<Class<? extends AbstractTester>> getTesters() {
List<Class<? extends AbstractTester>> testers = new ArrayList<>();
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapClearTester.class);
#if !VALUE_OBJECT
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeNonDefaultTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentNonDefaultTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentNonDefaultTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentNonDefaultTester.class);
#endif
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester.class);
@@ -0,0 +1,153 @@
package speiger.src.testers.PACKAGE.tests.maps;
#ignore
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
#endignore
#if !VALUE_BOOLEAN
#ignore
import static com.google.common.collect.testing.features.CollectionSize.ONE;
#endignore
#endif
import org.junit.Ignore;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
import junit.framework.AssertionFailedError;
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
@Ignore
@SuppressWarnings("javadoc")
public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
{
#ignore
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testComputeIfAbsent_supportedAbsent() {
#if VALUE_BOOLEAN
getMap().setDefaultReturnValue(true);
#endif
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
assertEquals(k3(), k);
return v3();
}));
expectAdded(e3());
}
#if !VALUE_BOOLEAN
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ONE)
#endignore
public void testComputeIfAbsent_supportedAbsentFirst() {
getMap().setDefaultReturnValue(v0());
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
assertEquals(k0(), k);
return v3();
}));
expectContents(entry(k0(), v3()));
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ONE)
#endignore
public void testComputeIfAbsent_supportedAbsentSameResult() {
getMap().setDefaultReturnValue(v0());
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
assertEquals(k0(), k);
return v0();
}));
expectUnchanged();
}
#endif
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfAbsent_supportedPresent() {
assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
throw new AssertionFailedError();
}));
expectUnchanged();
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testComputeIfAbsent_functionReturnsNullNotInserted() {
assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
assertEquals(k3(), k);
return INVALID_VALUE;
}));
expectUnchanged();
}
static class ExpectedException extends RuntimeException {
private static final long serialVersionUID = 1L;
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testComputeIfAbsent_functionThrows() {
try {
getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
assertEquals(k3(), k);
throw new ExpectedException();
});
fail("Expected ExpectedException");
} catch (ExpectedException expected) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
#endignore
public void testComputeIfAbsent_unsupportedAbsent() {
try {
getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
// allowed to be called
assertEquals(k3(), k);
return v3();
});
fail("COMPUTE_IF_ABSENT(notPresent, function) should throw");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfAbsent_unsupportedPresentExistingValue() {
try {
assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
assertEquals(k0(), k);
return v0();
}));
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfAbsent_unsupportedPresentDifferentValue() {
try {
assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
assertEquals(k0(), k);
return v3();
}));
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
}
@@ -26,7 +26,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testComputeIfAbsent_supportedAbsent() {
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENT(k3(), k -> {
assertEquals(k3(), k);
return v3();
}));
@@ -40,11 +40,19 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
#endignore
public void testComputeIfAbsent_supportedAbsentFirst() {
getMap().setDefaultReturnValue(v0());
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
#if VALUE_OBJECT
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
assertEquals(k0(), k);
return v3();
}));
expectContents(entry(k0(), v3()));
#else
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
assertEquals(k0(), k);
return v3();
}));
expectUnchanged();
#endif
}
#ignore
@@ -53,7 +61,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
#endignore
public void testComputeIfAbsent_supportedAbsentSameResult() {
getMap().setDefaultReturnValue(v0());
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
assertEquals(k0(), k);
return v0();
}));
@@ -66,7 +74,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfAbsent_supportedPresent() {
assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
throw new AssertionFailedError();
}));
expectUnchanged();
@@ -76,11 +84,15 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testComputeIfAbsent_functionReturnsNullNotInserted() {
assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_ABSENT(k3(), k -> {
assertEquals(k3(), k);
return INVALID_VALUE;
}));
#if VALUE_OBJECT
expectUnchanged();
#else
expectAdded(entry(k3(), INVALID_VALUE));
#endif
}
static class ExpectedException extends RuntimeException {
@@ -92,7 +104,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
#endignore
public void testComputeIfAbsent_functionThrows() {
try {
getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
getMap().COMPUTE_IF_ABSENT(k3(), k -> {
assertEquals(k3(), k);
throw new ExpectedException();
});
@@ -107,7 +119,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
#endignore
public void testComputeIfAbsent_unsupportedAbsent() {
try {
getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
getMap().COMPUTE_IF_ABSENT(k3(), k -> {
// allowed to be called
assertEquals(k3(), k);
return v3();
@@ -124,7 +136,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
#endignore
public void testComputeIfAbsent_unsupportedPresentExistingValue() {
try {
assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
assertEquals(k0(), k);
return v0();
}));
@@ -139,7 +151,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
#endignore
public void testComputeIfAbsent_unsupportedPresentDifferentValue() {
try {
assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
assertEquals(k0(), k);
return v3();
}));
@@ -0,0 +1,104 @@
package speiger.src.testers.PACKAGE.tests.maps;
#ignore
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
#endignore
import org.junit.Ignore;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
import junit.framework.AssertionFailedError;
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
@Ignore
@SuppressWarnings("javadoc")
public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
{
#ignore
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testComputeIfPresent_supportedAbsent() {
assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> {
throw new AssertionFailedError();
}));
expectUnchanged();
}
#if !VALUE_BOOLEAN
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfPresent_supportedPresent() {
assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
return v3();
}));
expectReplacement(entry(k0(), v3()));
}
#endif
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfPresent_functionReturnsNull() {
assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
return INVALID_VALUE;
}));
expectMissing(e0());
}
static class ExpectedException extends RuntimeException {
private static final long serialVersionUID = 1L;
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfPresent_functionThrows() {
try {
getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
throw new ExpectedException();
});
fail("Expected ExpectedException");
} catch (ExpectedException expected) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
#endignore
public void testComputeIfPresent_unsupportedAbsent() {
try {
getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> {
throw new AssertionFailedError();
});
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfPresent_unsupportedPresent() {
try {
getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> v3());
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
}
}
@@ -21,7 +21,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testComputeIfPresent_supportedAbsent() {
assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> {
assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENT(k3(), (k, v) -> {
throw new AssertionFailedError();
}));
expectUnchanged();
@@ -32,7 +32,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfPresent_supportedPresent() {
assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
return v3();
@@ -45,7 +45,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
@CollectionSize.Require(absent = ZERO)
#endignore
public void testComputeIfPresent_functionReturnsNull() {
assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
return INVALID_VALUE;
@@ -63,7 +63,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
#endignore
public void testComputeIfPresent_functionThrows() {
try {
getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
throw new ExpectedException();
@@ -79,7 +79,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
#endignore
public void testComputeIfPresent_unsupportedAbsent() {
try {
getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> {
getMap().COMPUTE_IF_PRESENT(k3(), (k, v) -> {
throw new AssertionFailedError();
});
} catch (UnsupportedOperationException tolerated) {
@@ -93,7 +93,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
#endignore
public void testComputeIfPresent_unsupportedPresent() {
try {
getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> v3());
getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> v3());
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
@@ -0,0 +1,148 @@
package speiger.src.testers.PACKAGE.tests.maps;
#ignore
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
#endignore
import org.junit.Ignore;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
@Ignore
@SuppressWarnings("javadoc")
public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
{
#if !VALUE_BOOLEAN
#ignore
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
#endignore
public void testCompute_absentToPresent() {
assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), getMap().COMPUTENonDefault(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
return v3();
}));
expectAdded(e3());
assertEquals(getNumElements() + 1, getMap().size());
}
#endif
#ignore
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
#endignore
public void testCompute_absentToAbsent() {
assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
return INVALID_VALUE;
}));
expectUnchanged();
assertEquals(getNumElements(), getMap().size());
}
#ignore
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
@CollectionSize.Require(absent = ZERO)
#endignore
public void testCompute_presentToPresent() {
#if VALUE_BOOLEAN
getMap().setDefaultReturnValue(true);
#endif
assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), getMap().COMPUTENonDefault(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
return v3();
}));
expectReplacement(entry(k0(), v3()));
assertEquals(getNumElements(), getMap().size());
}
#ignore
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
@CollectionSize.Require(absent = ZERO)
#endignore
public void testCompute_presentToAbsent() {
assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
return INVALID_VALUE;
}));
expectMissing(e0());
expectMissingKeys(k0());
assertEquals(getNumElements() - 1, getMap().size());
}
static class ExpectedException extends RuntimeException {
private static final long serialVersionUID = 1L;
}
#ignore
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
@CollectionSize.Require(absent = ZERO)
#endignore
public void testCompute_presentFunctionThrows() {
try {
getMap().COMPUTENonDefault(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
throw new ExpectedException();
});
fail("Expected ExpectedException");
} catch (ExpectedException expected) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
#endignore
public void testCompute_absentFunctionThrows() {
try {
getMap().COMPUTENonDefault(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
throw new ExpectedException();
});
fail("Expected ExpectedException");
} catch (ExpectedException expected) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_REMOVE)
#endignore
public void testCompute_removeAbsent() {
try {
getMap().COMPUTENonDefault(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
return INVALID_VALUE;
});
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
#endignore
public void testCompute_putAbsent() {
try {
getMap().COMPUTENonDefault(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
return INVALID_VALUE;
});
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
}
}
@@ -21,7 +21,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
#endignore
public void testCompute_absentToPresent() {
assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), getMap().COMPUTENonDefault(k3(), (k, v) -> {
assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), getMap().COMPUTE(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
return v3();
@@ -34,13 +34,18 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
#endignore
public void testCompute_absentToAbsent() {
assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k3(), (k, v) -> {
assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
return INVALID_VALUE;
}));
#if VALUE_OBJECT
expectUnchanged();
assertEquals(getNumElements(), getMap().size());
#else
expectAdded(entry(k3(), INVALID_VALUE));
assertEquals(getNumElements()+1, getMap().size());
#endif
}
#ignore
@@ -48,7 +53,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
@CollectionSize.Require(absent = ZERO)
#endignore
public void testCompute_presentToPresent() {
assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), getMap().COMPUTENonDefault(k0(), (k, v) -> {
assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), getMap().COMPUTE(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
return v3();
@@ -62,14 +67,19 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
@CollectionSize.Require(absent = ZERO)
#endignore
public void testCompute_presentToAbsent() {
assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k0(), (k, v) -> {
assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
return INVALID_VALUE;
}));
#if VALUE_OBJECT
expectMissing(e0());
expectMissingKeys(k0());
assertEquals(getNumElements() - 1, getMap().size());
#else
expectReplacement(entry(k0(), INVALID_VALUE));
assertEquals(getNumElements(), getMap().size());
#endif
}
static class ExpectedException extends RuntimeException {
@@ -82,7 +92,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
#endignore
public void testCompute_presentFunctionThrows() {
try {
getMap().COMPUTENonDefault(k0(), (k, v) -> {
getMap().COMPUTE(k0(), (k, v) -> {
assertEquals(k0(), k);
assertEquals(v0(), v);
throw new ExpectedException();
@@ -98,7 +108,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
#endignore
public void testCompute_absentFunctionThrows() {
try {
getMap().COMPUTENonDefault(k3(), (k, v) -> {
getMap().COMPUTE(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
throw new ExpectedException();
@@ -114,7 +124,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
#endignore
public void testCompute_removeAbsent() {
try {
getMap().COMPUTENonDefault(k3(), (k, v) -> {
getMap().COMPUTE(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
return INVALID_VALUE;
@@ -130,7 +140,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
#endignore
public void testCompute_putAbsent() {
try {
getMap().COMPUTENonDefault(k3(), (k, v) -> {
getMap().COMPUTE(k3(), (k, v) -> {
assertEquals(k3(), k);
assertEquals(INVALID_VALUE, v);
return INVALID_VALUE;
@@ -0,0 +1,130 @@
package speiger.src.testers.PACKAGE.tests.maps;
#ignore
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
#endignore
#if !VALUE_BOOLEAN
#ignore
import static com.google.common.collect.testing.features.CollectionSize.ONE;
#endignore
#endif
import org.junit.Ignore;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
import junit.framework.AssertionFailedError;
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
@Ignore
@SuppressWarnings("javadoc")
public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
{
#ignore
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testSupplyIfAbsent_supportedAbsent() {
#if VALUE_BOOLEAN
getMap().setDefaultReturnValue(true);
#endif
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3));
expectAdded(e3());
}
#if !VALUE_BOOLEAN
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ONE)
#endignore
public void testSupplyIfAbsent_supportedAbsentFirst() {
getMap().setDefaultReturnValue(v0());
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3));
expectContents(entry(k0(), v3()));
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ONE)
#endignore
public void testSupplyIfAbsent_supportedAbsentSameResult() {
getMap().setDefaultReturnValue(v0());
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0));
expectUnchanged();
}
#endif
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testSupplyIfAbsent_supportedPresent() {
assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), () -> {
throw new AssertionFailedError();
}));
expectUnchanged();
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testSupplyIfAbsent_functionReturnsNullNotInserted() {
assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> INVALID_VALUE));
expectUnchanged();
}
static class ExpectedException extends RuntimeException {
private static final long serialVersionUID = 1L;
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testSupplyIfAbsent_functionThrows() {
try {
getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> {
throw new ExpectedException();
});
fail("Expected ExpectedException");
} catch (ExpectedException expected) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
#endignore
public void testSupplyIfAbsent_unsupportedAbsent() {
try {
getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3);
fail("SUPPLY_IF_ABSENT(notPresent, function) should throw");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testSupplyIfAbsent_unsupportedPresentExistingValue() {
try {
assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0));
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testSupplyIfAbsent_unsupportedPresentDifferentValue() {
try {
assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3));
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
}
@@ -26,7 +26,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testSupplyIfAbsent_supportedAbsent() {
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3));
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENT(k3(), this::v3));
expectAdded(e3());
}
@@ -37,8 +37,13 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
#endignore
public void testSupplyIfAbsent_supportedAbsentFirst() {
getMap().setDefaultReturnValue(v0());
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3));
#if VALUE_OBJECT
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3));
expectContents(entry(k0(), v3()));
#else
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3));
expectUnchanged();
#endif
}
#ignore
@@ -47,7 +52,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
#endignore
public void testSupplyIfAbsent_supportedAbsentSameResult() {
getMap().setDefaultReturnValue(v0());
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0));
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v0));
expectUnchanged();
}
@@ -57,7 +62,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
@CollectionSize.Require(absent = ZERO)
#endignore
public void testSupplyIfAbsent_supportedPresent() {
assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), () -> {
assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), getMap().SUPPLY_IF_ABSENT(k0(), () -> {
throw new AssertionFailedError();
}));
expectUnchanged();
@@ -67,8 +72,12 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testSupplyIfAbsent_functionReturnsNullNotInserted() {
assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> INVALID_VALUE));
assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENT(k3(), () -> INVALID_VALUE));
#if VALUE_OBJECT
expectUnchanged();
#else
expectAdded(entry(k3(), INVALID_VALUE));
#endif
}
static class ExpectedException extends RuntimeException {
@@ -80,7 +89,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
#endignore
public void testSupplyIfAbsent_functionThrows() {
try {
getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> {
getMap().SUPPLY_IF_ABSENT(k3(), () -> {
throw new ExpectedException();
});
fail("Expected ExpectedException");
@@ -94,7 +103,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
#endignore
public void testSupplyIfAbsent_unsupportedAbsent() {
try {
getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3);
getMap().SUPPLY_IF_ABSENT(k3(), this::v3);
fail("SUPPLY_IF_ABSENT(notPresent, function) should throw");
} catch (UnsupportedOperationException expected) {
}
@@ -107,7 +116,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
#endignore
public void testSupplyIfAbsent_unsupportedPresentExistingValue() {
try {
assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0));
assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v0));
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
@@ -119,7 +128,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
#endignore
public void testSupplyIfAbsent_unsupportedPresentDifferentValue() {
try {
assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3));
assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3));
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
@@ -1,252 +0,0 @@
package speiger.src.collections.booleans.collections;
import java.util.Collection;
import java.util.Objects;
import java.util.AbstractCollection;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.utils.BooleanIterators;
import speiger.src.collections.booleans.utils.BooleanArrays;
/**
* Abstract Type Specific Collection that reduces boxing/unboxing
*/
public abstract class AbstractBooleanCollection extends AbstractCollection<Boolean> implements BooleanCollection
{
@Override
public abstract BooleanIterator iterator();
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public boolean add(Boolean e) { return BooleanCollection.super.add(e); }
@Override
public boolean addAll(BooleanCollection c) {
boolean modified = false;
for(BooleanIterator iter = c.iterator();iter.hasNext();modified |= add(iter.nextBoolean()));
return modified;
}
@Override
public BooleanCollection copy() { throw new UnsupportedOperationException(); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public boolean contains(Object e) { return BooleanCollection.super.contains(e); }
/**
* A Type-Specific implementation of contains. This implementation iterates over the elements and returns true if the value match.
* @param e the element that should be searched for.
* @return true if the value was found.
*/
@Override
public boolean contains(boolean e) {
for(BooleanIterator iter = iterator();iter.hasNext();) { if(iter.nextBoolean() == e) return true; }
return false;
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public boolean addAll(Collection<? extends Boolean> c)
{
return c instanceof BooleanCollection ? addAll((BooleanCollection)c) : super.addAll(c);
}
/**
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
* @param c the collection that should be checked if it contains all elements.
* @return true if all elements were found in the collection
* @throws java.lang.NullPointerException if the collection is null
*/
@Override
public boolean containsAll(BooleanCollection c) {
Objects.requireNonNull(c);
if(c.isEmpty()) return true;
for(BooleanIterator iter = c.iterator();iter.hasNext();)
if(!contains(iter.nextBoolean()))
return false;
return true;
}
@Override
public boolean containsAll(Collection<?> c) {
Objects.requireNonNull(c);
return c instanceof BooleanCollection ? containsAll((BooleanCollection)c) : super.containsAll(c);
}
/**
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
* @param c the elements that should be checked for
* @return true if any element is in this collection
* @throws java.lang.NullPointerException if the collection is null
*/
@Override
@Deprecated
public boolean containsAny(Collection<?> c) {
Objects.requireNonNull(c);
if(c.isEmpty()) return false;
for(Object e : c)
if(contains(e))
return true;
return false;
}
/**
* This implementation iterates over the elements of the collection and checks if they are stored in this collection.
* @param c the elements that should be checked for
* @return true if any element is in this collection
* @throws java.lang.NullPointerException if the collection is null
*/
@Override
public boolean containsAny(BooleanCollection c) {
Objects.requireNonNull(c);
if(c.isEmpty()) return false;
for(BooleanIterator iter = c.iterator();iter.hasNext();)
if(contains(iter.nextBoolean()))
return true;
return false;
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public boolean remove(Object e) { return BooleanCollection.super.remove(e); }
/**
* A Type-Specific implementation of remove. This implementation iterates over the elements until it finds the element that is searched for or it runs out of elements.
* It stops after finding the first element
* @param e the element that is searched for
* @return true if the element was found and removed.
*/
@Override
public boolean remBoolean(boolean e) {
for(BooleanIterator iter = iterator();iter.hasNext();) {
if(iter.nextBoolean() == e) {
iter.remove();
return true;
}
}
return false;
}
/**
* A Type-Specific implementation of removeAll. This Implementation iterates over all elements and removes them as they were found in the other collection.
* @param c the elements that should be deleted
* @return true if the collection was modified.
* @throws java.lang.NullPointerException if the collection is null
*/
@Override
public boolean removeAll(BooleanCollection c) {
Objects.requireNonNull(c);
if(c.isEmpty()) return false;
boolean modified = false;
for(BooleanIterator iter = iterator();iter.hasNext();) {
if(c.contains(iter.nextBoolean())) {
iter.remove();
modified = true;
}
}
return modified;
}
@Override
public boolean removeAll(BooleanCollection c, BooleanConsumer r) {
Objects.requireNonNull(c);
if(c.isEmpty()) return false;
Objects.requireNonNull(r);
boolean modified = false;
for(BooleanIterator iter = iterator();iter.hasNext();) {
boolean e = iter.nextBoolean();
if(c.contains(e)) {
r.accept(e);
iter.remove();
modified = true;
}
}
return modified;
}
/**
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
* @param c the elements that should be kept
* @return true if the collection was modified.
* @throws java.lang.NullPointerException if the collection is null
*/
@Override
public boolean retainAll(BooleanCollection c) {
Objects.requireNonNull(c);
if(c.isEmpty()) {
boolean modified = !isEmpty();
clear();
return modified;
}
boolean modified = false;
for(BooleanIterator iter = iterator();iter.hasNext();) {
if(!c.contains(iter.nextBoolean())) {
iter.remove();
modified = true;
}
}
return modified;
}
@Override
public boolean retainAll(BooleanCollection c, BooleanConsumer r) {
Objects.requireNonNull(c);
Objects.requireNonNull(r);
if(c.isEmpty()) {
boolean modified = !isEmpty();
forEach(r);
clear();
return modified;
}
boolean modified = false;
for(BooleanIterator iter = iterator();iter.hasNext();) {
boolean e = iter.nextBoolean();
if(!c.contains(e)) {
r.accept(e);
iter.remove();
modified = true;
}
}
return modified;
}
/**
* A Type-Specific implementation of toArray that links to {@link #toBooleanArray(boolean[])} with a newly created array.
* @return an array containing all of the elements in this collection
*/
@Override
public boolean[] toBooleanArray() {
if(isEmpty()) return BooleanArrays.EMPTY_ARRAY;
return toBooleanArray(new boolean[size()]);
}
/**
* A Type-Specific implementation of toArray. This implementation iterates over all elements and unwraps them into primitive type.
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
* @return an array containing all of the elements in this collection
*/
@Override
public boolean[] toBooleanArray(boolean[] a) {
if(a == null || a.length < size()) a = new boolean[size()];
BooleanIterators.unwrap(a, iterator());
if (a.length > size()) a[size()] = false;
return a;
}
}
@@ -1,52 +0,0 @@
package speiger.src.collections.booleans.collections;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
/**
* A Type-Specific {@link ObjectBidirectionalIterator} to reduce (un)boxing
*/
public interface BooleanBidirectionalIterator extends BooleanIterator, ObjectBidirectionalIterator<Boolean>
{
/**
* Returns true if the Iterator has a Previous element
* @return true if the Iterator has a Previous element
*/
public boolean hasPrevious();
/**
* Returns the Previous element of the iterator.
* @return the Previous element of the iterator.
* @throws java.util.NoSuchElementException if the iteration has no more elements
*/
public boolean previousBoolean();
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default Boolean previous() {
return Boolean.valueOf(previousBoolean());
}
/**
* {@inheritDoc}
*/
@Override
default int skip(int amount)
{
return BooleanIterator.super.skip(amount);
}
/**
* Reverses the Given amount of elements if possible. A Optimization function to reverse elements faster if the implementation allows it.
* @param amount the amount of elements that should be reversed
* @return the amount of elements that were reversed
*/
public default int back(int amount) {
if(amount < 0) throw new IllegalStateException("Can't go forward");
int i = 0;
for(;i<amount && hasPrevious();previousBoolean(),i++);
return i;
}
}
@@ -1,231 +0,0 @@
package speiger.src.collections.booleans.collections;
import java.util.Collection;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.utils.BooleanSplititerators;
import speiger.src.collections.booleans.utils.BooleanCollections;
import speiger.src.collections.utils.ISizeProvider;
import speiger.src.collections.utils.SanityChecks;
/**
* A Type-Specific {@link Collection} that reduces (un)boxing
*/
public interface BooleanCollection extends Collection<Boolean>, BooleanIterable, ISizeProvider
{
/**
* A Type-Specific add function to reduce (un)boxing
* @param o the element that should be added
* @return true if the element was added to the collection
*/
public boolean add(boolean o);
/**
* A Type-Specific addAll function to reduce (un)boxing
* @param c the collection of elements that should be added
* @return true if elements were added into the collection
*/
public boolean addAll(BooleanCollection 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(boolean... 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(boolean[] 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(boolean[] 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;
}
/**
* A Type-Specific contains function to reduce (un)boxing
* @param o the element that is checked for
* @return true if the element is found in the collection
*/
public boolean contains(boolean o);
/**
* A Type-Specific containsAll function to reduce (un)boxing
* @param c the collection of elements that should be tested for
* @return true if all the element is found in the collection
*/
public boolean containsAll(BooleanCollection c);
/**
* A Type-Specific containsAny function to reduce (un)boxing
* @param c the collection of elements that should be tested for
* @return true if any element was found
*/
public boolean containsAny(BooleanCollection c);
/**
* Returns true if any element of the Collection is found in the provided collection.
* A Small Optimization function to find out of any element is present when comparing collections and not all of them.
* @param c the collection of elements that should be tested for
* @return true if any element was found.
*/
@Deprecated
public boolean containsAny(Collection<?> c);
/**
* A Type-Specific remove function that reduces (un)boxing.
* @param o the element that should be removed
* @return true if the element was removed
* @see Collection#remove(Object)
*/
public boolean remBoolean(boolean o);
/**
* A Type-Specific removeAll function that reduces (un)boxing.
* @param c the collection of elements that should be removed
* @return true if any element was removed
* @see Collection#removeAll(Collection)
*/
public boolean removeAll(BooleanCollection c);
/**
* A Type-Specific removeAll function that reduces (un)boxing.
* It also notifies the remover of which exact element is going to be removed.
* @param c the collection of elements that should be removed
* @param r elements that got removed
* @return true if any element was removed
* @see Collection#removeAll(Collection)
*/
public boolean removeAll(BooleanCollection c, BooleanConsumer r);
/**
* A Type-Specific retainAll function that reduces (un)boxing.
* @param c the collection of elements that should be kept
* @return true if any element was removed
* @see Collection#retainAll(Collection)
*/
public boolean retainAll(BooleanCollection c);
/**
* A Type-Specific retainAll function that reduces (un)boxing.
* It also notifies the remover of which exact element is going to be removed.
* @param c the collection of elements that should be kept
* @param r elements that got removed
* @return true if any element was removed
* @see Collection#retainAll(Collection)
*/
public boolean retainAll(BooleanCollection c, BooleanConsumer r);
/**
* A Helper function to reduce the usage of Streams and allows to collect all elements
* @param collection that the elements should be inserted to
* @param <E> the collection type
* @return the input with the desired elements
*/
default <E extends BooleanCollection> E pour(E collection) {
collection.addAll(this);
return collection;
}
/**
* A Function that does a shallow clone of the Collection itself.
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
* It can be compared to Cloneable but with less exception risk
* @return a Shallow Copy of the collection
* @note Wrappers and view collections will not support this feature
*/
public BooleanCollection copy();
/**
* A Type-Specific toArray function that delegates to {@link #toBooleanArray(boolean[])} with a newly created array.
* @return an array containing all of the elements in this collection
* @see Collection#toArray()
*/
public boolean[] toBooleanArray();
/**
* A Type-Specific toArray function that reduces (un)boxing.
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
* @return an array containing all of the elements in this collection
* @see Collection#toArray(Object[])
*/
public boolean[] toBooleanArray(boolean[] a);
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default boolean add(Boolean o) { return add(o.booleanValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default boolean contains(Object o) { return o != null && contains(((Boolean)o).booleanValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default boolean remove(Object o) { return o != null && remBoolean(((Boolean)o).booleanValue()); }
/**
* Returns a Type-Specific Iterator to reduce (un)boxing
* @return a iterator of the collection
* @see Collection#iterator()
*/
@Override
public BooleanIterator iterator();
/**
* Creates a Wrapped Collection that is Synchronized
* @return a new Collection that is synchronized
* @see BooleanCollections#synchronize
*/
public default BooleanCollection synchronize() { return BooleanCollections.synchronize(this); }
/**
* Creates a Wrapped Collection that is Synchronized
* @param mutex is the controller of the synchronization block
* @return a new Collection Wrapper that is synchronized
* @see BooleanCollections#synchronize
*/
public default BooleanCollection synchronize(Object mutex) { return BooleanCollections.synchronize(this, mutex); }
/**
* Creates a Wrapped Collection that is unmodifiable
* @return a new Collection Wrapper that is unmodifiable
* @see BooleanCollections#unmodifiable
*/
public default BooleanCollection unmodifiable() { return BooleanCollections.unmodifiable(this); }
/**
* A Type Specific Type Splititerator to reduce boxing/unboxing
* @return type specific splititerator
*/
@Override
default BooleanSplititerator spliterator() { return BooleanSplititerators.createSplititerator(this, 0); }
}
@@ -1,333 +0,0 @@
package speiger.src.collections.booleans.collections;
import java.util.Objects;
import java.util.function.Consumer;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.objects.collections.ObjectIterable;
import speiger.src.collections.booleans.functions.function.BooleanFunction;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.function.BooleanBooleanUnaryOperator;
import speiger.src.collections.booleans.lists.BooleanList;
import speiger.src.collections.booleans.lists.BooleanArrayList;
import speiger.src.collections.booleans.utils.BooleanArrays;
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder;
import speiger.src.collections.booleans.utils.BooleanSplititerators;
import speiger.src.collections.booleans.utils.BooleanIterables;
import speiger.src.collections.booleans.utils.BooleanIterators;
import speiger.src.collections.utils.ISizeProvider;
/**
* A Type-Specific {@link Iterable} that reduces (un)boxing
*/
public interface BooleanIterable extends Iterable<Boolean>
{
/**
* Returns an iterator over elements of type {@code T}.
*
* @return an Iterator.
*/
@Override
BooleanIterator iterator();
/**
* A Type Specific foreach function that reduces (un)boxing
*
* @implSpec
* <p>The default implementation behaves as if:
* <pre>{@code
* iterator().forEachRemaining(action);
* }</pre>
*
* @param action The action to be performed for each element
* @throws NullPointerException if the specified action is null
* @see Iterable#forEach(Consumer)
*/
default void forEach(BooleanConsumer action) {
Objects.requireNonNull(action);
iterator().forEachRemaining(action);
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Deprecated
@Override
default void forEach(Consumer<? super Boolean> action) {
Objects.requireNonNull(action);
iterator().forEachRemaining(action);
}
/**
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
* @param action The action to be performed for each element
* @throws java.lang.NullPointerException if the specified action is null
*/
public default void forEachIndexed(IntBooleanConsumer action) {
Objects.requireNonNull(action);
int index = 0;
for(BooleanIterator iter = iterator();iter.hasNext();action.accept(index++, iter.nextBoolean()));
}
/**
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
* @param input the object that should be included
* @param action The action to be performed for each element
* @param <E> the generic type of the Object
* @throws java.lang.NullPointerException if the specified action is null
*/
default <E> void forEach(E input, ObjectBooleanConsumer<E> action) {
Objects.requireNonNull(action);
iterator().forEachRemaining(input, action);
}
/**
* A Type Specific Type Splititerator to reduce boxing/unboxing
* @return type specific splititerator
*/
@Override
default BooleanSplititerator spliterator() { return BooleanSplititerators.createUnknownSplititerator(iterator(), 0); }
/**
* Creates a Async Builder for moving work of the thread.
* It is not designed to split the work to multithreaded work, so using this keep it singlethreaded, but it allows to be moved to another thread.
* @see BooleanAsyncBuilder
* @return a AsyncBuilder
*/
default BooleanAsyncBuilder asAsync() {
return new BooleanAsyncBuilder(this);
}
/**
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
* @param mapper the mapping function
* @param <E> The return type.
* @return a new Iterable that returns the desired result
*/
default <E> ObjectIterable<E> map(BooleanFunction<E> mapper) {
return BooleanIterables.map(this, mapper);
}
/**
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
* @param mapper the flatMapping function
* @param <V> The return type supplier.
* @param <E> The return type.
* @return a new Iterable that returns the desired result
* @note does not support toBooleanArray optimizations.
*/
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(BooleanFunction<V> mapper) {
return BooleanIterables.flatMap(this, mapper);
}
/**
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
* @param mapper the flatMapping function
* @param <E> The return type.
* @return a new Iterable that returns the desired result
* @note does not support toBooleanArray optimizations.
*/
default <E> ObjectIterable<E> arrayflatMap(BooleanFunction<E[]> mapper) {
return BooleanIterables.arrayFlatMap(this, mapper);
}
/**
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
* @param filter the elements that should be kept.
* @return a Iterable that filtered out all unwanted elements
* @note does not support toBooleanArray optimizations.
*/
default BooleanIterable filter(BooleanPredicate filter) {
return BooleanIterables.filter(this, filter);
}
/**
* A Helper function to reduce the usage of Streams and allows to filter out duplicated elements
* @return a Iterable that filtered out all duplicated elements
* @note does not support toBooleanArray optimizations.
*/
default BooleanIterable distinct() {
return BooleanIterables.distinct(this);
}
/**
* A Helper function to reduce the usage of Streams and allows to repeat elements a desired amount of times
* @param repeats how many times the elements should be repeated
* @return a Iterable that is repeating multiple times
*/
default BooleanIterable repeat(int repeats) {
return BooleanIterables.repeat(this, repeats);
}
/**
* A Helper function to reduce the usage of Streams and allows to limit the amount of elements
* @param limit the amount of elements it should be limited to
* @return a Iterable that is limited in length
*/
default BooleanIterable limit(long limit) {
return BooleanIterables.limit(this, limit);
}
/**
* A Helper function to reduce the usage of Streams and allows to sort the elements
* @param sorter that sorts the elements.
* @return a Iterable that is sorted
*/
default BooleanIterable sorted(BooleanComparator sorter) {
return BooleanIterables.sorted(this, sorter);
}
/**
* A Helper function to reduce the usage of Streams and allows to preview elements before they are iterated through
* @param action the action that should be applied
* @return a Peeked Iterable
*/
default BooleanIterable peek(BooleanConsumer action) {
return BooleanIterables.peek(this, action);
}
/**
* A Helper function to reduce the usage of Streams and allows to collect all elements
* @param collection that the elements should be inserted to
* @param <E> the collection type
* @return the input with the desired elements
*/
default <E extends BooleanCollection> E pour(E collection) {
BooleanIterators.pour(iterator(), collection);
return collection;
}
/**
* A Helper function that reduces the usage of streams and allows to collect all elements as a ArrayList
* @return a new ArrayList of all elements
*/
default BooleanList pourAsList() {
return pour(new BooleanArrayList());
}
/**
* A Helper function that reduces the usage of streams and allows to collect all elements as a Array
* @return a new Array of all elements
*/
default boolean[] toBooleanArray() {
ISizeProvider prov = ISizeProvider.of(this);
if(prov != null) {
int size = prov.size();
if(size >= 0) {
boolean[] array = new boolean[size];
BooleanIterators.unwrap(array, iterator());
return array;
}
}
return BooleanArrays.pour(iterator());
}
/**
* Helper function to reduce stream usage that allows to filter for any matches.
* @param filter that should be applied
* @return true if any matches were found
*/
default boolean matchesAny(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(BooleanIterator iter = iterator();iter.hasNext();) {
if(filter.test(iter.nextBoolean())) return true;
}
return false;
}
/**
* Helper function to reduce stream usage that allows to filter for no matches.
* @param filter that should be applied
* @return true if no matches were found
*/
default boolean matchesNone(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(BooleanIterator iter = iterator();iter.hasNext();) {
if(filter.test(iter.nextBoolean())) return false;
}
return true;
}
/**
* Helper function to reduce stream usage that allows to filter for all matches.
* @param filter that should be applied
* @return true if all matches.
*/
default boolean matchesAll(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(BooleanIterator iter = iterator();iter.hasNext();) {
if(!filter.test(iter.nextBoolean())) return false;
}
return true;
}
/**
* Helper function to reduce stream usage that allows to filter for the first match.
* @param filter that should be applied
* @return the found value or the null equivalent variant.
*/
default boolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(BooleanIterator iter = iterator();iter.hasNext();) {
boolean entry = iter.nextBoolean();
if(filter.test(entry)) return entry;
}
return false;
}
/**
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
* elements of this Iterable
* @param operator the operation that should be applied
* @param identity the start value
* @return the reduction result, returns identity if nothing was found
*/
default boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = identity;
for(BooleanIterator iter = iterator();iter.hasNext();) {
state = operator.applyAsBoolean(state, iter.nextBoolean());
}
return state;
}
/**
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
* elements of this Iterable
* @param operator the operation that should be applied
* @return the reduction result, returns null value if nothing was found
*/
default boolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
for(BooleanIterator iter = iterator();iter.hasNext();) {
if(empty) {
empty = false;
state = iter.nextBoolean();
continue;
}
state = operator.applyAsBoolean(state, iter.nextBoolean());
}
return state;
}
/**
* Helper function to reduce stream usage that allows to count the valid elements.
* @param filter that should be applied
* @return the amount of Valid Elements
*/
default int count(BooleanPredicate filter) {
Objects.requireNonNull(filter);
int result = 0;
for(BooleanIterator iter = iterator();iter.hasNext();) {
if(filter.test(iter.nextBoolean())) result++;
}
return result;
}
}
@@ -1,88 +0,0 @@
package speiger.src.collections.booleans.collections;
import java.util.Iterator;
import java.util.Objects;
import java.util.function.Consumer;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
/**
* A Type-Specific {@link Iterator} that reduces (un)boxing
*/
public interface BooleanIterator extends Iterator<Boolean>
{
/**
* Returns the next element in the iteration.
*
* @return the next element in the iteration
* @throws java.util.NoSuchElementException if the iteration has no more elements
* @see Iterator#next()
*/
public boolean nextBoolean();
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default Boolean next() { return Boolean.valueOf(nextBoolean()); }
/**
* Performs the given action for each remaining element until all elements
* have been processed or the action throws an exception. Actions are
* performed in the order of iteration, if that order is specified.
* Exceptions thrown by the action are relayed to the caller.
*
* @implSpec
* <p>The default implementation behaves as if:
* <pre>{@code
* while (hasNext()) action.accept(nextBoolean());
* }</pre>
*
* @param action The action to be performed for each element
* @throws java.lang.NullPointerException if the specified action is null
* @see Iterator#forEachRemaining(Consumer)
*/
public default void forEachRemaining(BooleanConsumer action) {
Objects.requireNonNull(action);
while(hasNext()) { action.accept(nextBoolean()); }
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Deprecated
@Override
default void forEachRemaining(Consumer<? super Boolean> action) {
Objects.requireNonNull(action);
forEachRemaining(action::accept);
}
/**
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
* @param input the object that should be included
* @param action The action to be performed for each element
* @param <E> the generic type of the Object
* @throws java.lang.NullPointerException if the specified action is null
*/
default <E> void forEachRemaining(E input, ObjectBooleanConsumer<E> action) {
Objects.requireNonNull(action);
while(hasNext()) { action.accept(input, nextBoolean()); }
}
/**
* Skips the Given amount of elements if possible. A Optimization function to skip elements faster if the implementation allows it.
* @param amount the amount of elements that should be skipped
* @return the amount of elements that were skipped
*/
default int skip(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int i = 0;
for(;i<amount && hasNext();nextBoolean(), i++);
return i;
}
}
@@ -1,19 +0,0 @@
package speiger.src.collections.booleans.collections;
import java.util.Spliterator.OfPrimitive;
import java.util.function.Consumer;
import speiger.src.collections.booleans.functions.BooleanConsumer;
/**
* A Type Specific Split-Iterator that reduces boxing/unboxing
* It fills the gaps of the java and uses this collection interfaces
*/
public interface BooleanSplititerator extends OfPrimitive<Boolean, BooleanConsumer, BooleanSplititerator>, BooleanIterator
{
@Override
default void forEachRemaining(BooleanConsumer action) { BooleanIterator.super.forEachRemaining(action); }
@Override
@Deprecated
default void forEachRemaining(Consumer<? super Boolean> action) { BooleanIterator.super.forEachRemaining(action); }
}
@@ -1,85 +0,0 @@
package speiger.src.collections.booleans.collections;
import java.util.NoSuchElementException;
import speiger.src.collections.utils.Stack;
/**
* A Type-Specific {@link Stack} that reduces (un)boxing
*/
public interface BooleanStack
{
/**
* Inserts a given Object on top of the stack
* @param e the Object to insert
* @see Stack#push(Object)
*/
public void push(boolean e);
/**
* Helper function that pushes the top element on top of the stack again.
* @throws NoSuchElementException if the stack is empty
*/
public default void pushTop() {
push(top());
}
/**
* Removes the Object on top of the stack.
* @return the element that is on top of the stack
* @throws ArrayIndexOutOfBoundsException if the stack is empty
* @see Stack#pop()
*/
public boolean pop();
/**
* Provides the Object on top of the stack
* @return the element that is on top of the stack
* @throws ArrayIndexOutOfBoundsException if the stack is empty
* @see Stack#top()
*/
public default boolean top() {
return peek(0);
}
/**
* Provides the Selected Object from the stack.
* Top to bottom
* @param index of the element that should be provided
* @return the element that was requested
* @throws ArrayIndexOutOfBoundsException if the index is out of bounds
* @see Stack#peek(int)
*/
public boolean peek(int index);
/**
* Clears the stack
*/
public void clear();
/**
* Provides the amount of elements currently in the stack
* @return amount of elements in the list
*/
public int size();
/**
* @return if the stack is empty
*/
public default boolean isEmpty() {
return size() == 0;
}
/**
* A method to drop the contents of the Stack without clearing the stack
* @return the contents of the stack into a seperate array.
*/
public default boolean[] toBooleanArray() { return toBooleanArray(new boolean[size()]); }
/**
* A method to drop the contents of the Stack without clearing the stack
* @param input where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
* @return the contents of the stack into a seperate array.
* @note if the Type is generic then a Object Array is created instead of a Type Array
*/
public boolean[] toBooleanArray(boolean[] input);
}
@@ -1,70 +0,0 @@
package speiger.src.collections.booleans.functions;
import java.util.Comparator;
import java.util.Objects;
/**
* Type-Specific Class for Comparator to reduce (un)boxing
*/
public interface BooleanComparator extends Comparator<Boolean>
{
/**
* Type-Specific compare function to reduce (un)boxing
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
* @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
* @see Comparator#compare(Object, Object)
*/
int compare(boolean o1, boolean o2);
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default int compare(Boolean o1, Boolean o2) {
return compare(o1.booleanValue(), o2.booleanValue());
}
/**
* A Wrapper function to convert a Non-Type-Specific Comparator to a Type-Specific-Comparator
* @param c comparator to convert
* @return the wrapper of the comparator
* @throws NullPointerException if the comparator is null
*/
public static BooleanComparator of(Comparator<Boolean> c) {
Objects.requireNonNull(c);
return (K, V) -> c.compare(Boolean.valueOf(K), Boolean.valueOf(V));
}
@Override
public default BooleanComparator reversed() {
return new Reversed(this);
}
/**
* A Type Specific Reversed Comparator to reduce boxing/unboxing
*/
static class Reversed implements BooleanComparator
{
BooleanComparator original;
/**
* default constructor
* @param original that is going to be reversed
*/
public Reversed(BooleanComparator original) {
this.original = original;
}
public int compare(boolean o1, boolean o2) {
return original.compare(o2, o1);
}
@Override
public BooleanComparator reversed() {
return original;
}
}
}
@@ -1,48 +0,0 @@
package speiger.src.collections.booleans.functions;
import java.util.Objects;
import java.util.function.Consumer;
/**
* Type-Specific Consumer interface that reduces (un)boxing and allows to merge other consumer types into this interface
*/
@FunctionalInterface
public interface BooleanConsumer extends Consumer<Boolean>
{
/**
* Type-Specific function to reduce (un)boxing.
* Performs this operation on the given argument.
*
* @param t the input argument
*/
void accept(boolean t);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced consumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanConsumer andThen(BooleanConsumer after) {
Objects.requireNonNull(after);
return T -> {accept(T); after.accept(T);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean t) { accept(t.booleanValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanConsumer andThen(Consumer<? super Boolean> after) {
Objects.requireNonNull(after);
return T -> {accept(T); after.accept(Boolean.valueOf(T));};
}
}
@@ -1,12 +0,0 @@
package speiger.src.collections.booleans.functions;
/**
* Type-Specific Supplier interface that reduces (un)boxing and allows to merge other consumer types into this interface
*/
public interface BooleanSupplier
{
/**
* @return the supplied value
*/
public boolean getAsBoolean();
}
@@ -1,87 +0,0 @@
package speiger.src.collections.booleans.functions;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
*
* A Type Specific Task interface that allows you to keep track of the task that is currently running.<br>
* It extends Runnable future and supports said functions but also provides quality of life functions like:<br>
*
* - isSuccesfull: which allows to detect if the task was completed properly and not interrupted or crashed.
* - pause/resume: which allows to pause/resume the task at any moment, making it easier to create thread-safe actions.
*/
public interface BooleanTask extends RunnableFuture<Boolean> {
/**
* Helper function to detect if the task is currently paused.
* @return true if paused
*/
public boolean isPaused();
/**
* Pauses the task, which lets the thread finish without completing the task.
* Tasks are written in the way where they can pause without any issues.
* This won't be instant, as this function is applied asynchronous and doesn't check if the thread paused.
* So make sure it had the time to pause.
*/
public void pause();
/**
* Pauses the task, which lets the thread finish without completing the task.
* Tasks are written in the way where they can pause without any issues.
* This won't be instant, as this function is applied asynchronous.
* It will await the pausing of the task.
*/
public void awaitPausing();
/**
* Continues the task if it wasn't already completed.
* This is done by resubmitting the task to the executor provided.
*/
public void resume();
/**
* Quality of life function that allows to detect if no cancellation/exception was applied to this task and it completed on its own.
* @return true if it was properly completed
*/
public boolean isSuccessful();
/**
* A Type Specific get method that allows to reduce (un)boxing of primtives.
*
* Waits if necessary for the computation to complete, and then
* retrieves its result.
*
* @return the computed result as primitive
* @throws CancellationException if the computation was cancelled
* @throws ExecutionException if the computation threw an exception
* @throws InterruptedException if the current thread was interrupted
* while waiting
*/
public boolean getBoolean() throws InterruptedException, ExecutionException;
/**
* Waits if necessary for at most the given time for the computation
* to complete, and then retrieves its result, if available.
*
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
* @return the computed result as primitive
* @throws CancellationException if the computation was cancelled
* @throws ExecutionException if the computation threw an exception
* @throws InterruptedException if the current thread was interrupted while waiting
* @throws TimeoutException if the wait timed out
*/
public boolean getBoolean(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
@Override
@Deprecated
public default Boolean get() throws InterruptedException, ExecutionException { return Boolean.valueOf(getBoolean()); }
@Override
@Deprecated
public default Boolean get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return Boolean.valueOf(getBoolean(timeout, unit)); }
}
@@ -1,49 +0,0 @@
package speiger.src.collections.booleans.functions.consumer;
import java.util.Objects;
import java.util.function.BiConsumer;
/**
* A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has.
*/
public interface BooleanBooleanConsumer extends BiConsumer<Boolean, Boolean>
{
/**
* A Type Specific operation method to reduce boxing/unboxing
* Performs this operation on the given arguments.
*
* @param k the first input argument
* @param v the second input argument
*/
void accept(boolean k, boolean v);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced biconsumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanBooleanConsumer andThen(BooleanBooleanConsumer after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(K, V);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean k, Boolean v) { accept(k.booleanValue(), v.booleanValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanBooleanConsumer andThen(BiConsumer<? super Boolean, ? super Boolean> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(Boolean.valueOf(K), Boolean.valueOf(V));};
}
}
@@ -1,49 +0,0 @@
package speiger.src.collections.booleans.functions.consumer;
import java.util.Objects;
import java.util.function.BiConsumer;
/**
* A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has.
*/
public interface BooleanByteConsumer extends BiConsumer<Boolean, Byte>
{
/**
* A Type Specific operation method to reduce boxing/unboxing
* Performs this operation on the given arguments.
*
* @param k the first input argument
* @param v the second input argument
*/
void accept(boolean k, byte v);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced biconsumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanByteConsumer andThen(BooleanByteConsumer after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(K, V);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean k, Byte v) { accept(k.booleanValue(), v.byteValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanByteConsumer andThen(BiConsumer<? super Boolean, ? super Byte> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(Boolean.valueOf(K), Byte.valueOf(V));};
}
}
@@ -1,49 +0,0 @@
package speiger.src.collections.booleans.functions.consumer;
import java.util.Objects;
import java.util.function.BiConsumer;
/**
* A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has.
*/
public interface BooleanCharConsumer extends BiConsumer<Boolean, Character>
{
/**
* A Type Specific operation method to reduce boxing/unboxing
* Performs this operation on the given arguments.
*
* @param k the first input argument
* @param v the second input argument
*/
void accept(boolean k, char v);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced biconsumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanCharConsumer andThen(BooleanCharConsumer after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(K, V);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean k, Character v) { accept(k.booleanValue(), v.charValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanCharConsumer andThen(BiConsumer<? super Boolean, ? super Character> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(Boolean.valueOf(K), Character.valueOf(V));};
}
}
@@ -1,49 +0,0 @@
package speiger.src.collections.booleans.functions.consumer;
import java.util.Objects;
import java.util.function.BiConsumer;
/**
* A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has.
*/
public interface BooleanDoubleConsumer extends BiConsumer<Boolean, Double>
{
/**
* A Type Specific operation method to reduce boxing/unboxing
* Performs this operation on the given arguments.
*
* @param k the first input argument
* @param v the second input argument
*/
void accept(boolean k, double v);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced biconsumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanDoubleConsumer andThen(BooleanDoubleConsumer after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(K, V);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean k, Double v) { accept(k.booleanValue(), v.doubleValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanDoubleConsumer andThen(BiConsumer<? super Boolean, ? super Double> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(Boolean.valueOf(K), Double.valueOf(V));};
}
}
@@ -1,49 +0,0 @@
package speiger.src.collections.booleans.functions.consumer;
import java.util.Objects;
import java.util.function.BiConsumer;
/**
* A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has.
*/
public interface BooleanFloatConsumer extends BiConsumer<Boolean, Float>
{
/**
* A Type Specific operation method to reduce boxing/unboxing
* Performs this operation on the given arguments.
*
* @param k the first input argument
* @param v the second input argument
*/
void accept(boolean k, float v);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced biconsumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanFloatConsumer andThen(BooleanFloatConsumer after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(K, V);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean k, Float v) { accept(k.booleanValue(), v.floatValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanFloatConsumer andThen(BiConsumer<? super Boolean, ? super Float> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(Boolean.valueOf(K), Float.valueOf(V));};
}
}
@@ -1,49 +0,0 @@
package speiger.src.collections.booleans.functions.consumer;
import java.util.Objects;
import java.util.function.BiConsumer;
/**
* A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has.
*/
public interface BooleanIntConsumer extends BiConsumer<Boolean, Integer>
{
/**
* A Type Specific operation method to reduce boxing/unboxing
* Performs this operation on the given arguments.
*
* @param k the first input argument
* @param v the second input argument
*/
void accept(boolean k, int v);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced biconsumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanIntConsumer andThen(BooleanIntConsumer after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(K, V);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean k, Integer v) { accept(k.booleanValue(), v.intValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanIntConsumer andThen(BiConsumer<? super Boolean, ? super Integer> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(Boolean.valueOf(K), Integer.valueOf(V));};
}
}
@@ -1,49 +0,0 @@
package speiger.src.collections.booleans.functions.consumer;
import java.util.Objects;
import java.util.function.BiConsumer;
/**
* A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has.
*/
public interface BooleanLongConsumer extends BiConsumer<Boolean, Long>
{
/**
* A Type Specific operation method to reduce boxing/unboxing
* Performs this operation on the given arguments.
*
* @param k the first input argument
* @param v the second input argument
*/
void accept(boolean k, long v);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced biconsumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanLongConsumer andThen(BooleanLongConsumer after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(K, V);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean k, Long v) { accept(k.booleanValue(), v.longValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanLongConsumer andThen(BiConsumer<? super Boolean, ? super Long> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(Boolean.valueOf(K), Long.valueOf(V));};
}
}
@@ -1,50 +0,0 @@
package speiger.src.collections.booleans.functions.consumer;
import java.util.Objects;
import java.util.function.BiConsumer;
/**
* A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has.
* @param <V> the keyType of elements maintained by this Collection
*/
public interface BooleanObjectConsumer<V> extends BiConsumer<Boolean, V>
{
/**
* A Type Specific operation method to reduce boxing/unboxing
* Performs this operation on the given arguments.
*
* @param k the first input argument
* @param v the second input argument
*/
void accept(boolean k, V v);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced biconsumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanObjectConsumer<V> andThen(BooleanObjectConsumer<V> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(K, V);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean k, V v) { accept(k.booleanValue(), v); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanObjectConsumer<V> andThen(BiConsumer<? super Boolean, ? super V> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(Boolean.valueOf(K), V);};
}
}
@@ -1,49 +0,0 @@
package speiger.src.collections.booleans.functions.consumer;
import java.util.Objects;
import java.util.function.BiConsumer;
/**
* A Type Specific BiConsumer class to reduce boxing/unboxing and that fills the gaps that java has.
*/
public interface BooleanShortConsumer extends BiConsumer<Boolean, Short>
{
/**
* A Type Specific operation method to reduce boxing/unboxing
* Performs this operation on the given arguments.
*
* @param k the first input argument
* @param v the second input argument
*/
void accept(boolean k, short v);
/**
* Type Specific sequencing method to reduce boxing/unboxing.
* @param after a operation that should be performed afterwards
* @return a sequenced biconsumer that does 2 operations
* @throws NullPointerException if after is null
*/
public default BooleanShortConsumer andThen(BooleanShortConsumer after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(K, V);};
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void accept(Boolean k, Short v) { accept(k.booleanValue(), v.shortValue()); }
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default BooleanShortConsumer andThen(BiConsumer<? super Boolean, ? super Short> after) {
Objects.requireNonNull(after);
return (K, V) -> {accept(K, V); after.accept(Boolean.valueOf(K), Short.valueOf(V));};
}
}
@@ -1,17 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
*/
@FunctionalInterface
public interface Boolean2BooleanFunction
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public boolean test(boolean k);
}
@@ -1,17 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
*/
@FunctionalInterface
public interface Boolean2ByteFunction
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public byte applyAsByte(boolean k);
}
@@ -1,17 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
*/
@FunctionalInterface
public interface Boolean2CharFunction
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public char applyAsChar(boolean k);
}
@@ -1,17 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
*/
@FunctionalInterface
public interface Boolean2DoubleFunction
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public double applyAsDouble(boolean k);
}
@@ -1,17 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
*/
@FunctionalInterface
public interface Boolean2FloatFunction
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public float applyAsFloat(boolean k);
}
@@ -1,17 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
*/
@FunctionalInterface
public interface Boolean2IntFunction
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public int applyAsInt(boolean k);
}
@@ -1,17 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
*/
@FunctionalInterface
public interface Boolean2LongFunction
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public long applyAsLong(boolean k);
}
@@ -1,18 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
* @param <V> the keyType of elements maintained by this Collection
*/
@FunctionalInterface
public interface Boolean2ObjectFunction<V>
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public V apply(boolean k);
}
@@ -1,17 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
*/
@FunctionalInterface
public interface Boolean2ShortFunction
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public short applyAsShort(boolean k);
}
@@ -1,22 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.function.BiFunction;
/**
* A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing
*/
public interface BooleanBooleanUnaryOperator extends BiFunction<Boolean, Boolean, Boolean>
{
/**
* A Type Specifc apply method to reduce boxing/unboxing.
* Applies this function to the given arguments.
*
* @param k the first function argument
* @param v the second function argument
* @return the function result
*/
public boolean applyAsBoolean(boolean k, boolean v);
@Override
public default Boolean apply(Boolean k, Boolean v) { return Boolean.valueOf(applyAsBoolean(k.booleanValue(), v.booleanValue())); }
}
@@ -1,22 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.function.BiFunction;
/**
* A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing
*/
public interface BooleanByteUnaryOperator extends BiFunction<Boolean, Byte, Byte>
{
/**
* A Type Specifc apply method to reduce boxing/unboxing.
* Applies this function to the given arguments.
*
* @param k the first function argument
* @param v the second function argument
* @return the function result
*/
public byte applyAsByte(boolean k, byte v);
@Override
public default Byte apply(Boolean k, Byte v) { return Byte.valueOf(applyAsByte(k.booleanValue(), v.byteValue())); }
}
@@ -1,22 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.function.BiFunction;
/**
* A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing
*/
public interface BooleanCharUnaryOperator extends BiFunction<Boolean, Character, Character>
{
/**
* A Type Specifc apply method to reduce boxing/unboxing.
* Applies this function to the given arguments.
*
* @param k the first function argument
* @param v the second function argument
* @return the function result
*/
public char applyAsChar(boolean k, char v);
@Override
public default Character apply(Boolean k, Character v) { return Character.valueOf(applyAsChar(k.booleanValue(), v.charValue())); }
}
@@ -1,22 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.function.BiFunction;
/**
* A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing
*/
public interface BooleanDoubleUnaryOperator extends BiFunction<Boolean, Double, Double>
{
/**
* A Type Specifc apply method to reduce boxing/unboxing.
* Applies this function to the given arguments.
*
* @param k the first function argument
* @param v the second function argument
* @return the function result
*/
public double applyAsDouble(boolean k, double v);
@Override
public default Double apply(Boolean k, Double v) { return Double.valueOf(applyAsDouble(k.booleanValue(), v.doubleValue())); }
}
@@ -1,22 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.function.BiFunction;
/**
* A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing
*/
public interface BooleanFloatUnaryOperator extends BiFunction<Boolean, Float, Float>
{
/**
* A Type Specifc apply method to reduce boxing/unboxing.
* Applies this function to the given arguments.
*
* @param k the first function argument
* @param v the second function argument
* @return the function result
*/
public float applyAsFloat(boolean k, float v);
@Override
public default Float apply(Boolean k, Float v) { return Float.valueOf(applyAsFloat(k.booleanValue(), v.floatValue())); }
}
@@ -1,18 +0,0 @@
package speiger.src.collections.booleans.functions.function;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
* @param <V> the keyType of elements maintained by this Collection
*/
@FunctionalInterface
public interface BooleanFunction<V>
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public V apply(boolean k);
}
@@ -1,22 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.function.BiFunction;
/**
* A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing
*/
public interface BooleanIntUnaryOperator extends BiFunction<Boolean, Integer, Integer>
{
/**
* A Type Specifc apply method to reduce boxing/unboxing.
* Applies this function to the given arguments.
*
* @param k the first function argument
* @param v the second function argument
* @return the function result
*/
public int applyAsInt(boolean k, int v);
@Override
public default Integer apply(Boolean k, Integer v) { return Integer.valueOf(applyAsInt(k.booleanValue(), v.intValue())); }
}
@@ -1,22 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.function.BiFunction;
/**
* A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing
*/
public interface BooleanLongUnaryOperator extends BiFunction<Boolean, Long, Long>
{
/**
* A Type Specifc apply method to reduce boxing/unboxing.
* Applies this function to the given arguments.
*
* @param k the first function argument
* @param v the second function argument
* @return the function result
*/
public long applyAsLong(boolean k, long v);
@Override
public default Long apply(Boolean k, Long v) { return Long.valueOf(applyAsLong(k.booleanValue(), v.longValue())); }
}
@@ -1,23 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.function.BiFunction;
/**
* A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing
* @param <V> the keyType of elements maintained by this Collection
*/
public interface BooleanObjectUnaryOperator<V> extends BiFunction<Boolean, V, V>
{
/**
* A Type Specifc apply method to reduce boxing/unboxing.
* Applies this function to the given arguments.
*
* @param k the first function argument
* @param v the second function argument
* @return the function result
*/
public V apply(boolean k, V v);
@Override
public default V apply(Boolean k, V v) { return apply(k.booleanValue(), v); }
}
@@ -1,98 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.Objects;
/**
* A Type Specific Function interface that reduces boxing/unboxing and fills the gaps of interfaces that are missing.
*/
@FunctionalInterface
public interface BooleanPredicate
{
/**
* Type Specific get function to reduce boxing/unboxing
* @param k the value that should be processed
* @return the result of the function
*/
public boolean test(boolean k);
/**
* Creates a Default function that returns the input provided.
* @return a input returning function
*/
public static BooleanPredicate identity() {
return T -> T;
}
/**
* Returns a composed function that first applies the {@code before}
* function to its input, and then applies this function to the result.
* If evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
*
* @param before the function that should be used first
* @return a composed function with a different starting function.
*/
public default BooleanPredicate compose(BooleanPredicate before) {
Objects.requireNonNull(before);
return T -> test(before.test(T));
}
/**
* Returns a composed function that first applies this function to
* its input, and then applies the {@code after} function to the result.
* If evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
*
* @param after the function that should be used last
* @return a composed function with a different starting function.
*/
public default BooleanPredicate andThen(BooleanPredicate after) {
Objects.requireNonNull(after);
return T -> after.test(test(T));
}
/**
* Creates a Always true function that may be useful if you don't need to process information or just want a default.
* @return a default returning function
*/
public static BooleanPredicate alwaysTrue() {
return T -> true;
}
/**
* Creates a Always false function that may be useful if you don't need to process information or just want a default.
* @return a default returning function
*/
public static BooleanPredicate alwaysFalse() {
return T -> false;
}
/**
* A Type specific and-function helper function that reduces boxing/unboxing
* @param other the other function that should be merged with.
* @return a function that compares values in a and comparason
*/
public default BooleanPredicate andType(BooleanPredicate other) {
Objects.requireNonNull(other);
return T -> test(T) && other.test(T);
}
/**
* A type specific inverter function
* @return the same function but inverts the result
*/
public default BooleanPredicate negate() {
return T -> !test(T);
}
/**
* A Type specific or-function helper function that reduces boxing/unboxing
* @param other the other function that should be merged with.
* @return a function that compares values in a or comparason
*/
public default BooleanPredicate orType(BooleanPredicate other) {
Objects.requireNonNull(other);
return T -> test(T) || other.test(T);
}
}
@@ -1,22 +0,0 @@
package speiger.src.collections.booleans.functions.function;
import java.util.function.BiFunction;
/**
* A Type Specific Unary Operator to support Compute/Merge functions with type specific methods to reduce boxing/unboxing
*/
public interface BooleanShortUnaryOperator extends BiFunction<Boolean, Short, Short>
{
/**
* A Type Specifc apply method to reduce boxing/unboxing.
* Applies this function to the given arguments.
*
* @param k the first function argument
* @param v the second function argument
* @return the function result
*/
public short applyAsShort(boolean k, short v);
@Override
public default Short apply(Boolean k, Short v) { return Short.valueOf(applyAsShort(k.booleanValue(), v.shortValue())); }
}
@@ -1,651 +0,0 @@
package speiger.src.collections.booleans.lists;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.RandomAccess;
import speiger.src.collections.booleans.collections.AbstractBooleanCollection;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.collections.BooleanSplititerator;
import speiger.src.collections.booleans.utils.BooleanSplititerators;
import speiger.src.collections.utils.SanityChecks;
/**
* Abstract implementation of the {@link BooleanList} interface.
*/
public abstract class AbstractBooleanList extends AbstractBooleanCollection implements BooleanList
{
/**
* A Type-Specific implementation of add function that delegates to {@link List#add(int, Object)}
*/
@Override
public boolean add(boolean e) {
add(size(), e);
return true;
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public void add(int index, Boolean element) {
add(index, element.booleanValue());
}
/**
* A Type-Specific implementation that iterates over the elements and adds them.
* @param c the elements that wants to be added
* @return true if the list was modified
*/
@Override
public boolean addAll(BooleanCollection c) {
return addAll(size(), c);
}
/**
* A Type-Specific implementation that iterates over the elements and adds them.
* @param c the elements that wants to be added
* @return true if the list was modified
*/
@Override
public boolean addAll(BooleanList c) {
return addAll(size(), c);
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public boolean addAll(Collection<? extends Boolean> c) {
return c instanceof BooleanCollection ? addAll((BooleanCollection)c) : addAll(size(), c);
}
/**
* The IndexOf implementation iterates over all elements and compares them to the search value.
* @param o the value that the index is searched for.
* @return index of the value that was searched for. -1 if not found
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
*/
@Override
@Deprecated
public int indexOf(Object o) {
BooleanListIterator iter = listIterator();
if(o == null) return -1;
while(iter.hasNext()) {
if(Objects.equals(o, Boolean.valueOf(iter.nextBoolean())))
return iter.previousIndex();
}
return -1;
}
/**
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
* @param o the value that the index is searched for.
* @return the last index of the value that was searched for. -1 if not found
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
*/
@Override
@Deprecated
public int lastIndexOf(Object o) {
BooleanListIterator iter = listIterator(size());
if(o == null) return -1;
while(iter.hasPrevious()) {
if(Objects.equals(o, Boolean.valueOf(iter.previousBoolean())))
return iter.nextIndex();
}
return -1;
}
/**
* The indexOf implementation iterates over all elements and compares them to the search value.
* @param e the value that the index is searched for.
* @return index of the value that was searched for. -1 if not found
*/
@Override
public int indexOf(boolean e) {
BooleanListIterator iter = listIterator();
while(iter.hasNext()) {
if(iter.nextBoolean() == e)
return iter.previousIndex();
}
return -1;
}
/**
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
* @param e the value that the index is searched for.
* @return the last index of the value that was searched for. -1 if not found
*/
@Override
public int lastIndexOf(boolean e) {
BooleanListIterator iter = listIterator(size());
while(iter.hasPrevious()) {
if(iter.previousBoolean() == e)
return iter.nextIndex();
}
return -1;
}
@Override
public boolean swapRemoveBoolean(boolean e) {
int index = indexOf(e);
if(index == -1) return false;
swapRemove(index);
return true;
}
/**
* Compares if the list are the same.
*/
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof List))
return false;
List<?> l = (List<?>)o;
if(l.size() != size()) return false;
if(l instanceof BooleanList)
{
BooleanListIterator e1 = listIterator();
BooleanListIterator e2 = ((BooleanList)l).listIterator();
while (e1.hasNext() && e2.hasNext()) {
if(!(e1.nextBoolean() == e2.nextBoolean()))
return false;
}
return !(e1.hasNext() || e2.hasNext());
}
ListIterator<Boolean> e1 = listIterator();
ListIterator<?> e2 = l.listIterator();
while (e1.hasNext() && e2.hasNext()) {
if(!Objects.equals(e1.next(), e2.next()))
return false;
}
return !(e1.hasNext() || e2.hasNext());
}
/**
* Generates the hashcode based on the values stored in the list.
*/
@Override
public int hashCode() {
int hashCode = 1;
BooleanListIterator i = listIterator();
while(i.hasNext())
hashCode = 31 * hashCode + Boolean.hashCode(i.nextBoolean());
return hashCode;
}
@Override
public BooleanList subList(int fromIndex, int toIndex) {
SanityChecks.checkArrayCapacity(size(), fromIndex, toIndex-fromIndex);
return new SubList(this, 0, fromIndex, toIndex);
}
@Override
public BooleanList reversed() {
return new ReversedList(this);
}
@Override
public BooleanIterator iterator() {
return listIterator(0);
}
@Override
public BooleanListIterator listIterator() {
return listIterator(0);
}
@Override
public BooleanListIterator listIterator(int index) {
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
return new BooleanListIter(index);
}
@Override
public void size(int size) {
while(size > size()) add(false);
while(size < size()) removeBoolean(size() - 1);
}
public AbstractBooleanList copy() { throw new UnsupportedOperationException(); }
private class ReversedList extends AbstractBooleanList
{
final AbstractBooleanList list;
public ReversedList(AbstractBooleanList list) {
this.list = list;
}
@Override
public void add(int index, boolean e) {
list.add(list.size() - index - 1, e);
}
@Override
public boolean addAll(int index, BooleanCollection c) {
return addCollection(index, c);
}
@Override
public boolean addAll(int index, BooleanList c) {
if(c instanceof RandomAccess) {
for(int i = 0,m=c.size();i<m;i++) {
list.add(list.size() - index - i - 1, c.getBoolean(i));
}
return true;
}
return addCollection(index, c);
}
private boolean addCollection(int index, BooleanCollection c) {
int i = 0;
for(BooleanIterator iter = c.iterator();iter.hasNext();i++) {
list.add(list.size() - index - i - 1, iter.nextBoolean());
}
return true;
}
@Override
public boolean addAll(int index, Collection<? extends Boolean> c) {
int i = 0;
for(Iterator<? extends Boolean> iter = c.iterator();iter.hasNext();i++) {
list.add(list.size() - index - i - 1, iter.next());
}
return true;
}
@Override
public boolean getBoolean(int index) {
return list.getBoolean(list.size() - index - 1);
}
@Override
public boolean set(int index, boolean e) {
return list.set(list.size() - index - 1, e);
}
@Override
public boolean removeBoolean(int index) {
return list.removeBoolean(list.size() - index - 1);
}
@Override
public void addElements(int from, boolean[] a, int offset, int length) {
for(int i = 0,m=length;i<m;i++) {
list.add(list.size() - from - i - 1, a[i+offset]);
}
}
@Override
public boolean[] getElements(int from, boolean[] a, int offset, int length) {
return reverse(list.getElements(list.size() - from - 1, a, offset, length));
}
@Override
public void removeElements(int from, int to) {
list.removeElements(list.size() - to - 1, list.size() - from - 1);
}
@Override
public boolean swapRemove(int index) {
return list.swapRemove(list.size() - index - 1);
}
@Override
public boolean[] extractElements(int from, int to) {
return reverse(list.extractElements(list.size() - to - 1, list.size() - from - 1));
}
@Override
public int size() {
return list.size();
}
@Override
public void clear() {
list.clear();
}
@Override
public BooleanList reversed() {
return list;
}
private boolean[] reverse(boolean[] data) {
for (int i = 0, mid = data.length >> 1, j = data.length - 1; i < mid; i++, j--) {
boolean t = data[i];
data[i] = data[j];
data[j] = t;
}
return data;
}
}
private class SubList extends AbstractBooleanList
{
final AbstractBooleanList list;
final int parentOffset;
final int offset;
int size;
public SubList(AbstractBooleanList list, int offset, int from, int to) {
this.list = list;
this.parentOffset = from;
this.offset = offset + from;
this.size = to - from;
}
@Override
public void add(int index, boolean element) {
checkAddSubRange(index);
list.add(parentOffset+index, element);
size++;
}
@Override
public boolean addAll(int index, Collection<? extends Boolean> c) {
checkAddSubRange(index);
int add = c.size();
if(add <= 0) return false;
list.addAll(parentOffset+index, c);
this.size += add;
return true;
}
@Override
public boolean addAll(int index, BooleanCollection c) {
checkAddSubRange(index);
int add = c.size();
if(add <= 0) return false;
list.addAll(parentOffset+index, c);
this.size += add;
return true;
}
@Override
public boolean addAll(int index, BooleanList c) {
checkAddSubRange(index);
int add = c.size();
if(add <= 0) return false;
list.addAll(parentOffset+index, c);
this.size += add;
return true;
}
@Override
public void addElements(int from, boolean[] a, int offset, int length) {
checkAddSubRange(from);
if(length <= 0) return;
list.addElements(parentOffset+from, a, offset, length);
this.size += length;
}
@Override
public boolean[] getElements(int from, boolean[] a, int offset, int length) {
SanityChecks.checkArrayCapacity(size, from, length);
SanityChecks.checkArrayCapacity(a.length, offset, length);
return list.getElements(from+parentOffset, a, offset, length);
}
@Override
public void removeElements(int from, int to) {
if(to-from <= 0) return;
checkSubRange(from);
checkAddSubRange(to);
list.removeElements(from+parentOffset, to+parentOffset);
size -= to - from;
}
@Override
public boolean[] extractElements(int from, int to) {
checkSubRange(from);
checkAddSubRange(to);
boolean[] result = list.extractElements(from+parentOffset, to+parentOffset);
size -= result.length;
return result;
}
@Override
public boolean getBoolean(int index) {
checkSubRange(index);
return list.getBoolean(parentOffset+index);
}
@Override
public boolean set(int index, boolean element) {
checkSubRange(index);
return list.set(parentOffset+index, element);
}
@Override
public boolean swapRemove(int index) {
checkSubRange(index);
if(index == size-1) {
boolean result = list.removeBoolean(parentOffset+size-1);
size--;
return result;
}
boolean result = list.set(index+parentOffset, list.getBoolean(parentOffset+size-1));
list.removeBoolean(parentOffset+size-1);
size--;
return result;
}
@Override
public boolean removeBoolean(int index) {
checkSubRange(index);
boolean result = list.removeBoolean(index+parentOffset);
size--;
return result;
}
@Override
public int size() {
return size;
}
@Override
public BooleanSplititerator spliterator() { return BooleanSplititerators.createSplititerator(this, 16464); }
@Override
public BooleanListIterator listIterator(int index) {
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
return new SubListIterator(this, index);
}
@Override
public BooleanList subList(int fromIndex, int toIndex) {
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
return new SubList(this, offset, fromIndex, toIndex);
}
protected void checkSubRange(int index) {
if (index < 0 || index >= size)
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
}
protected void checkAddSubRange(int index) {
if (index < 0 || index > size)
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
}
private class SubListIterator implements BooleanListIterator
{
AbstractBooleanList list;
int index;
int lastReturned = -1;
SubListIterator(AbstractBooleanList list, int index) {
this.list = list;
this.index = index;
}
@Override
public boolean hasNext() {
return index < list.size();
}
@Override
public boolean nextBoolean() {
if(!hasNext()) throw new NoSuchElementException();
int i = index++;
return list.getBoolean((lastReturned = i));
}
@Override
public boolean hasPrevious() {
return index > 0;
}
@Override
public boolean previousBoolean() {
if(!hasPrevious()) throw new NoSuchElementException();
index--;
return list.getBoolean((lastReturned = index));
}
@Override
public int nextIndex() {
return index;
}
@Override
public int previousIndex() {
return index-1;
}
@Override
public void remove() {
if(lastReturned == -1) throw new IllegalStateException();
list.removeBoolean(lastReturned);
index = lastReturned;
lastReturned = -1;
}
@Override
public void set(boolean e) {
if(lastReturned == -1) throw new IllegalStateException();
list.set(lastReturned, e);
}
@Override
public void add(boolean e) {
list.add(index, e);
index++;
lastReturned = -1;
}
@Override
public int skip(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, size() - index);
index += steps;
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
return steps;
}
@Override
public int back(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, index);
index -= steps;
if(steps > 0) lastReturned = Math.min(index, size()-1);
return steps;
}
}
}
private class BooleanListIter implements BooleanListIterator {
int index;
int lastReturned = -1;
BooleanListIter(int index) {
this.index = index;
}
@Override
public boolean hasNext() {
return index < size();
}
@Override
public boolean nextBoolean() {
if(!hasNext()) throw new NoSuchElementException();
int i = index++;
return getBoolean((lastReturned = i));
}
@Override
public boolean hasPrevious() {
return index > 0;
}
@Override
public boolean previousBoolean() {
if(!hasPrevious()) throw new NoSuchElementException();
index--;
return getBoolean((lastReturned = index));
}
@Override
public int nextIndex() {
return index;
}
@Override
public int previousIndex() {
return index-1;
}
@Override
public void remove() {
if(lastReturned == -1) throw new IllegalStateException();
AbstractBooleanList.this.removeBoolean(lastReturned);
index = lastReturned;
lastReturned = -1;
}
@Override
public void set(boolean e) {
if(lastReturned == -1) throw new IllegalStateException();
AbstractBooleanList.this.set(lastReturned, e);
}
@Override
public void add(boolean e) {
AbstractBooleanList.this.add(index, e);
index++;
lastReturned = -1;
}
@Override
public int skip(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, size() - index);
index += steps;
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
return steps;
}
@Override
public int back(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, index);
index -= steps;
if(steps > 0) lastReturned = Math.min(index, size()-1);
return steps;
}
}
}
@@ -1,910 +0,0 @@
package speiger.src.collections.booleans.lists;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanStack;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.function.BooleanBooleanUnaryOperator;
import speiger.src.collections.booleans.utils.BooleanArrays;
import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.booleans.utils.BooleanIterators;
import speiger.src.collections.booleans.utils.IBooleanArray;
import speiger.src.collections.booleans.collections.BooleanSplititerator;
import speiger.src.collections.booleans.utils.BooleanSplititerators;
import speiger.src.collections.utils.SanityChecks;
/**
* A Type-Specific Array-based implementation of list that is written to reduce (un)boxing
*
* <p>This implementation is optimized to improve how data is processed with interfaces like {@link IBooleanArray}, {@link BooleanStack}
* and with optimized functions that use type-specific implementations for primitives and optimized logic for bulkactions.
*
*/
public class BooleanArrayList extends AbstractBooleanList implements IBooleanArray, BooleanStack
{
static final int DEFAULT_ARRAY_SIZE = 10;
/** The backing array */
protected transient boolean[] data;
/** The current size of the elements stored in the backing array */
protected int size = 0;
/**
* Creates a new ArrayList with a Empty array.
*/
public BooleanArrayList() {
data = BooleanArrays.EMPTY_ARRAY;
}
/**
* Creates a new ArrayList with the specific requested size
* @param size the minimum initial size of the Backing array
*/
public BooleanArrayList(int size) {
if(size < 0) throw new IllegalStateException("Size has to be 0 or greater");
data = new boolean[size];
}
/**
* Creates a new ArrayList a copy with the contents of the Collection.
* @param c the elements that should be added into the list
*/
@Deprecated
public BooleanArrayList(Collection<? extends Boolean> c) {
this(c.size());
size = BooleanIterators.unwrap(data, c.iterator());
}
/**
* Creates a new ArrayList a copy with the contents of the Collection.
* @param c the elements that should be added into the list
*/
public BooleanArrayList(BooleanCollection c) {
this(c.size());
size = BooleanIterators.unwrap(data, c.iterator());
}
/**
* Creates a new ArrayList a copy with the contents of the List.
* @param l the elements that should be added into the list
*/
public BooleanArrayList(BooleanList l) {
this(l.size());
size = l.size();
l.getElements(0, data, 0, size);
}
/**
* Creates a new ArrayList with a Copy of the array
* @param a the array that should be copied
*/
public BooleanArrayList(boolean... a) {
this(a, 0, a.length);
}
/**
* Creates a new ArrayList with a Copy of the array with a custom length
* @param a the array that should be copied
* @param length the desired length that should be copied
*/
public BooleanArrayList(boolean[] a, int length) {
this(a, 0, length);
}
/**
* Creates a new ArrayList with a Copy of the array with in the custom range.
* @param a the array that should be copied
* @param offset the starting offset of where the array should be copied from
* @param length the desired length that should be copied
* @throws IllegalStateException if offset is smaller then 0
* @throws IllegalStateException if the offset + length exceeds the array length
*/
public BooleanArrayList(boolean[] a, int offset, int length) {
this(length);
SanityChecks.checkArrayCapacity(a.length, offset, length);
System.arraycopy(a, offset, data, 0, length);
size = length;
}
/**
* Creates a wrapped arraylist that uses the array as backing array
* @param a elements that should be wrapped
* @return a Wrapped list using the input array
*/
public static BooleanArrayList wrap(boolean... a) {
return wrap(a, a.length);
}
/**
* Creates a wrapped arraylist that uses the array as backing array and a custom fill size
* @param a elements that should be wrapped
* @param length the size of the elements within the array
* @return a Wrapped list using the input array
*/
public static BooleanArrayList wrap(boolean[] a, int length) {
SanityChecks.checkArrayCapacity(a.length, 0, length);
BooleanArrayList list = new BooleanArrayList();
list.data = a;
list.size = length;
return list;
}
/**
* Appends the specified element to the end of this list.
*
* @param e element to be appended to this list
* @return true (as specified by {@link Collection#add})
*/
@Override
public boolean add(boolean e) {
grow(size + 1);
data[size++] = e;
return true;
}
/**
* Appends the specified element to the end of this Stack.
* @param e element to be appended to this Stack
*/
@Override
public void push(boolean e) {
add(e);
}
/**
* Appends the specified element to the index of the list
* @param index the index where to append the element to
* @param e the element to append to the list
* @throws IndexOutOfBoundsException if index is outside of the lists range
*/
@Override
public void add(int index, boolean e) {
checkAddRange(index);
grow(size + 1);
if(index != size) System.arraycopy(data, index, data, index+1, size - index);
data[index] = e;
size++;
}
/**
* Appends the specified elements to the index of the list.
* This function may delegate to more appropriate function if necessary
* @param index the index where to append the elements to
* @param c the elements to append to the list
* @throws IndexOutOfBoundsException if index is outside of the lists range
* @throws NullPointerException if collection contains a null element
*/
@Override
@Deprecated
public boolean addAll(int index, Collection<? extends Boolean> c) {
if(c instanceof BooleanCollection) return addAll(index, (BooleanCollection)c);
int add = c.size();
if(add <= 0) return false;
if(c.contains(null)) throw new NullPointerException();
grow(size + add);
if(index != size) System.arraycopy(data, index, data, index+add, size - index);
size+=add;
Iterator<? extends Boolean> iter = c.iterator();
while(add-- != 0) data[index++] = iter.next().booleanValue();
return true;
}
/**
* Appends the specified elements to the index of the list.
* This function may delegate to more appropriate function if necessary
* @param index the index where to append the elements to
* @param c the elements to append to the list
* @throws IndexOutOfBoundsException if index is outside of the lists range
*/
@Override
public boolean addAll(int index, BooleanCollection c) {
if(c instanceof BooleanList) return addAll(index, (BooleanList)c);
int add = c.size();
if(add <= 0) return false;
grow(size + add);
if(index != size) System.arraycopy(data, index, data, index+add, size - index);
size+=add;
BooleanIterator iter = c.iterator();
while(add-- != 0) data[index++] = iter.nextBoolean();
return true;
}
/**
* Appends the specified elements to the index of the list.
* @param index the index where to append the elements to
* @param c the elements to append to the list
* @throws IndexOutOfBoundsException if index is outside of the lists range
*/
@Override
public boolean addAll(int index, BooleanList c) {
int add = c.size();
if(add <= 0) return false;
checkAddRange(index);
grow(size + add);
if(index != size) System.arraycopy(data, index, data, index+add, size - index);
size+=add;
c.getElements(0, data, index, c.size());
return true;
}
@Override
public boolean addAll(boolean[] 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
* @param a the elements to append to the list
* @param offset where to start ino the array
* @param length the amount of elements to insert
* @throws IndexOutOfBoundsException if index is outside of the lists range
*/
@Override
public void addElements(int from, boolean[] a, int offset, int length) {
if(length <= 0) return;
checkAddRange(from);
SanityChecks.checkArrayCapacity(a.length, offset, length);
grow(size + length);
if(from != size) System.arraycopy(data, from, data, from+length, size - from);
size+=length;
System.arraycopy(a, offset, data, from, length);
}
/**
* A function to fast fetch elements from the list
* @param from index where the list should be fetching elements from
* @param a the array where the values should be inserted to
* @param offset the startIndex of where the array should be written to
* @param length the number of elements the values should be fetched from
* @return the inputArray
* @throws NullPointerException if the array is null
* @throws IndexOutOfBoundsException if from is outside of the lists range
* @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length
*/
@Override
public boolean[] getElements(int from, boolean[] a, int offset, int length) {
SanityChecks.checkArrayCapacity(size, from, length);
SanityChecks.checkArrayCapacity(a.length, offset, length);
System.arraycopy(data, from, a, offset, length);
return a;
}
/**
* a function to fast remove elements from the list.
* @param from the start index of where the elements should be removed from (inclusive)
* @param to the end index of where the elements should be removed to (exclusive)
*/
@Override
public void removeElements(int from, int to) {
checkRange(from);
checkAddRange(to);
int length = to - from;
if(length <= 0) return;
if(to != size) System.arraycopy(data, to, data, from, size - to);
size -= length;
}
/**
* A function to fast extract elements out of the list, this removes the elements that were fetched.
* @param from the start index of where the elements should be fetched from (inclusive)
* @param to the end index of where the elements should be fetched to (exclusive)
* @return a array of the elements that were fetched
*/
@Override
public boolean[] extractElements(int from, int to) {
int length = to - from;
if(length <= 0) return BooleanArrays.EMPTY_ARRAY;
boolean[] a = new boolean[length];
System.arraycopy(data, from, a, 0, length);
if(to != size) System.arraycopy(data, to, data, from, size - to);
size -= length;
return a;
}
/**
* A function to find if the Element is present in this list.
* @param o the element that is searched for
* @return if the element was found.
*/
@Override
@Deprecated
public boolean contains(Object o) {
return indexOf(o) != -1;
}
/**
* A function to find the index of a given element
* @param o the element that is searched for
* @return the index of the element if found. (if not found then -1)
*/
@Override
@Deprecated
public int indexOf(Object o) {
if(o == null) return -1;
for(int i = 0;i<size;i++) {
if(Objects.equals(o, Boolean.valueOf(data[i]))) return i;
}
return -1;
}
/**
* A function to find the last index of a given element
* @param o the element that is searched for
* @return the last index of the element if found. (if not found then -1)
*/
@Override
@Deprecated
public int lastIndexOf(Object o) {
if(o == null) return -1;
for(int i = size - 1;i>=0;i--) {
if(Objects.equals(o, Boolean.valueOf(data[i]))) return i;
}
return -1;
}
/**
* A Type Specific implementation of the Collection#contains function.
* @param e the element that is searched for.
* @return if the element was found
*/
@Override
public boolean contains(boolean e) {
return indexOf(e) != -1;
}
/**
* A Type-Specific function to find the index of a given element
* @param e the element that is searched for
* @return the index of the element if found. (if not found then -1)
*/
@Override
public int indexOf(boolean e) {
for(int i = 0;i<size;i++) {
if(data[i] == e) return i;
}
return -1;
}
/**
* A Type-Specific function to find the last index of a given element
* @param e the element that is searched for
* @return the last index of the element if found. (if not found then -1)
*/
@Override
public int lastIndexOf(boolean e) {
for(int i = size - 1;i>=0;i--) {
if(data[i] == e) return i;
}
return -1;
}
/**
* Sorts the elements specified by the Natural order either by using the Comparator or the elements
* @param c the sorter of the elements, can be null
* @see java.util.List#sort(java.util.Comparator)
* @see BooleanArrays#stableSort(boolean[], BooleanComparator)
*/
@Override
public void sort(BooleanComparator c) {
if(c != null) BooleanArrays.stableSort(data, size, c);
else BooleanArrays.stableSort(data, size);
}
/**
* Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort
* @param c the sorter of the elements, can be null
* @see java.util.List#sort(java.util.Comparator)
* @see BooleanArrays#unstableSort(boolean[], BooleanComparator)
*/
@Override
public void unstableSort(BooleanComparator c) {
if(c != null) BooleanArrays.unstableSort(data, size, c);
else BooleanArrays.unstableSort(data, size);
}
/**
* A Type-Specific get function to reduce (un)boxing
* @param index the index of the element to fetch
* @return the value of the requested index
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override
public boolean getBoolean(int index) {
checkRange(index);
return data[index];
}
/**
* Provides the Selected Object from the stack.
* Top to bottom
* @param index of the element that should be provided
* @return the element that was requested
* @throws ArrayIndexOutOfBoundsException if the index is out of bounds
* @see speiger.src.collections.utils.Stack#peek(int)
*/
@Override
public boolean peek(int index) {
checkRange((size() - 1) - index);
return data[(size() - 1) - index];
}
/**
* Provides the Underlying Array in the Implementation
* @return underlying Array
* @throws ClassCastException if the return type does not match the underlying array. (Only for Object Implementations)
*/
@Override
public boolean[] elements() {
return data;
}
/**
* A Type Specific foreach function that reduces (un)boxing
*
* @implSpec
* <p>The default implementation behaves as if:
* <pre>{@code
* for(int i = 0;i<size;i++)
* action.accept(data[i]);
* }</pre>
*
* @param action The action to be performed for each element
* @throws NullPointerException if the specified action is null
* @see Iterable#forEach(java.util.function.Consumer)
*/
@Override
public void forEach(BooleanConsumer action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;i++)
action.accept(data[i]);
}
@Override
public <E> void forEach(E input, ObjectBooleanConsumer<E> action) {
Objects.requireNonNull(action);
for(int i = 0;i<size;i++)
action.accept(input, data[i]);
}
@Override
public boolean matchesAny(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(data[i])) return true;
}
return false;
}
@Override
public boolean matchesNone(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(data[i])) return false;
}
return true;
}
@Override
public boolean matchesAll(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(!filter.test(data[i])) return false;
}
return true;
}
@Override
public boolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(data[i])) return data[i];
}
return false;
}
@Override
public boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = identity;
for(int i = 0;i<size;i++) {
state = operator.applyAsBoolean(state, data[i]);
}
return state;
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
for(int i = 0;i<size;i++) {
if(empty) {
empty = false;
state = data[i];
continue;
}
state = operator.applyAsBoolean(state, data[i]);
}
return state;
}
@Override
public int count(BooleanPredicate filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0;i<size;i++) {
if(filter.test(data[i])) result++;
}
return result;
}
/**
* A Type-Specific set function to reduce (un)boxing
* @param index the index of the element to set
* @param e the value that should be set
* @return the previous element
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override
public boolean set(int index, boolean e) {
checkRange(index);
boolean old = data[index];
data[index] = e;
return old;
}
/**
* A function to replace all values in the list
* @param o the action to replace the values
* @throws NullPointerException if o is null
*/
@Override
@Deprecated
public void replaceAll(UnaryOperator<Boolean> o) {
Objects.requireNonNull(o);
for(int i = 0;i<size;i++)
data[i] = o.apply(Boolean.valueOf(data[i])).booleanValue();
}
/**
* A Type-Specific remove function to reduce (un)boxing
* @param index the index of the element to fetch
* @return the value of the requested index
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override
public boolean removeBoolean(int index) {
checkRange(index);
boolean old = data[index];
size--;
if(index != size) System.arraycopy(data, index+1, data, index, size - index);
return old;
}
public boolean swapRemove(int index) {
checkRange(index);
boolean old = data[index];
size--;
data[index] = data[size];
return old;
}
/**
* A Type-Specific implementation of remove. This implementation iterates over the elements until it finds the element that is searched for or it runs out of elements.
* It stops after finding the first element
* @param type the element that is searched for
* @return true if the element was found and removed.
*/
@Override
public boolean remBoolean(boolean type) {
int index = indexOf(type);
if(index == -1) return false;
removeBoolean(index);
return true;
}
/**
* A Type-Specific pop function to reduce (un)boxing
* @return the value of the requested index
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override
public boolean pop() {
return removeBoolean(size() - 1);
}
/**
* A function to remove all elements that were provided in the other collection
* This function might delegate to a more appropriate function if necessary
* @param c the elements that should be removed
* @return true if the collection was modified
* @throws NullPointerException if the collection is null
*/
@Override
@Deprecated
public boolean removeAll(Collection<?> c) {
if(c.isEmpty()) return false;
boolean modified = false;
int j = 0;
for(int i = 0;i<size;i++) {
if(!c.contains(Boolean.valueOf(data[i]))) data[j++] = data[i];
else modified = true;
}
size = j;
return modified;
}
/**
* A function to retain all elements that were provided in the other collection
* This function might delegate to a more appropriate function if necessary
* @param c the elements that should be kept. If empty, BooleanArrayList#clear is called.
* @return true if the collection was modified
* @throws NullPointerException if the collection is null
*/
@Override
@Deprecated
public boolean retainAll(Collection<?> c) {
if(c.isEmpty()) {
boolean modifed = size > 0;
clear();
return modifed;
}
boolean modified = false;
int j = 0;
for(int i = 0;i<size;i++) {
if(c.contains(Boolean.valueOf(data[i]))) data[j++] = data[i];
else modified = true;
}
size = j;
return modified;
}
/**
* A optimized List#removeIf(Predicate) that more quickly removes elements from the list then the ArrayList implementation
* @param filter the filter to remove elements
* @return true if the list was modified
*/
@Override
@Deprecated
public boolean removeIf(Predicate<? super Boolean> filter) {
Objects.requireNonNull(filter);
boolean modified = false;
int j = 0;
for(int i = 0;i<size;i++) {
if(!filter.test(Boolean.valueOf(data[i]))) data[j++] = data[i];
else modified = true;
}
size = j;
return modified;
}
/**
* A function to remove all elements that were provided in the other collection
* @param c the elements that should be removed
* @return true if the collection was modified
* @throws NullPointerException if the collection is null
*/
@Override
public boolean removeAll(BooleanCollection c) {
if(c.isEmpty()) return false;
boolean modified = false;
int j = 0;
for(int i = 0;i<size;i++) {
if(!c.contains(data[i])) data[j++] = data[i];
else modified = true;
}
size = j;
return modified;
}
@Override
public boolean removeAll(BooleanCollection c, BooleanConsumer r) {
if(c.isEmpty()) return false;
int j = 0;
for(int i = 0;i<size;i++) {
if(!c.contains(data[i])) data[j++] = data[i];
else r.accept(data[i]);
}
boolean modified = j != size;
size = j;
return modified;
}
/**
* A function to retain all elements that were provided in the other collection
* This function might delegate to a more appropriate function if necessary
* @param c the elements that should be kept. If empty, BooleanArrayList#clear is called.
* @return true if the collection was modified
* @throws NullPointerException if the collection is null
*/
@Override
public boolean retainAll(BooleanCollection c) {
if(c.isEmpty()) {
boolean modifed = size > 0;
clear();
return modifed;
}
boolean modified = false;
int j = 0;
for(int i = 0;i<size;i++) {
if(c.contains(data[i])) data[j++] = data[i];
else modified = true;
}
size = j;
return modified;
}
@Override
public boolean retainAll(BooleanCollection c, BooleanConsumer r) {
if(c.isEmpty()) {
boolean modifed = size > 0;
forEach(r);
clear();
return modifed;
}
int j = 0;
for(int i = 0;i<size;i++) {
if(c.contains(data[i])) data[j++] = data[i];
else r.accept(data[i]);
}
boolean modified = j != size;
size = j;
return modified;
}
/**
* A toArray implementation that ensures the Array itself is a Object.
* @return a Array of the elements in the list
*/
@Override
@Deprecated
public Object[] toArray() {
if(size == 0) return ObjectArrays.EMPTY_ARRAY;
Object[] obj = new Object[size];
for(int i = 0;i<size;i++)
obj[i] = Boolean.valueOf(data[i]);
return obj;
}
/**
* A toArray implementation that ensures the Array itself is a Object.
* @param a original array. If null a Object array with the right size is created. If to small the Array of the same type is created with the right size
* @return a Array of the elements in the list
*/
@Override
@Deprecated
public <E> E[] toArray(E[] a) {
if(a == null) a = (E[])new Object[size];
else if(a.length < size) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size);
for(int i = 0;i<size;i++)
a[i] = (E)Boolean.valueOf(data[i]);
if (a.length > size) a[size] = null;
return a;
}
@Override
public boolean[] toBooleanArray(boolean[] a) {
if(a.length < size) a = new boolean[size];
System.arraycopy(data, 0, a, 0, size);
if (a.length > size) a[size] = false;
return a;
}
/**
* A function to return the size of the list
* @return the size of elements in the list
*/
@Override
public int size() {
return size;
}
/**
* A function to ensure the elements are within the requested size.
* If smaller then the stored elements they get removed as needed.
* If bigger it is ensured that enough room is provided depending on the implementation
* @param size the requested amount of elements/room for elements
*/
@Override
public void size(int size) {
if(size > data.length)
data = Arrays.copyOf(data, size);
else if(size < size() && size >= 0)
Arrays.fill(data, size, size(), false);
this.size = size;
}
/**
* A function to clear all elements in the list.
*/
@Override
public void clear() {
size = 0;
}
/**
* Trims the original collection down to the size of the current elements or the requested size depending which is bigger
* @param size the requested trim size.
*/
@Override
public boolean trim(int size) {
if(size > size() || size() == data.length) return false;
int value = Math.max(size, size());
data = value == 0 ? BooleanArrays.EMPTY_ARRAY : Arrays.copyOf(data, value);
return true;
}
/**
* Trims the collection down to the requested size and clears all elements while doing so
* @param size the amount of elements that should be allowed
* @note this will enforce minimum size of the collection itself
*/
@Override
public void clearAndTrim(int size) {
if(data.length <= size) {
clear();
return;
}
data = size == 0 ? BooleanArrays.EMPTY_ARRAY : new boolean[size];
this.size = size;
}
/**
* Increases the capacity of this implementation instance, if necessary,
* to ensure that it can hold at least the number of elements specified by
* the minimum capacity argument.
*
* @param size the desired minimum capacity
*/
@Override
public void ensureCapacity(int size) {
grow(size);
}
@Override
public BooleanArrayList copy() {
BooleanArrayList list = new BooleanArrayList();
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 == BooleanArrays.EMPTY_ARRAY ? Math.max(DEFAULT_ARRAY_SIZE, capacity) : (int)Math.max(Math.min((long)data.length + (data.length >> 1), SanityChecks.MAX_ARRAY_SIZE), capacity));
}
protected void checkRange(int index) {
if (index < 0 || index >= size)
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
}
protected void checkAddRange(int index) {
if (index < 0 || index > size)
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
}
/**
* A Type Specific Type Splititerator to reduce boxing/unboxing
* @return type specific splititerator
* @note characteristics are ordered, sized, subsized
*/
@Override
public BooleanSplititerator spliterator() { return BooleanSplititerators.createArraySplititerator(data, size, 16464); }
}
File diff suppressed because it is too large Load Diff
@@ -1,455 +0,0 @@
package speiger.src.collections.booleans.lists;
import java.util.List;
import java.util.Objects;
import java.util.Comparator;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanSplititerator;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.utils.BooleanArrays;
import speiger.src.collections.booleans.utils.BooleanLists;
import speiger.src.collections.booleans.utils.BooleanSplititerators;
/**
* A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features
*/
public interface BooleanList extends BooleanCollection, List<Boolean>
{
/**
* A Type-Specific add Function to reduce (un)boxing
* @param e the element to add
* @return true if the list was modified
* @see List#add(Object)
*/
@Override
public boolean add(boolean e);
/**
* A Type-Specific add Function to reduce (un)boxing
* @param e the element to add
* @param index index at which the specified element is to be inserted
* @see List#add(int, Object)
*/
public void add(int index, boolean e);
/**
* A Helper function that will only add elements if it is not present.
* @param e the element to add
* @return true if the list was modified
*/
public default boolean addIfAbsent(boolean e) {
if(indexOf(e) == -1) return add(e);
return false;
}
/**
* A Helper function that will only add elements if it is present.
* @param e the element to add
* @return true if the list was modified
*/
public default boolean addIfPresent(boolean e) {
if(indexOf(e) != -1) return add(e);
return false;
}
/**
* A Type-Specific addAll Function to reduce (un)boxing
* @param c the elements that need to be added
* @param index index at which the specified elements is to be inserted
* @return true if the list was modified
* @see java.util.List#addAll(int, java.util.Collection)
*/
public boolean addAll(int index, BooleanCollection c);
/**
* A Type-Specific and optimized addAll function that allows a faster transfer of elements
* @param c the elements that need to be added
* @return true if the list was modified
*/
public boolean addAll(BooleanList c);
/**
* A Type-Specific and optimized addAll function that allows a faster transfer of elements
* @param c the elements that need to be added
* @param index index at which the specified elements is to be inserted
* @return true if the list was modified
*/
public boolean addAll(int index, BooleanList c);
/**
* Helper method that returns the first element of a List.
* This function was introduced due to how annoying it is to get/remove the last element of a list.
* This simplifies this process a bit.
* @return first element of the list
*/
public default boolean getFirstBoolean() {
return getBoolean(0);
}
/**
* Helper method that returns the last element of a List.
* This function was introduced due to how annoying it is to get/remove the last element of a list.
* This simplifies this process a bit.
* @return last element of the list
*/
public default boolean getLastBoolean() {
return getBoolean(size() - 1);
}
/**
* Helper method that removes and returns the first element of a List.
* This function was introduced due to how annoying it is to get/remove the last element of a list.
* This simplifies this process a bit.
* @return first element of the list and removes it
*/
public default boolean removeFirstBoolean() {
return removeBoolean(0);
}
/**
* Helper method that removes and returns the last element of a List.
* This function was introduced due to how annoying it is to get/remove the last element of a list.
* This simplifies this process a bit.
* @return last element of the list and removes it
*/
public default boolean removeLastBoolean() {
return removeBoolean(size() - 1);
}
/**
* A Type-Specific get function to reduce (un)boxing
* @param index the index of the value that is requested
* @return the value at the given index
* @throws IndexOutOfBoundsException if the index is not within the list range
* @see List#get(int)
*/
public boolean getBoolean(int index);
/**
* A Type-Specific set function to reduce (un)boxing
* @param index index of the element to replace
* @param e element to be stored at the specified position
* @return the element previously at the specified position
* @throws IndexOutOfBoundsException if the index is not within the list range
* @see List#set(int, Object)
*/
public boolean set(int index, boolean e);
/**
* A Type-Specific remove function to reduce (un)boxing
* @param index the index of the element to be removed
* @return the element previously at the specified position
* @see List#remove(int)
*/
public boolean removeBoolean(int index);
/**
* A Type-Specific indexOf function to reduce (un)boxing
* @param e the element that is searched for
* @return the index of the element if found. (if not found then -1)
* @note does not support null values
*/
public int indexOf(boolean e);
/**
* A Type-Specific lastIndexOf function to reduce (un)boxing
* @param e the element that is searched for
* @return the lastIndex of the element if found. (if not found then -1)
* @note does not support null values
*/
public int lastIndexOf(boolean e);
/**
* A function to fast add elements to the list
* @param a the elements that should be added
* @throws IndexOutOfBoundsException if from is outside of the lists range
*/
public default void addElements(boolean... a) { addElements(size(), a, 0, a.length); }
/**
* A function to fast add elements to the list
* @param from the index where the elements should be added into the list
* @param a the elements that should be added
* @throws IndexOutOfBoundsException if from is outside of the lists range
*/
public default void addElements(int from, boolean... a) { addElements(from, a, 0, a.length); }
/**
* A function to fast add elements to the list
* @param from the index where the elements should be added into the list
* @param a the elements that should be added
* @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
*/
public void addElements(int from, boolean[] a, int offset, int length);
/**
* A function to fast fetch elements from the list
* @param from index where the list should be fetching elements from
* @param a the array where the values should be inserted to
* @return the inputArray
* @throws NullPointerException if the array is null
* @throws IndexOutOfBoundsException if from is outside of the lists range
* @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length
*/
public default boolean[] getElements(int from, boolean[] a) { return getElements(from, a, 0, a.length); }
/**
* A function to fast fetch elements from the list
* @param from index where the list should be fetching elements from
* @param a the array where the values should be inserted to
* @param offset the startIndex of where the array should be written to
* @param length the number of elements the values should be fetched from
* @return the inputArray
* @throws NullPointerException if the array is null
* @throws IndexOutOfBoundsException if from is outside of the lists range
* @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length
*/
public boolean[] getElements(int from, boolean[] a, int offset, int length);
/**
* a function to fast remove elements from the list.
* @param from the start index of where the elements should be removed from (inclusive)
* @param to the end index of where the elements should be removed to (exclusive)
*/
public void removeElements(int from, int to);
/**
* A Highly Optimized remove function that removes the desired element.
* But instead of shifting the elements to the left it moves the last element to the removed space.
* @param index the index of the element to be removed
* @return the element previously at the specified position
*/
public boolean swapRemove(int index);
/**
* A Highly Optimized remove function that removes the desired element.
* But instead of shifting the elements to the left it moves the last element to the removed space.
* @param e the element that should be removed
* @return true if the element was removed
*/
public boolean swapRemoveBoolean(boolean e);
/**
* A function to fast extract elements out of the list, this removes the elements that were fetched.
* @param from the start index of where the elements should be fetched from (inclusive)
* @param to the end index of where the elements should be fetched to (exclusive)
* @return a array of the elements that were fetched
*/
public boolean[] extractElements(int from, int to);
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
default void sort(Comparator<? super Boolean> c) {
sort((K, V) -> c.compare(Boolean.valueOf(K), Boolean.valueOf(V)));
}
/**
* Sorts the elements specified by the Natural order either by using the Comparator or the elements
* @param c the sorter of the elements, can be null
* @see java.util.List#sort(Comparator)
* @see BooleanArrays#stableSort(boolean[], BooleanComparator)
*/
public default void sort(BooleanComparator c) {
boolean[] array = toBooleanArray();
if(c != null) BooleanArrays.stableSort(array, c);
else BooleanArrays.stableSort(array);
BooleanListIterator iter = listIterator();
for (int i = 0,m=size();i<m && iter.hasNext();i++) {
iter.nextBoolean();
iter.set(array[i]);
}
}
/**
* <p>This default implementation delegates to the corresponding type-specific function.
* @param c the sorter of the elements, can be null
* @deprecated Please use the corresponding type-specific function instead.
*/
@Deprecated
public default void unstableSort(Comparator<? super Boolean> c) {
unstableSort((K, V) -> c.compare(Boolean.valueOf(K), Boolean.valueOf(V)));
}
/**
* Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort
* @param c the sorter of the elements, can be null
* @see java.util.List#sort(Comparator)
* @see BooleanArrays#unstableSort(boolean[], BooleanComparator)
*/
public default void unstableSort(BooleanComparator c) {
boolean[] array = toBooleanArray();
if(c != null) BooleanArrays.unstableSort(array, c);
else BooleanArrays.unstableSort(array);
BooleanListIterator iter = listIterator();
for (int i = 0,m=size();i<m && iter.hasNext();i++) {
iter.nextBoolean();
iter.set(array[i]);
}
}
/**
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
* @param action The action to be performed for each element
* @throws java.lang.NullPointerException if the specified action is null
*/
@Override
public default void forEachIndexed(IntBooleanConsumer action) {
Objects.requireNonNull(action);
for(int i = 0,m=size();i<m;action.accept(i, getBoolean(i++)));
}
/**
* A Type-Specific Iterator of listIterator
* @see java.util.List#listIterator
*/
@Override
public BooleanListIterator listIterator();
/**
* A Type-Specific Iterator of listIterator
* @see java.util.List#listIterator(int)
*/
@Override
public BooleanListIterator listIterator(int index);
/**
* A Type-Specific List of subList
* @see java.util.List#subList(int, int)
*/
@Override
public BooleanList subList(int from, int to);
/**
* A Type-Specific List Helper that shows all elements in reverse.
* @return a list wrapper that has all elements reversed!
*/
public BooleanList reversed();
/**
* Creates a Wrapped List that is Synchronized
* @return a new List that is synchronized
* @see BooleanLists#synchronize
*/
public default BooleanList synchronize() { return BooleanLists.synchronize(this); }
/**
* Creates a Wrapped List that is Synchronized
* @param mutex is the controller of the synchronization block
* @return a new List Wrapper that is synchronized
* @see BooleanLists#synchronize
*/
public default BooleanList synchronize(Object mutex) { return BooleanLists.synchronize(this, mutex); }
/**
* Creates a Wrapped List that is unmodifiable
* @return a new List Wrapper that is unmodifiable
* @see BooleanLists#unmodifiable
*/
public default BooleanList unmodifiable() { return BooleanLists.unmodifiable(this); }
/**
* A function to ensure the elements are within the requested size.
* If smaller then the stored elements they get removed as needed.
* If bigger it is ensured that enough room is provided depending on the implementation
* @param size the requested amount of elements/room for elements
*/
public void size(int size);
@Override
public BooleanList copy();
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default boolean add(Boolean e) {
return BooleanCollection.super.add(e);
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default Boolean get(int index) {
return Boolean.valueOf(getBoolean(index));
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default Boolean set(int index, Boolean e) {
return Boolean.valueOf(set(index, e.booleanValue()));
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default int indexOf(Object o) {
return indexOf(((Boolean)o).booleanValue());
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default int lastIndexOf(Object o) {
return lastIndexOf(((Boolean)o).booleanValue());
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default boolean contains(Object o) {
return BooleanCollection.super.contains(o);
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default boolean remove(Object o) {
return BooleanCollection.super.remove(o);
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default Boolean remove(int index) {
return Boolean.valueOf(removeBoolean(index));
}
/**
* A Type Specific Type Splititerator to reduce boxing/unboxing
* @return type specific splititerator
*/
@Override
default BooleanSplititerator spliterator() { return BooleanSplititerators.createSplititerator(this, 0); }
}
@@ -1,65 +0,0 @@
package speiger.src.collections.booleans.lists;
import java.util.ListIterator;
import speiger.src.collections.booleans.collections.BooleanBidirectionalIterator;
/**
* A Type Specific ListIterator that reduces boxing/unboxing
*/
public interface BooleanListIterator extends ListIterator<Boolean>, BooleanBidirectionalIterator
{
/**
* A Primitive set function to reduce (un)boxing
* @param e the element that should replace the last returned value
* @see ListIterator#set(Object)
*/
public void set(boolean e);
/**
* A Primitive set function to reduce (un)boxing
* @param e the element that should be inserted before the last returned value
* @see ListIterator#set(Object)
*/
public void add(boolean e);
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default Boolean previous() {
return BooleanBidirectionalIterator.super.previous();
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default Boolean next() {
return BooleanBidirectionalIterator.super.next();
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default void set(Boolean e) {
set(e.booleanValue());
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default void add(Boolean e) {
add(e.booleanValue());
}
}
@@ -1,482 +0,0 @@
package speiger.src.collections.booleans.lists;
import java.util.Arrays;
import java.util.Collection;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.utils.BooleanArrays;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.function.BooleanBooleanUnaryOperator;
import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.booleans.utils.BooleanIterators;
import speiger.src.collections.booleans.collections.BooleanSplititerator;
import speiger.src.collections.booleans.utils.BooleanSplititerators;
import speiger.src.collections.utils.SanityChecks;
/**
* A Type-Specific Immutable implementation of list that is written to reduce (un)boxing
*/
public class ImmutableBooleanList extends AbstractBooleanList
{
/** The backing array */
protected transient boolean[] data;
/**
* Creates a new Immutable copy of the contents of the Collection.
* @param c the elements that should be added into the list
*/
@Deprecated
public ImmutableBooleanList(Collection<? extends Boolean> c) {
data = BooleanArrays.pour(BooleanIterators.wrap(c.iterator()));
}
/**
* Creates a new Immutable copy of the contents of the Collection.
* @param c the elements that should be added into the list
*/
public ImmutableBooleanList(BooleanCollection c) {
data = BooleanArrays.pour(c.iterator());
}
/**
* Creates a new Immutable copy of the contents of the List.
* @param l the elements that should be added into the list
*/
public ImmutableBooleanList(BooleanList l) {
boolean[] temp = new boolean[l.size()];
l.getElements(0, temp, 0, l.size());
data = temp;
}
/**
* Creates a new Immutable copy of the contents of the Array.
* @param a the array that should be copied
*/
public ImmutableBooleanList(boolean... a) {
this(a, 0, a.length);
}
/**
* Creates a new ImmutableList copy of the array with a custom length
* @param a the array that should be copied
* @param length the desired length that should be copied
*/
public ImmutableBooleanList(boolean[] a, int length) {
this(a, 0, length);
}
/**
* Creates a new ImmutableList copy of the array with in the custom range.
* @param a the array that should be copied
* @param offset the starting offset of where the array should be copied from
* @param length the desired length that should be copied
* @throws IllegalStateException if offset is smaller then 0
* @throws IllegalStateException if the offset + length exceeds the array length
*/
public ImmutableBooleanList(boolean[] a, int offset, int length) {
SanityChecks.checkArrayCapacity(a.length, offset, length);
data = Arrays.copyOfRange(a, offset, offset+length);
}
@Override
public boolean add(boolean e) { throw new UnsupportedOperationException(); }
@Override
public void add(int index, boolean e) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean addAll(int index, Collection<? extends Boolean> c) { throw new UnsupportedOperationException(); }
@Override
public boolean addAll(int index, BooleanCollection c) { throw new UnsupportedOperationException(); }
@Override
public boolean addAll(int index, BooleanList c) { throw new UnsupportedOperationException(); }
@Override
public boolean addAll(boolean[] e, int offset, int length) { throw new UnsupportedOperationException(); }
@Override
public void addElements(int from, boolean[] a, int offset, int length) { throw new UnsupportedOperationException(); }
@Override
public boolean[] getElements(int from, boolean[] a, int offset, int length) {
SanityChecks.checkArrayCapacity(a.length, offset, length);
SanityChecks.checkArrayCapacity(data.length, from, length);
System.arraycopy(data, from, a, offset, length);
return a;
}
@Override
public void removeElements(int from, int to) { throw new UnsupportedOperationException(); }
@Override
public boolean[] extractElements(int from, int to) { throw new UnsupportedOperationException(); }
/**
* A function to find if the Element is present in this list.
* @param o the element that is searched for
* @return if the element was found.
*/
@Override
@Deprecated
public boolean contains(Object o) {
return indexOf(o) != -1;
}
/**
* A function to find the index of a given element
* @param o the element that is searched for
* @return the index of the element if found. (if not found then -1)
*/
@Override
@Deprecated
public int indexOf(Object o) {
if(o == null) return -1;
for(int i = 0,m=data.length;i<m;i++) {
if(Objects.equals(o, Boolean.valueOf(data[i]))) return i;
}
return -1;
}
/**
* A function to find the last index of a given element
* @param o the element that is searched for
* @return the last index of the element if found. (if not found then -1)
*/
@Override
@Deprecated
public int lastIndexOf(Object o) {
if(o == null) return -1;
for(int i = data.length - 1;i>=0;i--) {
if(Objects.equals(o, Boolean.valueOf(data[i]))) return i;
}
return -1;
}
/**
* A Type Specific implementation of the Collection#contains function.
* @param e the element that is searched for.
* @return if the element was found
*/
@Override
public boolean contains(boolean e) {
return indexOf(e) != -1;
}
/**
* A Type-Specific function to find the index of a given element
* @param e the element that is searched for
* @return the index of the element if found. (if not found then -1)
*/
@Override
public int indexOf(boolean e) {
for(int i = 0,m=data.length;i<m;i++) {
if(data[i] == e) return i;
}
return -1;
}
/**
* A Type-Specific function to find the last index of a given element
* @param e the element that is searched for
* @return the last index of the element if found. (if not found then -1)
*/
@Override
public int lastIndexOf(boolean e) {
for(int i = data.length - 1;i>=0;i--) {
if(data[i] == e) return i;
}
return -1;
}
@Override
public void sort(BooleanComparator c) { throw new UnsupportedOperationException(); }
@Override
public void unstableSort(BooleanComparator c) { throw new UnsupportedOperationException(); }
/**
* A Type-Specific get function to reduce (un)boxing
* @param index the index of the element to fetch
* @return the value of the requested index
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override
public boolean getBoolean(int index) {
checkRange(index);
return data[index];
}
@Override
public ImmutableBooleanList copy() {
return new ImmutableBooleanList(Arrays.copyOf(data, data.length));
}
/**
* A Type Specific foreach function that reduces (un)boxing
*
* @implSpec
* <p>The default implementation behaves as if:
* <pre>{@code
* for(int i = 0;i<size;i++)
* action.accept(data[i]);
* }</pre>
*
* @param action The action to be performed for each element
* @throws NullPointerException if the specified action is null
* @see Iterable#forEach(java.util.function.Consumer)
*/
@Override
public void forEach(BooleanConsumer action) {
Objects.requireNonNull(action);
for(int i = 0,m=data.length;i<m;i++)
action.accept(data[i]);
}
@Override
public <E> void forEach(E input, ObjectBooleanConsumer<E> action) {
Objects.requireNonNull(action);
for(int i = 0,m=data.length;i<m;i++)
action.accept(input, data[i]);
}
@Override
public boolean matchesAny(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=data.length;i<m;i++) {
if(filter.test(data[i])) return true;
}
return false;
}
@Override
public boolean matchesNone(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=data.length;i<m;i++) {
if(filter.test(data[i])) return false;
}
return true;
}
@Override
public boolean matchesAll(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=data.length;i<m;i++) {
if(!filter.test(data[i])) return false;
}
return true;
}
@Override
public boolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=data.length;i<m;i++) {
if(filter.test(data[i])) return data[i];
}
return false;
}
@Override
public boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = identity;
for(int i = 0,m=data.length;i<m;i++) {
state = operator.applyAsBoolean(state, data[i]);
}
return state;
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
for(int i = 0,m=data.length;i<m;i++) {
if(empty) {
empty = false;
state = data[i];
continue;
}
state = operator.applyAsBoolean(state, data[i]);
}
return state;
}
@Override
public int count(BooleanPredicate filter) {
Objects.requireNonNull(filter);
int result = 0;
for(int i = 0,m=data.length;i<m;i++) {
if(filter.test(data[i])) result++;
}
return result;
}
@Override
public BooleanListIterator listIterator(int index) {
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
return new BooleanListIter(index);
}
@Override
public boolean set(int index, boolean e) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public void replaceAll(UnaryOperator<Boolean> o) { throw new UnsupportedOperationException(); }
@Override
public boolean removeBoolean(int index) { throw new UnsupportedOperationException(); }
@Override
public boolean swapRemove(int index) { throw new UnsupportedOperationException(); }
@Override
public boolean remBoolean(boolean type) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean removeIf(Predicate<? super Boolean> filter) { throw new UnsupportedOperationException(); }
@Override
public boolean removeAll(BooleanCollection c) { throw new UnsupportedOperationException(); }
@Override
public boolean retainAll(BooleanCollection c) { throw new UnsupportedOperationException(); }
@Override
public boolean removeAll(BooleanCollection c, BooleanConsumer r) { throw new UnsupportedOperationException(); }
@Override
public boolean retainAll(BooleanCollection c, BooleanConsumer r) { throw new UnsupportedOperationException(); }
/**
* A toArray implementation that ensures the Array itself is a Object.
* @return a Array of the elements in the list
*/
@Override
@Deprecated
public Object[] toArray() {
if(data.length == 0) return ObjectArrays.EMPTY_ARRAY;
Object[] obj = new Object[data.length];
for(int i = 0,m=data.length;i<m;i++)
obj[i] = Boolean.valueOf(data[i]);
return obj;
}
/**
* A toArray implementation that ensures the Array itself is a Object.
* @param a original array. If null a Object array with the right size is created. If to small the Array of the same type is created with the right size
* @return a Array of the elements in the list
*/
@Override
@Deprecated
public <E> E[] toArray(E[] a) {
if(a == null) a = (E[])new Object[data.length];
else if(a.length < data.length) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), data.length);
for(int i = 0,m=data.length;i<m;i++)
a[i] = (E)Boolean.valueOf(data[i]);
if (a.length > data.length) a[data.length] = null;
return a;
}
@Override
public boolean[] toBooleanArray(boolean[] a) {
if(a.length < data.length) a = new boolean[data.length];
System.arraycopy(data, 0, a, 0, data.length);
if (a.length > data.length) a[data.length] = false;
return a;
}
/**
* A function to return the size of the list
* @return the size of elements in the list
*/
@Override
public int size() {
return data.length;
}
@Override
public void size(int size) { throw new UnsupportedOperationException(); }
@Override
public void clear() { throw new UnsupportedOperationException(); }
protected void checkRange(int index) {
if (index < 0 || index >= data.length)
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + data.length);
}
/**
* A Type Specific Type Splititerator to reduce boxing/unboxing
* @return type specific splititerator
* @note characteristics are ordered, sized, subsized
*/
@Override
public BooleanSplititerator spliterator() { return BooleanSplititerators.createArraySplititerator(data, data.length, 16464); }
private class BooleanListIter implements BooleanListIterator {
int index;
BooleanListIter(int index) {
this.index = index;
}
@Override
public boolean hasNext() {
return index < size();
}
@Override
public boolean nextBoolean() {
if(!hasNext()) throw new NoSuchElementException();
return getBoolean(index++);
}
@Override
public boolean hasPrevious() {
return index > 0;
}
@Override
public boolean previousBoolean() {
if(!hasPrevious()) throw new NoSuchElementException();
return getBoolean(--index);
}
@Override
public int nextIndex() {
return index;
}
@Override
public int previousIndex() {
return index-1;
}
@Override
public void remove() { throw new UnsupportedOperationException(); }
@Override
public void set(boolean e) { throw new UnsupportedOperationException(); }
@Override
public void add(boolean e) { throw new UnsupportedOperationException(); }
@Override
public int skip(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, size() - index);
index += steps;
return steps;
}
@Override
public int back(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, index);
index -= steps;
return steps;
}
}
}
@@ -1,132 +0,0 @@
package speiger.src.collections.booleans.misc.pairs;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanBooleanImmutablePair;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanBooleanMutablePair;
/**
* Key Value Pair Interface that allows to reduce boxing/unboxing.
*/
public interface BooleanBooleanPair
{
/**
* Empty Reference for Immutable Pairs
*/
public static final BooleanBooleanPair EMPTY = new BooleanBooleanImmutablePair();
/**
* @return empty Immutable Pair
*/
public static BooleanBooleanPair of() {
return EMPTY;
}
/**
* @param key the key that should be in the pair
* @return Immutable Pair of Key
*/
public static BooleanBooleanPair ofKey(boolean key) {
return new BooleanBooleanImmutablePair(key, false);
}
/**
* @param value the value that should be in the pair
* @return Immutable Pair of Value
*/
public static BooleanBooleanPair ofValue(boolean value) {
return new BooleanBooleanImmutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Immutable Pair of key and value
*/
public static BooleanBooleanPair of(boolean key, boolean value) {
return new BooleanBooleanImmutablePair(key, value);
}
/**
* @param pair the Pair that should be immutably copied
* @return a Immutable Copy of the Provided Pair
*/
public static BooleanBooleanPair of(BooleanBooleanPair pair) {
return new BooleanBooleanImmutablePair(pair.getBooleanKey(), pair.getBooleanValue());
}
/**
* @return empty Mutable Pair
*/
public static BooleanBooleanPair mutable() {
return new BooleanBooleanMutablePair();
}
/**
* @param key the key that should be in the pair
* @return Mutable Pair of key
*/
public static BooleanBooleanPair mutableKey(boolean key) {
return new BooleanBooleanMutablePair(key, false);
}
/**
* @param value the value that should be in the pair
* @return Mutable Pair of value
*/
public static BooleanBooleanPair mutableValue(boolean value) {
return new BooleanBooleanMutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Mutable Pair of key and value
*/
public static BooleanBooleanPair mutable(boolean key, boolean value) {
return new BooleanBooleanMutablePair(key, value);
}
/**
* @param pair the Pair that should be copied
* @return a Mutable Copy of the Provided Pair
*/
public static BooleanBooleanPair mutable(BooleanBooleanPair pair) {
return new BooleanBooleanMutablePair(pair.getBooleanKey(), pair.getBooleanValue());
}
/**
* Sets the Key of the Pair.
* @param key the key that should be set.
* @return self or a new Pair instance with the new key.
*/
public BooleanBooleanPair setBooleanKey(boolean key);
/**
* @return the Key of the Pair
*/
public boolean getBooleanKey();
/**
* Sets the Value of the Pair.
* @param value the value that should be set.
* @return self or a new Pair instance with the new value.
*/
public BooleanBooleanPair setBooleanValue(boolean value);
/**
* @return the Value of the Pair
*/
public boolean getBooleanValue();
/**
* Sets key and value of the Pair
* @param key the key that should be set.
* @param value the value that should be set.
* @return self or a new Pair instance with the new key and value.
*/
public BooleanBooleanPair set(boolean key, boolean value);
/**
* Clones the Pair if it is mutable.
* @return a New Mutable Instance if it is mutable
*/
public BooleanBooleanPair shallowCopy();
}
@@ -1,132 +0,0 @@
package speiger.src.collections.booleans.misc.pairs;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanByteImmutablePair;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanByteMutablePair;
/**
* Key Value Pair Interface that allows to reduce boxing/unboxing.
*/
public interface BooleanBytePair
{
/**
* Empty Reference for Immutable Pairs
*/
public static final BooleanBytePair EMPTY = new BooleanByteImmutablePair();
/**
* @return empty Immutable Pair
*/
public static BooleanBytePair of() {
return EMPTY;
}
/**
* @param key the key that should be in the pair
* @return Immutable Pair of Key
*/
public static BooleanBytePair ofKey(boolean key) {
return new BooleanByteImmutablePair(key, (byte)0);
}
/**
* @param value the value that should be in the pair
* @return Immutable Pair of Value
*/
public static BooleanBytePair ofValue(byte value) {
return new BooleanByteImmutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Immutable Pair of key and value
*/
public static BooleanBytePair of(boolean key, byte value) {
return new BooleanByteImmutablePair(key, value);
}
/**
* @param pair the Pair that should be immutably copied
* @return a Immutable Copy of the Provided Pair
*/
public static BooleanBytePair of(BooleanBytePair pair) {
return new BooleanByteImmutablePair(pair.getBooleanKey(), pair.getByteValue());
}
/**
* @return empty Mutable Pair
*/
public static BooleanBytePair mutable() {
return new BooleanByteMutablePair();
}
/**
* @param key the key that should be in the pair
* @return Mutable Pair of key
*/
public static BooleanBytePair mutableKey(boolean key) {
return new BooleanByteMutablePair(key, (byte)0);
}
/**
* @param value the value that should be in the pair
* @return Mutable Pair of value
*/
public static BooleanBytePair mutableValue(byte value) {
return new BooleanByteMutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Mutable Pair of key and value
*/
public static BooleanBytePair mutable(boolean key, byte value) {
return new BooleanByteMutablePair(key, value);
}
/**
* @param pair the Pair that should be copied
* @return a Mutable Copy of the Provided Pair
*/
public static BooleanBytePair mutable(BooleanBytePair pair) {
return new BooleanByteMutablePair(pair.getBooleanKey(), pair.getByteValue());
}
/**
* Sets the Key of the Pair.
* @param key the key that should be set.
* @return self or a new Pair instance with the new key.
*/
public BooleanBytePair setBooleanKey(boolean key);
/**
* @return the Key of the Pair
*/
public boolean getBooleanKey();
/**
* Sets the Value of the Pair.
* @param value the value that should be set.
* @return self or a new Pair instance with the new value.
*/
public BooleanBytePair setByteValue(byte value);
/**
* @return the Value of the Pair
*/
public byte getByteValue();
/**
* Sets key and value of the Pair
* @param key the key that should be set.
* @param value the value that should be set.
* @return self or a new Pair instance with the new key and value.
*/
public BooleanBytePair set(boolean key, byte value);
/**
* Clones the Pair if it is mutable.
* @return a New Mutable Instance if it is mutable
*/
public BooleanBytePair shallowCopy();
}
@@ -1,132 +0,0 @@
package speiger.src.collections.booleans.misc.pairs;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanCharImmutablePair;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanCharMutablePair;
/**
* Key Value Pair Interface that allows to reduce boxing/unboxing.
*/
public interface BooleanCharPair
{
/**
* Empty Reference for Immutable Pairs
*/
public static final BooleanCharPair EMPTY = new BooleanCharImmutablePair();
/**
* @return empty Immutable Pair
*/
public static BooleanCharPair of() {
return EMPTY;
}
/**
* @param key the key that should be in the pair
* @return Immutable Pair of Key
*/
public static BooleanCharPair ofKey(boolean key) {
return new BooleanCharImmutablePair(key, (char)0);
}
/**
* @param value the value that should be in the pair
* @return Immutable Pair of Value
*/
public static BooleanCharPair ofValue(char value) {
return new BooleanCharImmutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Immutable Pair of key and value
*/
public static BooleanCharPair of(boolean key, char value) {
return new BooleanCharImmutablePair(key, value);
}
/**
* @param pair the Pair that should be immutably copied
* @return a Immutable Copy of the Provided Pair
*/
public static BooleanCharPair of(BooleanCharPair pair) {
return new BooleanCharImmutablePair(pair.getBooleanKey(), pair.getCharValue());
}
/**
* @return empty Mutable Pair
*/
public static BooleanCharPair mutable() {
return new BooleanCharMutablePair();
}
/**
* @param key the key that should be in the pair
* @return Mutable Pair of key
*/
public static BooleanCharPair mutableKey(boolean key) {
return new BooleanCharMutablePair(key, (char)0);
}
/**
* @param value the value that should be in the pair
* @return Mutable Pair of value
*/
public static BooleanCharPair mutableValue(char value) {
return new BooleanCharMutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Mutable Pair of key and value
*/
public static BooleanCharPair mutable(boolean key, char value) {
return new BooleanCharMutablePair(key, value);
}
/**
* @param pair the Pair that should be copied
* @return a Mutable Copy of the Provided Pair
*/
public static BooleanCharPair mutable(BooleanCharPair pair) {
return new BooleanCharMutablePair(pair.getBooleanKey(), pair.getCharValue());
}
/**
* Sets the Key of the Pair.
* @param key the key that should be set.
* @return self or a new Pair instance with the new key.
*/
public BooleanCharPair setBooleanKey(boolean key);
/**
* @return the Key of the Pair
*/
public boolean getBooleanKey();
/**
* Sets the Value of the Pair.
* @param value the value that should be set.
* @return self or a new Pair instance with the new value.
*/
public BooleanCharPair setCharValue(char value);
/**
* @return the Value of the Pair
*/
public char getCharValue();
/**
* Sets key and value of the Pair
* @param key the key that should be set.
* @param value the value that should be set.
* @return self or a new Pair instance with the new key and value.
*/
public BooleanCharPair set(boolean key, char value);
/**
* Clones the Pair if it is mutable.
* @return a New Mutable Instance if it is mutable
*/
public BooleanCharPair shallowCopy();
}
@@ -1,132 +0,0 @@
package speiger.src.collections.booleans.misc.pairs;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanDoubleImmutablePair;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanDoubleMutablePair;
/**
* Key Value Pair Interface that allows to reduce boxing/unboxing.
*/
public interface BooleanDoublePair
{
/**
* Empty Reference for Immutable Pairs
*/
public static final BooleanDoublePair EMPTY = new BooleanDoubleImmutablePair();
/**
* @return empty Immutable Pair
*/
public static BooleanDoublePair of() {
return EMPTY;
}
/**
* @param key the key that should be in the pair
* @return Immutable Pair of Key
*/
public static BooleanDoublePair ofKey(boolean key) {
return new BooleanDoubleImmutablePair(key, 0D);
}
/**
* @param value the value that should be in the pair
* @return Immutable Pair of Value
*/
public static BooleanDoublePair ofValue(double value) {
return new BooleanDoubleImmutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Immutable Pair of key and value
*/
public static BooleanDoublePair of(boolean key, double value) {
return new BooleanDoubleImmutablePair(key, value);
}
/**
* @param pair the Pair that should be immutably copied
* @return a Immutable Copy of the Provided Pair
*/
public static BooleanDoublePair of(BooleanDoublePair pair) {
return new BooleanDoubleImmutablePair(pair.getBooleanKey(), pair.getDoubleValue());
}
/**
* @return empty Mutable Pair
*/
public static BooleanDoublePair mutable() {
return new BooleanDoubleMutablePair();
}
/**
* @param key the key that should be in the pair
* @return Mutable Pair of key
*/
public static BooleanDoublePair mutableKey(boolean key) {
return new BooleanDoubleMutablePair(key, 0D);
}
/**
* @param value the value that should be in the pair
* @return Mutable Pair of value
*/
public static BooleanDoublePair mutableValue(double value) {
return new BooleanDoubleMutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Mutable Pair of key and value
*/
public static BooleanDoublePair mutable(boolean key, double value) {
return new BooleanDoubleMutablePair(key, value);
}
/**
* @param pair the Pair that should be copied
* @return a Mutable Copy of the Provided Pair
*/
public static BooleanDoublePair mutable(BooleanDoublePair pair) {
return new BooleanDoubleMutablePair(pair.getBooleanKey(), pair.getDoubleValue());
}
/**
* Sets the Key of the Pair.
* @param key the key that should be set.
* @return self or a new Pair instance with the new key.
*/
public BooleanDoublePair setBooleanKey(boolean key);
/**
* @return the Key of the Pair
*/
public boolean getBooleanKey();
/**
* Sets the Value of the Pair.
* @param value the value that should be set.
* @return self or a new Pair instance with the new value.
*/
public BooleanDoublePair setDoubleValue(double value);
/**
* @return the Value of the Pair
*/
public double getDoubleValue();
/**
* Sets key and value of the Pair
* @param key the key that should be set.
* @param value the value that should be set.
* @return self or a new Pair instance with the new key and value.
*/
public BooleanDoublePair set(boolean key, double value);
/**
* Clones the Pair if it is mutable.
* @return a New Mutable Instance if it is mutable
*/
public BooleanDoublePair shallowCopy();
}
@@ -1,132 +0,0 @@
package speiger.src.collections.booleans.misc.pairs;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanFloatImmutablePair;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanFloatMutablePair;
/**
* Key Value Pair Interface that allows to reduce boxing/unboxing.
*/
public interface BooleanFloatPair
{
/**
* Empty Reference for Immutable Pairs
*/
public static final BooleanFloatPair EMPTY = new BooleanFloatImmutablePair();
/**
* @return empty Immutable Pair
*/
public static BooleanFloatPair of() {
return EMPTY;
}
/**
* @param key the key that should be in the pair
* @return Immutable Pair of Key
*/
public static BooleanFloatPair ofKey(boolean key) {
return new BooleanFloatImmutablePair(key, 0F);
}
/**
* @param value the value that should be in the pair
* @return Immutable Pair of Value
*/
public static BooleanFloatPair ofValue(float value) {
return new BooleanFloatImmutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Immutable Pair of key and value
*/
public static BooleanFloatPair of(boolean key, float value) {
return new BooleanFloatImmutablePair(key, value);
}
/**
* @param pair the Pair that should be immutably copied
* @return a Immutable Copy of the Provided Pair
*/
public static BooleanFloatPair of(BooleanFloatPair pair) {
return new BooleanFloatImmutablePair(pair.getBooleanKey(), pair.getFloatValue());
}
/**
* @return empty Mutable Pair
*/
public static BooleanFloatPair mutable() {
return new BooleanFloatMutablePair();
}
/**
* @param key the key that should be in the pair
* @return Mutable Pair of key
*/
public static BooleanFloatPair mutableKey(boolean key) {
return new BooleanFloatMutablePair(key, 0F);
}
/**
* @param value the value that should be in the pair
* @return Mutable Pair of value
*/
public static BooleanFloatPair mutableValue(float value) {
return new BooleanFloatMutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Mutable Pair of key and value
*/
public static BooleanFloatPair mutable(boolean key, float value) {
return new BooleanFloatMutablePair(key, value);
}
/**
* @param pair the Pair that should be copied
* @return a Mutable Copy of the Provided Pair
*/
public static BooleanFloatPair mutable(BooleanFloatPair pair) {
return new BooleanFloatMutablePair(pair.getBooleanKey(), pair.getFloatValue());
}
/**
* Sets the Key of the Pair.
* @param key the key that should be set.
* @return self or a new Pair instance with the new key.
*/
public BooleanFloatPair setBooleanKey(boolean key);
/**
* @return the Key of the Pair
*/
public boolean getBooleanKey();
/**
* Sets the Value of the Pair.
* @param value the value that should be set.
* @return self or a new Pair instance with the new value.
*/
public BooleanFloatPair setFloatValue(float value);
/**
* @return the Value of the Pair
*/
public float getFloatValue();
/**
* Sets key and value of the Pair
* @param key the key that should be set.
* @param value the value that should be set.
* @return self or a new Pair instance with the new key and value.
*/
public BooleanFloatPair set(boolean key, float value);
/**
* Clones the Pair if it is mutable.
* @return a New Mutable Instance if it is mutable
*/
public BooleanFloatPair shallowCopy();
}
@@ -1,132 +0,0 @@
package speiger.src.collections.booleans.misc.pairs;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanIntImmutablePair;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanIntMutablePair;
/**
* Key Value Pair Interface that allows to reduce boxing/unboxing.
*/
public interface BooleanIntPair
{
/**
* Empty Reference for Immutable Pairs
*/
public static final BooleanIntPair EMPTY = new BooleanIntImmutablePair();
/**
* @return empty Immutable Pair
*/
public static BooleanIntPair of() {
return EMPTY;
}
/**
* @param key the key that should be in the pair
* @return Immutable Pair of Key
*/
public static BooleanIntPair ofKey(boolean key) {
return new BooleanIntImmutablePair(key, 0);
}
/**
* @param value the value that should be in the pair
* @return Immutable Pair of Value
*/
public static BooleanIntPair ofValue(int value) {
return new BooleanIntImmutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Immutable Pair of key and value
*/
public static BooleanIntPair of(boolean key, int value) {
return new BooleanIntImmutablePair(key, value);
}
/**
* @param pair the Pair that should be immutably copied
* @return a Immutable Copy of the Provided Pair
*/
public static BooleanIntPair of(BooleanIntPair pair) {
return new BooleanIntImmutablePair(pair.getBooleanKey(), pair.getIntValue());
}
/**
* @return empty Mutable Pair
*/
public static BooleanIntPair mutable() {
return new BooleanIntMutablePair();
}
/**
* @param key the key that should be in the pair
* @return Mutable Pair of key
*/
public static BooleanIntPair mutableKey(boolean key) {
return new BooleanIntMutablePair(key, 0);
}
/**
* @param value the value that should be in the pair
* @return Mutable Pair of value
*/
public static BooleanIntPair mutableValue(int value) {
return new BooleanIntMutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Mutable Pair of key and value
*/
public static BooleanIntPair mutable(boolean key, int value) {
return new BooleanIntMutablePair(key, value);
}
/**
* @param pair the Pair that should be copied
* @return a Mutable Copy of the Provided Pair
*/
public static BooleanIntPair mutable(BooleanIntPair pair) {
return new BooleanIntMutablePair(pair.getBooleanKey(), pair.getIntValue());
}
/**
* Sets the Key of the Pair.
* @param key the key that should be set.
* @return self or a new Pair instance with the new key.
*/
public BooleanIntPair setBooleanKey(boolean key);
/**
* @return the Key of the Pair
*/
public boolean getBooleanKey();
/**
* Sets the Value of the Pair.
* @param value the value that should be set.
* @return self or a new Pair instance with the new value.
*/
public BooleanIntPair setIntValue(int value);
/**
* @return the Value of the Pair
*/
public int getIntValue();
/**
* Sets key and value of the Pair
* @param key the key that should be set.
* @param value the value that should be set.
* @return self or a new Pair instance with the new key and value.
*/
public BooleanIntPair set(boolean key, int value);
/**
* Clones the Pair if it is mutable.
* @return a New Mutable Instance if it is mutable
*/
public BooleanIntPair shallowCopy();
}
@@ -1,132 +0,0 @@
package speiger.src.collections.booleans.misc.pairs;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanLongImmutablePair;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanLongMutablePair;
/**
* Key Value Pair Interface that allows to reduce boxing/unboxing.
*/
public interface BooleanLongPair
{
/**
* Empty Reference for Immutable Pairs
*/
public static final BooleanLongPair EMPTY = new BooleanLongImmutablePair();
/**
* @return empty Immutable Pair
*/
public static BooleanLongPair of() {
return EMPTY;
}
/**
* @param key the key that should be in the pair
* @return Immutable Pair of Key
*/
public static BooleanLongPair ofKey(boolean key) {
return new BooleanLongImmutablePair(key, 0L);
}
/**
* @param value the value that should be in the pair
* @return Immutable Pair of Value
*/
public static BooleanLongPair ofValue(long value) {
return new BooleanLongImmutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Immutable Pair of key and value
*/
public static BooleanLongPair of(boolean key, long value) {
return new BooleanLongImmutablePair(key, value);
}
/**
* @param pair the Pair that should be immutably copied
* @return a Immutable Copy of the Provided Pair
*/
public static BooleanLongPair of(BooleanLongPair pair) {
return new BooleanLongImmutablePair(pair.getBooleanKey(), pair.getLongValue());
}
/**
* @return empty Mutable Pair
*/
public static BooleanLongPair mutable() {
return new BooleanLongMutablePair();
}
/**
* @param key the key that should be in the pair
* @return Mutable Pair of key
*/
public static BooleanLongPair mutableKey(boolean key) {
return new BooleanLongMutablePair(key, 0L);
}
/**
* @param value the value that should be in the pair
* @return Mutable Pair of value
*/
public static BooleanLongPair mutableValue(long value) {
return new BooleanLongMutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Mutable Pair of key and value
*/
public static BooleanLongPair mutable(boolean key, long value) {
return new BooleanLongMutablePair(key, value);
}
/**
* @param pair the Pair that should be copied
* @return a Mutable Copy of the Provided Pair
*/
public static BooleanLongPair mutable(BooleanLongPair pair) {
return new BooleanLongMutablePair(pair.getBooleanKey(), pair.getLongValue());
}
/**
* Sets the Key of the Pair.
* @param key the key that should be set.
* @return self or a new Pair instance with the new key.
*/
public BooleanLongPair setBooleanKey(boolean key);
/**
* @return the Key of the Pair
*/
public boolean getBooleanKey();
/**
* Sets the Value of the Pair.
* @param value the value that should be set.
* @return self or a new Pair instance with the new value.
*/
public BooleanLongPair setLongValue(long value);
/**
* @return the Value of the Pair
*/
public long getLongValue();
/**
* Sets key and value of the Pair
* @param key the key that should be set.
* @param value the value that should be set.
* @return self or a new Pair instance with the new key and value.
*/
public BooleanLongPair set(boolean key, long value);
/**
* Clones the Pair if it is mutable.
* @return a New Mutable Instance if it is mutable
*/
public BooleanLongPair shallowCopy();
}
@@ -1,143 +0,0 @@
package speiger.src.collections.booleans.misc.pairs;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanObjectImmutablePair;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanObjectMutablePair;
/**
* Key Value Pair Interface that allows to reduce boxing/unboxing.
* @param <V> the keyType of elements maintained by this Collection
*/
public interface BooleanObjectPair<V>
{
/**
* Empty Reference for Immutable Pairs
*/
public static final BooleanObjectPair<?> EMPTY = new BooleanObjectImmutablePair<>();
/**
* @param <V> the keyType of elements maintained by this Collection
* @return empty Immutable Pair
*/
public static <V> BooleanObjectPair<V> of() {
return (BooleanObjectPair<V>)EMPTY;
}
/**
* @param key the key that should be in the pair
* @param <V> the keyType of elements maintained by this Collection
* @return Immutable Pair of Key
*/
public static <V> BooleanObjectPair<V> ofKey(boolean key) {
return new BooleanObjectImmutablePair<>(key, null);
}
/**
* @param value the value that should be in the pair
* @param <V> the keyType of elements maintained by this Collection
* @return Immutable Pair of Value
*/
public static <V> BooleanObjectPair<V> ofValue(V value) {
return new BooleanObjectImmutablePair<>(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @param <V> the keyType of elements maintained by this Collection
* @return Immutable Pair of key and value
*/
public static <V> BooleanObjectPair<V> of(boolean key, V value) {
return new BooleanObjectImmutablePair<>(key, value);
}
/**
* @param pair the Pair that should be immutably copied
* @param <V> the keyType of elements maintained by this Collection
* @return a Immutable Copy of the Provided Pair
*/
public static <V> BooleanObjectPair<V> of(BooleanObjectPair<V> pair) {
return new BooleanObjectImmutablePair<>(pair.getBooleanKey(), pair.getValue());
}
/**
* @param <V> the keyType of elements maintained by this Collection
* @return empty Mutable Pair
*/
public static <V> BooleanObjectPair<V> mutable() {
return new BooleanObjectMutablePair<>();
}
/**
* @param key the key that should be in the pair
* @param <V> the keyType of elements maintained by this Collection
* @return Mutable Pair of key
*/
public static <V> BooleanObjectPair<V> mutableKey(boolean key) {
return new BooleanObjectMutablePair<>(key, null);
}
/**
* @param value the value that should be in the pair
* @param <V> the keyType of elements maintained by this Collection
* @return Mutable Pair of value
*/
public static <V> BooleanObjectPair<V> mutableValue(V value) {
return new BooleanObjectMutablePair<>(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @param <V> the keyType of elements maintained by this Collection
* @return Mutable Pair of key and value
*/
public static <V> BooleanObjectPair<V> mutable(boolean key, V value) {
return new BooleanObjectMutablePair<>(key, value);
}
/**
* @param pair the Pair that should be copied
* @param <V> the keyType of elements maintained by this Collection
* @return a Mutable Copy of the Provided Pair
*/
public static <V> BooleanObjectPair<V> mutable(BooleanObjectPair<V> pair) {
return new BooleanObjectMutablePair<>(pair.getBooleanKey(), pair.getValue());
}
/**
* Sets the Key of the Pair.
* @param key the key that should be set.
* @return self or a new Pair instance with the new key.
*/
public BooleanObjectPair<V> setBooleanKey(boolean key);
/**
* @return the Key of the Pair
*/
public boolean getBooleanKey();
/**
* Sets the Value of the Pair.
* @param value the value that should be set.
* @return self or a new Pair instance with the new value.
*/
public BooleanObjectPair<V> setValue(V value);
/**
* @return the Value of the Pair
*/
public V getValue();
/**
* Sets key and value of the Pair
* @param key the key that should be set.
* @param value the value that should be set.
* @return self or a new Pair instance with the new key and value.
*/
public BooleanObjectPair<V> set(boolean key, V value);
/**
* Clones the Pair if it is mutable.
* @return a New Mutable Instance if it is mutable
*/
public BooleanObjectPair<V> shallowCopy();
}
@@ -1,132 +0,0 @@
package speiger.src.collections.booleans.misc.pairs;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanShortImmutablePair;
import speiger.src.collections.booleans.misc.pairs.impl.BooleanShortMutablePair;
/**
* Key Value Pair Interface that allows to reduce boxing/unboxing.
*/
public interface BooleanShortPair
{
/**
* Empty Reference for Immutable Pairs
*/
public static final BooleanShortPair EMPTY = new BooleanShortImmutablePair();
/**
* @return empty Immutable Pair
*/
public static BooleanShortPair of() {
return EMPTY;
}
/**
* @param key the key that should be in the pair
* @return Immutable Pair of Key
*/
public static BooleanShortPair ofKey(boolean key) {
return new BooleanShortImmutablePair(key, (short)0);
}
/**
* @param value the value that should be in the pair
* @return Immutable Pair of Value
*/
public static BooleanShortPair ofValue(short value) {
return new BooleanShortImmutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Immutable Pair of key and value
*/
public static BooleanShortPair of(boolean key, short value) {
return new BooleanShortImmutablePair(key, value);
}
/**
* @param pair the Pair that should be immutably copied
* @return a Immutable Copy of the Provided Pair
*/
public static BooleanShortPair of(BooleanShortPair pair) {
return new BooleanShortImmutablePair(pair.getBooleanKey(), pair.getShortValue());
}
/**
* @return empty Mutable Pair
*/
public static BooleanShortPair mutable() {
return new BooleanShortMutablePair();
}
/**
* @param key the key that should be in the pair
* @return Mutable Pair of key
*/
public static BooleanShortPair mutableKey(boolean key) {
return new BooleanShortMutablePair(key, (short)0);
}
/**
* @param value the value that should be in the pair
* @return Mutable Pair of value
*/
public static BooleanShortPair mutableValue(short value) {
return new BooleanShortMutablePair(false, value);
}
/**
* @param key the key that should be in the pair
* @param value the value that should be in the pair
* @return Mutable Pair of key and value
*/
public static BooleanShortPair mutable(boolean key, short value) {
return new BooleanShortMutablePair(key, value);
}
/**
* @param pair the Pair that should be copied
* @return a Mutable Copy of the Provided Pair
*/
public static BooleanShortPair mutable(BooleanShortPair pair) {
return new BooleanShortMutablePair(pair.getBooleanKey(), pair.getShortValue());
}
/**
* Sets the Key of the Pair.
* @param key the key that should be set.
* @return self or a new Pair instance with the new key.
*/
public BooleanShortPair setBooleanKey(boolean key);
/**
* @return the Key of the Pair
*/
public boolean getBooleanKey();
/**
* Sets the Value of the Pair.
* @param value the value that should be set.
* @return self or a new Pair instance with the new value.
*/
public BooleanShortPair setShortValue(short value);
/**
* @return the Value of the Pair
*/
public short getShortValue();
/**
* Sets key and value of the Pair
* @param key the key that should be set.
* @param value the value that should be set.
* @return self or a new Pair instance with the new key and value.
*/
public BooleanShortPair set(boolean key, short value);
/**
* Clones the Pair if it is mutable.
* @return a New Mutable Instance if it is mutable
*/
public BooleanShortPair shallowCopy();
}
@@ -1,79 +0,0 @@
package speiger.src.collections.booleans.misc.pairs.impl;
import speiger.src.collections.booleans.misc.pairs.BooleanBooleanPair;
/**
* Mutable Pair Implementation that
*/
public class BooleanBooleanImmutablePair implements BooleanBooleanPair
{
protected final boolean key;
protected final boolean value;
/**
* Default Constructor
*/
public BooleanBooleanImmutablePair() {
this(false, false);
}
/**
* Key/Value Constructur
* @param key the key of the Pair
* @param value the value of the Pair
*/
public BooleanBooleanImmutablePair(boolean key, boolean value) {
this.key = key;
this.value = value;
}
@Override
public BooleanBooleanPair setBooleanKey(boolean key) {
return new BooleanBooleanImmutablePair(key, value);
}
@Override
public boolean getBooleanKey() {
return key;
}
@Override
public BooleanBooleanPair setBooleanValue(boolean value) {
return new BooleanBooleanImmutablePair(key, value);
}
@Override
public boolean getBooleanValue() {
return value;
}
@Override
public BooleanBooleanPair set(boolean key, boolean value) {
return new BooleanBooleanImmutablePair(key, value);
}
@Override
public BooleanBooleanPair shallowCopy() {
return this;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof BooleanBooleanPair) {
BooleanBooleanPair entry = (BooleanBooleanPair)obj;
return key == entry.getBooleanKey() && value == entry.getBooleanValue();
}
return false;
}
@Override
public int hashCode() {
return Boolean.hashCode(key) ^ Boolean.hashCode(value);
}
@Override
public String toString() {
return Boolean.toString(key) + "->" + Boolean.toString(value);
}
}
@@ -1,83 +0,0 @@
package speiger.src.collections.booleans.misc.pairs.impl;
import speiger.src.collections.booleans.misc.pairs.BooleanBooleanPair;
/**
* Mutable Pair Implementation that
*/
public class BooleanBooleanMutablePair implements BooleanBooleanPair
{
protected boolean key;
protected boolean value;
/**
* Default Constructor
*/
public BooleanBooleanMutablePair() {}
/**
* Key/Value Constructur
* @param key the key of the Pair
* @param value the value of the Pair
*/
public BooleanBooleanMutablePair(boolean key, boolean value) {
this.key = key;
this.value = value;
}
@Override
public BooleanBooleanPair setBooleanKey(boolean key) {
this.key = key;
return this;
}
@Override
public boolean getBooleanKey() {
return key;
}
@Override
public BooleanBooleanPair setBooleanValue(boolean value) {
this.value = value;
return this;
}
@Override
public boolean getBooleanValue() {
return value;
}
@Override
public BooleanBooleanPair set(boolean key, boolean value) {
this.key = key;
this.value = value;
return this;
}
@Override
public BooleanBooleanPair shallowCopy() {
return BooleanBooleanPair.mutable(key, value);
}
@Override
public boolean equals(Object obj) {
if(obj instanceof BooleanBooleanPair) {
BooleanBooleanPair entry = (BooleanBooleanPair)obj;
return key == entry.getBooleanKey() && value == entry.getBooleanValue();
}
return false;
}
@Override
public int hashCode() {
return Boolean.hashCode(key) ^ Boolean.hashCode(value);
}
@Override
public String toString() {
return Boolean.toString(key) + "->" + Boolean.toString(value);
}
}
@@ -1,79 +0,0 @@
package speiger.src.collections.booleans.misc.pairs.impl;
import speiger.src.collections.booleans.misc.pairs.BooleanBytePair;
/**
* Mutable Pair Implementation that
*/
public class BooleanByteImmutablePair implements BooleanBytePair
{
protected final boolean key;
protected final byte value;
/**
* Default Constructor
*/
public BooleanByteImmutablePair() {
this(false, (byte)0);
}
/**
* Key/Value Constructur
* @param key the key of the Pair
* @param value the value of the Pair
*/
public BooleanByteImmutablePair(boolean key, byte value) {
this.key = key;
this.value = value;
}
@Override
public BooleanBytePair setBooleanKey(boolean key) {
return new BooleanByteImmutablePair(key, value);
}
@Override
public boolean getBooleanKey() {
return key;
}
@Override
public BooleanBytePair setByteValue(byte value) {
return new BooleanByteImmutablePair(key, value);
}
@Override
public byte getByteValue() {
return value;
}
@Override
public BooleanBytePair set(boolean key, byte value) {
return new BooleanByteImmutablePair(key, value);
}
@Override
public BooleanBytePair shallowCopy() {
return this;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof BooleanBytePair) {
BooleanBytePair entry = (BooleanBytePair)obj;
return key == entry.getBooleanKey() && value == entry.getByteValue();
}
return false;
}
@Override
public int hashCode() {
return Boolean.hashCode(key) ^ Byte.hashCode(value);
}
@Override
public String toString() {
return Boolean.toString(key) + "->" + Byte.toString(value);
}
}
@@ -1,83 +0,0 @@
package speiger.src.collections.booleans.misc.pairs.impl;
import speiger.src.collections.booleans.misc.pairs.BooleanBytePair;
/**
* Mutable Pair Implementation that
*/
public class BooleanByteMutablePair implements BooleanBytePair
{
protected boolean key;
protected byte value;
/**
* Default Constructor
*/
public BooleanByteMutablePair() {}
/**
* Key/Value Constructur
* @param key the key of the Pair
* @param value the value of the Pair
*/
public BooleanByteMutablePair(boolean key, byte value) {
this.key = key;
this.value = value;
}
@Override
public BooleanBytePair setBooleanKey(boolean key) {
this.key = key;
return this;
}
@Override
public boolean getBooleanKey() {
return key;
}
@Override
public BooleanBytePair setByteValue(byte value) {
this.value = value;
return this;
}
@Override
public byte getByteValue() {
return value;
}
@Override
public BooleanBytePair set(boolean key, byte value) {
this.key = key;
this.value = value;
return this;
}
@Override
public BooleanBytePair shallowCopy() {
return BooleanBytePair.mutable(key, value);
}
@Override
public boolean equals(Object obj) {
if(obj instanceof BooleanBytePair) {
BooleanBytePair entry = (BooleanBytePair)obj;
return key == entry.getBooleanKey() && value == entry.getByteValue();
}
return false;
}
@Override
public int hashCode() {
return Boolean.hashCode(key) ^ Byte.hashCode(value);
}
@Override
public String toString() {
return Boolean.toString(key) + "->" + Byte.toString(value);
}
}

Some files were not shown because too many files have changed in this diff Show More