use of org.eclipse.collections.api.iterator.ByteIterator in project eclipse-collections by eclipse.
the class ByteHashSet method count.
@Override
public int count(BytePredicate predicate) {
int count = 0;
ByteIterator iterator = this.byteIterator();
while (iterator.hasNext()) {
if (predicate.accept(iterator.next())) {
count++;
}
}
return count;
}
use of org.eclipse.collections.api.iterator.ByteIterator in project eclipse-collections by eclipse.
the class ByteHashSet method sum.
@Override
public long sum() {
long result = 0L;
ByteIterator iterator = this.byteIterator();
while (iterator.hasNext()) {
result += iterator.next();
}
return result;
}
use of org.eclipse.collections.api.iterator.ByteIterator in project eclipse-collections by eclipse.
the class ByteHashSet method removeAll.
@Override
public boolean removeAll(ByteIterable source) {
if (source.isEmpty()) {
return false;
}
int oldSize = this.size();
if (source instanceof ByteHashSet) {
this.size = 0;
ByteHashSet hashSet = (ByteHashSet) source;
this.bitGroup3 &= ~hashSet.bitGroup3;
this.size += Long.bitCount(this.bitGroup3);
this.bitGroup4 &= ~hashSet.bitGroup4;
this.size += Long.bitCount(this.bitGroup4);
this.bitGroup2 &= ~hashSet.bitGroup2;
this.size += Long.bitCount(this.bitGroup2);
this.bitGroup1 &= ~hashSet.bitGroup1;
this.size += Long.bitCount(this.bitGroup1);
} else {
ByteIterator iterator = source.byteIterator();
while (iterator.hasNext()) {
byte item = iterator.next();
this.remove(item);
}
}
return this.size() != oldSize;
}
use of org.eclipse.collections.api.iterator.ByteIterator in project eclipse-collections by eclipse.
the class ByteHashSet method addAll.
@Override
public boolean addAll(ByteIterable source) {
if (source.isEmpty()) {
return false;
}
int oldSize = this.size();
if (source instanceof ByteHashSet) {
ByteHashSet hashSet = (ByteHashSet) source;
this.size = 0;
this.bitGroup3 |= hashSet.bitGroup3;
this.size += Long.bitCount(this.bitGroup3);
this.bitGroup4 |= hashSet.bitGroup4;
this.size += Long.bitCount(this.bitGroup4);
this.bitGroup2 |= hashSet.bitGroup2;
this.size += Long.bitCount(this.bitGroup2);
this.bitGroup1 |= hashSet.bitGroup1;
this.size += Long.bitCount(this.bitGroup1);
} else {
ByteIterator iterator = source.byteIterator();
while (iterator.hasNext()) {
byte item = iterator.next();
this.add(item);
}
}
return this.size() != oldSize;
}
use of org.eclipse.collections.api.iterator.ByteIterator in project eclipse-collections by eclipse.
the class AbstractByteSetTestCase method byteIterator.
@Override
@Test
public void byteIterator() {
MutableSet<Byte> expected = UnifiedSet.newSetWith((byte) 0, (byte) 1, (byte) 31, (byte) 63, (byte) 100, (byte) 127, (byte) -1, (byte) -35, (byte) -64, (byte) -100, (byte) -128);
MutableSet<Byte> actual = UnifiedSet.newSet();
MutableByteSet set = this.newWith((byte) 0, (byte) 1, (byte) 31, (byte) 63, (byte) 100, (byte) 127, (byte) -1, (byte) -35, (byte) -64, (byte) -100, (byte) -128);
ByteIterator iterator = set.byteIterator();
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertTrue(iterator.hasNext());
actual.add(iterator.next());
Assert.assertFalse(iterator.hasNext());
Assert.assertEquals(expected, actual);
Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator::next);
}
Aggregations