forked from Speiger/Primitive-Collections
TreeSubSets (RB/AVL) got their functional implementations improved too.
This commit is contained in:
parent
5b67e85009
commit
fa3cf743f9
|
@ -11,6 +11,7 @@
|
||||||
- Added: Filter function to Iterators/Iterables (Iterable implements it by default)
|
- Added: Filter function to Iterators/Iterables (Iterable implements it by default)
|
||||||
- Changed: Cleanup of some variables/mappers
|
- Changed: Cleanup of some variables/mappers
|
||||||
- Added/Fixed: AVL/RBTreeMap got reworked and SubMaps work more properly now. Also forEach support got improved a lot
|
- Added/Fixed: AVL/RBTreeMap got reworked and SubMaps work more properly now. Also forEach support got improved a lot
|
||||||
|
- Added/Fixed: TreeSubSets (RB/AVL) got their functional implementations improved too.
|
||||||
|
|
||||||
### Version 0.3.6
|
### Version 0.3.6
|
||||||
- Fixed: addAll non Type Specific Lists was causing crashes.
|
- Fixed: addAll non Type Specific Lists was causing crashes.
|
||||||
|
|
|
@ -747,6 +747,9 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||||
return new DescendingSubSetBRACES(set, fromStart, start, loInclusive, false, fromElement, inclusive);
|
return new DescendingSubSetBRACES(set, fromStart, start, loInclusive, false, fromElement, inclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Entry KEY_GENERIC_TYPE next(Entry KEY_GENERIC_TYPE entry) { return entry.previous(); }
|
||||||
|
protected Entry KEY_GENERIC_TYPE start() { return findHighest(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_KEY() { return super.LAST_KEY(); }
|
public KEY_TYPE FIRST_KEY() { return super.LAST_KEY(); }
|
||||||
|
|
||||||
|
@ -852,6 +855,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||||
boolean inRange(KEY_TYPE key) { return !tooLow(key) && !tooHigh(key); }
|
boolean inRange(KEY_TYPE key) { return !tooLow(key) && !tooHigh(key); }
|
||||||
boolean inClosedRange(KEY_TYPE key) { return (fromStart || set.compare(key, start) >= 0) && (toEnd || set.compare(end, key) >= 0); }
|
boolean inClosedRange(KEY_TYPE key) { return (fromStart || set.compare(key, start) >= 0) && (toEnd || set.compare(end, key) >= 0); }
|
||||||
boolean inRange(KEY_TYPE key, boolean inclusive) { return inclusive ? inRange(key) : inClosedRange(key); }
|
boolean inRange(KEY_TYPE key, boolean inclusive) { return inclusive ? inRange(key) : inClosedRange(key); }
|
||||||
|
protected Entry KEY_GENERIC_TYPE next(Entry KEY_GENERIC_TYPE entry) { return entry.next(); }
|
||||||
|
protected Entry KEY_GENERIC_TYPE start() { return findLowest(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@ -994,6 +999,57 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||||
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
|
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
action.accept(entry.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry))
|
||||||
|
action.accept(entry.key, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
if(filter.TEST_VALUE(entry.key)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
if(filter.TEST_VALUE(entry.key)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
if(!filter.TEST_VALUE(entry.key)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||||
|
}
|
||||||
|
return EMPTY_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE previous;
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
|
|
|
@ -808,6 +808,9 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||||
return new DescendingSubSetBRACES(set, fromStart, start, loInclusive, false, fromElement, inclusive);
|
return new DescendingSubSetBRACES(set, fromStart, start, loInclusive, false, fromElement, inclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Entry KEY_GENERIC_TYPE next(Entry KEY_GENERIC_TYPE entry) { return entry.previous(); }
|
||||||
|
protected Entry KEY_GENERIC_TYPE start() { return findHighest(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_KEY() { return super.LAST_KEY(); }
|
public KEY_TYPE FIRST_KEY() { return super.LAST_KEY(); }
|
||||||
|
|
||||||
|
@ -913,6 +916,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||||
boolean inRange(KEY_TYPE key) { return !tooLow(key) && !tooHigh(key); }
|
boolean inRange(KEY_TYPE key) { return !tooLow(key) && !tooHigh(key); }
|
||||||
boolean inClosedRange(KEY_TYPE key) { return (fromStart || set.compare(key, start) >= 0) && (toEnd || set.compare(end, key) >= 0); }
|
boolean inClosedRange(KEY_TYPE key) { return (fromStart || set.compare(key, start) >= 0) && (toEnd || set.compare(end, key) >= 0); }
|
||||||
boolean inRange(KEY_TYPE key, boolean inclusive) { return inclusive ? inRange(key) : inClosedRange(key); }
|
boolean inRange(KEY_TYPE key, boolean inclusive) { return inclusive ? inRange(key) : inClosedRange(key); }
|
||||||
|
protected Entry KEY_GENERIC_TYPE next(Entry KEY_GENERIC_TYPE entry) { return entry.next(); }
|
||||||
|
protected Entry KEY_GENERIC_TYPE start() { return findLowest(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@ -1055,6 +1060,57 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||||
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
|
return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
action.accept(entry.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> void forEach(E input, BI_OBJECT_CONSUMER KKS_GENERIC_TYPE<E> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry))
|
||||||
|
action.accept(entry.key, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
if(filter.TEST_VALUE(entry.key)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
if(filter.TEST_VALUE(entry.key)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
if(!filter.TEST_VALUE(entry.key)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||||
|
if(filter.TEST_VALUE(entry.key)) return entry.key;
|
||||||
|
}
|
||||||
|
return EMPTY_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE previous;
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
|
|
Loading…
Reference in New Issue