New Features
-Added: Count method for Iterable -Fixed: A couple of bugs with the new stream removers not working well in LinkedCollections
This commit is contained in:
@@ -346,6 +346,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Entry KEY_GENERIC_TYPE findNode(KEY_TYPE o) {
|
||||
Entry KEY_GENERIC_TYPE node = tree;
|
||||
int compare;
|
||||
@@ -1050,6 +1060,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
|
||||
@@ -392,6 +392,16 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(filter.TEST_VALUE(data[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
protected int findIndex(KEY_TYPE o) {
|
||||
for(int i = size-1;i>=0;i--)
|
||||
|
||||
+16
@@ -312,6 +312,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -322,6 +323,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -332,6 +334,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -342,10 +345,23 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
|
||||
+16
@@ -549,6 +549,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -559,6 +560,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -569,6 +571,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -579,10 +582,23 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator();
|
||||
|
||||
+16
@@ -404,6 +404,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return true;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -414,6 +415,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -424,6 +426,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -434,10 +437,23 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
||||
index = (int)links[index];
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1) {
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNodeAdded(int pos) {
|
||||
if(size == 0) {
|
||||
|
||||
+12
@@ -521,6 +521,18 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
||||
int pos = nullIndex;
|
||||
int lastReturned = -1;
|
||||
|
||||
@@ -390,6 +390,18 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
if(size() <= 0) return 0;
|
||||
int result = 0;
|
||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ensureCapacity(int newCapacity) {
|
||||
int size = HashUtil.arraySize(newCapacity, loadFactor);
|
||||
if(size > nullIndex) rehash(size);
|
||||
|
||||
@@ -346,6 +346,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Entry KEY_GENERIC_TYPE findNode(KEY_TYPE o) {
|
||||
Entry KEY_GENERIC_TYPE node = tree;
|
||||
int compare;
|
||||
@@ -1111,6 +1121,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
Objects.requireNonNull(filter);
|
||||
int result = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = start();entry != null && inRange(entry.key);entry = next(entry)) {
|
||||
if(filter.TEST_VALUE(entry.key)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class SubSetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
|
||||
Reference in New Issue
Block a user