Search in sources :

Example 1 with MutableIntSet

use of org.eclipse.collections.api.set.primitive.MutableIntSet in project eclipse-collections by eclipse.

the class PrimitiveStreamsTest method toIntSet.

@Test
public void toIntSet() {
    MutableIntSet set = PrimitiveStreams.mIntSet(IntStream.rangeClosed(1, 10));
    Assert.assertEquals(IntInterval.oneTo(10).toSet(), set);
    Assert.assertEquals(IntSets.immutable.ofAll(IntStream.rangeClosed(1, 10)), set);
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) Test(org.junit.Test)

Example 2 with MutableIntSet

use of org.eclipse.collections.api.set.primitive.MutableIntSet in project eclipse-collections by eclipse.

the class IntIntMapProbeTest method testRandomRemove.

private void testRandomRemove(MutableIntIntMap intIntMap, int keyCount) {
    Random random = new Random(0x123456789ABCDL);
    MutableIntSet set = new IntHashSet(keyCount);
    while (set.size() < keyCount) {
        set.add(random.nextInt());
    }
    int[] intKeysForMap = set.toArray();
    this.shuffle(intKeysForMap, random);
    for (int i = 0; i < keyCount; i++) {
        intIntMap.put(intKeysForMap[i], intKeysForMap[i] * 10);
    }
    this.shuffle(intKeysForMap, random);
    for (int i = 0; i < intKeysForMap.length; i++) {
        intIntMap.remove(intKeysForMap[i]);
        for (int j = i + 1; j < intKeysForMap.length; j++) {
            Assert.assertEquals((long) (intKeysForMap[j] * 10), intIntMap.get(intKeysForMap[j]));
        }
    }
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) Random(java.util.Random) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)

Example 3 with MutableIntSet

use of org.eclipse.collections.api.set.primitive.MutableIntSet in project eclipse-collections by eclipse.

the class IntLongMapProbeTest method testRandomGet.

private void testRandomGet(MutableIntLongMap intlongMap, int keyCount) {
    Random random = new Random(0x123456789ABCDL);
    MutableIntSet set = new IntHashSet(keyCount);
    while (set.size() < keyCount) {
        set.add(random.nextInt());
    }
    int[] randomNumbersForMap = set.toArray();
    this.shuffle(randomNumbersForMap, random);
    for (int i = 0; i < keyCount; i++) {
        intlongMap.put(randomNumbersForMap[i], (long) (randomNumbersForMap[i] * 10));
    }
    for (int i = 0; i < intlongMap.size(); i++) {
        Assert.assertEquals((long) (randomNumbersForMap[i] * 10), intlongMap.get(randomNumbersForMap[i]));
    }
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) Random(java.util.Random) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)

Example 4 with MutableIntSet

use of org.eclipse.collections.api.set.primitive.MutableIntSet in project eclipse-collections by eclipse.

the class AbstractImmutableSet method collectInt.

@Override
public ImmutableIntSet collectInt(IntFunction<? super T> intFunction) {
    MutableIntSet result = new IntHashSet(this.size());
    this.forEach(new CollectIntProcedure<>(intFunction, result));
    return result.toImmutable();
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)

Example 5 with MutableIntSet

use of org.eclipse.collections.api.set.primitive.MutableIntSet in project eclipse-collections by eclipse.

the class AbstractMutableSet method collectInt.

@Override
public MutableIntSet collectInt(IntFunction<? super T> intFunction) {
    MutableIntSet result = new IntHashSet(this.size());
    this.forEach(new CollectIntProcedure<>(intFunction, result));
    return result;
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)

Aggregations

MutableIntSet (org.eclipse.collections.api.set.primitive.MutableIntSet)9 IntHashSet (org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)8 Random (java.util.Random)4 Test (org.junit.Test)1