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.
This commit is contained in:
+46
-44
@@ -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);
|
||||
|
||||
+95
-91
@@ -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,6 +525,28 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
return getSegment(hash).computeIfAbsent(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).supplyIfAbsent(hash, key, valueProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int hash = getHashCode(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);
|
||||
@@ -539,13 +554,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP 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);
|
||||
int hash = getHashCode(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);
|
||||
@@ -553,13 +561,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP 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);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).computeIfPresent(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@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 {
|
||||
@@ -2318,30 +2297,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -2368,6 +2324,76 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfPresent(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, 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;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -2392,29 +2418,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfPresent(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, 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;
|
||||
}
|
||||
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 {
|
||||
|
||||
+60
-58
@@ -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);
|
||||
@@ -595,26 +576,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
#endif
|
||||
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);
|
||||
|
||||
+60
-58
@@ -513,26 +513,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
values[index] = newValue;
|
||||
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);
|
||||
@@ -597,6 +559,64 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
#endif
|
||||
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) {
|
||||
@@ -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);
|
||||
|
||||
+8
-7
@@ -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(); }
|
||||
|
||||
|
||||
+63
-61
@@ -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);
|
||||
@@ -553,6 +534,68 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
#endif
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
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) {
|
||||
@@ -573,29 +616,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
#endif
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
#if VALUE_OBJECT
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
#endif
|
||||
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);
|
||||
|
||||
+61
-59
@@ -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();
|
||||
@@ -424,26 +404,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
#endif
|
||||
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();
|
||||
|
||||
+72
-64
@@ -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
|
||||
|
||||
+72
-64
@@ -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
|
||||
|
||||
+30
-28
@@ -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".
|
||||
|
||||
Reference in New Issue
Block a user