Search in sources :

Example 6 with ByteIterator

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;
}
Also used : MutableByteIterator(org.eclipse.collections.api.iterator.MutableByteIterator) ByteIterator(org.eclipse.collections.api.iterator.ByteIterator)

Example 7 with ByteIterator

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;
}
Also used : MutableByteIterator(org.eclipse.collections.api.iterator.MutableByteIterator) ByteIterator(org.eclipse.collections.api.iterator.ByteIterator)

Example 8 with ByteIterator

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;
}
Also used : MutableByteIterator(org.eclipse.collections.api.iterator.MutableByteIterator) ByteIterator(org.eclipse.collections.api.iterator.ByteIterator)

Example 9 with ByteIterator

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;
}
Also used : MutableByteIterator(org.eclipse.collections.api.iterator.MutableByteIterator) ByteIterator(org.eclipse.collections.api.iterator.ByteIterator)

Example 10 with ByteIterator

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);
}
Also used : ByteIterator(org.eclipse.collections.api.iterator.ByteIterator) MutableByteSet(org.eclipse.collections.api.set.primitive.MutableByteSet) Test(org.junit.Test)

Aggregations

ByteIterator (org.eclipse.collections.api.iterator.ByteIterator)12 MutableByteIterator (org.eclipse.collections.api.iterator.MutableByteIterator)8 Test (org.junit.Test)4 MutableByteSet (org.eclipse.collections.api.set.primitive.MutableByteSet)3 ImmutableByteSet (org.eclipse.collections.api.set.primitive.ImmutableByteSet)2 IOException (java.io.IOException)1 ByteIterable (org.eclipse.collections.api.ByteIterable)1 LazyByteIterable (org.eclipse.collections.api.LazyByteIterable)1