forked from Speiger/Primitive-Collections
New Fixes
- Fixed: Compute/ComputeIfAbsent/ComputeIfPresent/Merge/BulkMerge in maps now behave like they should.
This commit is contained in:
parent
fc1a738625
commit
c9cd62f5d7
|
@ -4,6 +4,7 @@
|
|||
### Version 0.3.7/0.4.0
|
||||
- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables
|
||||
- Added: New Stream replacing functions: findFirst, matchesAny/All/None
|
||||
- Fixed: Compute/ComputeIfAbsent/ComputeIfPresent/Merge/BulkMerge in maps now behave like they should.
|
||||
|
||||
### Version 0.3.6
|
||||
- Fixed: addAll non Type Specific Lists was causing crashes.
|
||||
|
|
|
@ -452,10 +452,15 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(strategy.equals(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(strategy.equals(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -465,6 +470,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
if(strategy.equals(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
|
@ -476,6 +482,10 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(strategy.equals(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -484,7 +494,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index < 0 ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(strategy.equals(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
}
|
||||
|
@ -500,7 +510,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index < 0 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(strategy.equals(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
}
|
||||
|
|
|
@ -413,10 +413,15 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -426,6 +431,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
|
@ -437,6 +443,10 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||
int index = findIndex(key);
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -445,7 +455,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index < 0 ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
}
|
||||
|
@ -461,7 +471,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index < 0 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
}
|
||||
|
|
|
@ -443,10 +443,15 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -456,6 +461,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
|
@ -467,6 +473,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
int index = findIndex(key);
|
||||
if(index == -1) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -475,7 +485,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index == -1 ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
}
|
||||
|
@ -491,7 +501,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
int index = findIndex(key);
|
||||
VALUE_TYPE newValue = index == -1 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(index >= 0)
|
||||
removeIndex(index);
|
||||
}
|
||||
|
|
|
@ -479,10 +479,15 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -492,6 +497,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
|
@ -503,6 +509,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -511,7 +521,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
VALUE_TYPE newValue = entry == null ? value : mappingFunction.APPLY_VALUE(entry.value, value);
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(entry != null)
|
||||
removeNode(entry);
|
||||
}
|
||||
|
@ -527,7 +537,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
Entry KEY_VALUE_GENERIC_TYPE subEntry = findNode(key);
|
||||
VALUE_TYPE newValue = subEntry == null ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(subEntry.value, entry.ENTRY_VALUE());
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(subEntry != null)
|
||||
removeNode(subEntry);
|
||||
}
|
||||
|
|
|
@ -478,10 +478,15 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -491,6 +496,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
|
@ -502,6 +508,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
@ -510,7 +520,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
VALUE_TYPE newValue = entry == null ? value : mappingFunction.APPLY_VALUE(entry.value, value);
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(entry != null)
|
||||
removeNode(entry);
|
||||
}
|
||||
|
@ -526,7 +536,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
Entry KEY_VALUE_GENERIC_TYPE subEntry = findNode(key);
|
||||
VALUE_TYPE newValue = subEntry == null ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(subEntry.value, entry.ENTRY_VALUE());
|
||||
if(newValue == getDefaultReturnValue()) {
|
||||
if(KEY_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(subEntry != null)
|
||||
removeNode(subEntry);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue