Search in sources :

Example 21 with OfInt

use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.

the class StaticHasherTest method testGetBits.

/**
 * Tests that iterator returns the proper values.
 */
@Test
public void testGetBits() {
    final List<Integer> lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
    final StaticHasher hasher = new StaticHasher(lst.iterator(), shape);
    assertEquals(17, hasher.size());
    final OfInt iter = hasher.iterator(shape);
    for (int i = 0; i < 17; i++) {
        assertTrue(iter.hasNext());
        assertEquals(i, iter.nextInt());
    }
    assertFalse(iter.hasNext());
}
Also used : OfInt(java.util.PrimitiveIterator.OfInt) Test(org.junit.jupiter.api.Test)

Example 22 with OfInt

use of java.util.PrimitiveIterator.OfInt in project uima-uimaj by apache.

the class JCasTest method testOtherListAPI.

@Test
public void testOtherListAPI() {
    // float and integer
    IntegerList sl = new EmptyIntegerList(jcas);
    sl = sl.push(2);
    sl = sl.push(1);
    int[] fss = new int[2];
    int i = 0;
    for (int s : sl) {
        fss[i++] = s;
    }
    int[] expected = { 1, 2 };
    assert (Arrays.equals(expected, fss));
    FloatList fl = new EmptyFloatList(jcas);
    fl = fl.push(2.0F);
    fl = fl.push(1.0F);
    float[] fls = new float[2];
    i = 0;
    for (float f : fl) {
        fls[i++] = f;
    }
    float[] expectedFloats = { 1.0f, 2.0f };
    assert (Arrays.equals(expectedFloats, fls));
    BooleanArray boa = new BooleanArray(jcas, 2);
    boa.set(0, true);
    boa.set(1, false);
    boolean[] expectedBa = { true, false };
    i = 0;
    for (boolean bov : boa) {
        assertEquals(expectedBa[i++], bov);
    }
    ByteArray bya = new ByteArray(jcas, 2);
    bya.set(0, (byte) 15);
    bya.set(1, (byte) 22);
    byte[] expectedBya = { 15, 22 };
    i = 0;
    for (byte v : bya) {
        assertEquals(expectedBya[i++], v);
    }
    ShortArray sha = new ShortArray(jcas, 2);
    sha.set(0, (short) 15);
    sha.set(1, (short) 22);
    short[] expectedSha = { 15, 22 };
    i = 0;
    for (short v : sha) {
        assertEquals(expectedSha[i++], v);
    }
    IntegerArray ina = new IntegerArray(jcas, 2);
    ina.set(0, (int) 15);
    ina.set(1, (int) 22);
    int[] expectedIna = { 15, 22 };
    i = 0;
    for (int v : ina) {
        assertEquals(expectedIna[i++], v);
    }
    IntegerArrayList inal = new IntegerArrayList(jcas, 2);
    inal.add(15);
    inal.add(22);
    OfInt ialit = inal.iterator();
    i = 0;
    while (ialit.hasNext()) {
        assertEquals(expectedIna[i++], ialit.nextInt());
    }
    i = 0;
    for (int v : inal) {
        assertEquals(expectedIna[i++], v);
    }
    LongArray loa = new LongArray(jcas, 2);
    loa.set(0, (long) 15);
    loa.set(1, (long) 22);
    long[] expectedLoa = { 15, 22 };
    i = 0;
    for (long v : loa) {
        assertEquals(expectedLoa[i++], v);
    }
    DoubleArray doa = new DoubleArray(jcas, 2);
    doa.set(0, (double) 15);
    doa.set(1, (double) 22);
    double[] expectedDoa = { 15d, 22d };
    i = 0;
    for (double v : doa) {
        Assertions.assertThat(expectedDoa[i++]).isEqualTo(v);
    }
}
Also used : BooleanArray(org.apache.uima.jcas.cas.BooleanArray) EmptyIntegerList(org.apache.uima.jcas.cas.EmptyIntegerList) NonEmptyIntegerList(org.apache.uima.jcas.cas.NonEmptyIntegerList) IntegerList(org.apache.uima.jcas.cas.IntegerList) EmptyIntegerList(org.apache.uima.jcas.cas.EmptyIntegerList) NonEmptyIntegerList(org.apache.uima.jcas.cas.NonEmptyIntegerList) ByteArray(org.apache.uima.jcas.cas.ByteArray) NonEmptyFloatList(org.apache.uima.jcas.cas.NonEmptyFloatList) EmptyFloatList(org.apache.uima.jcas.cas.EmptyFloatList) ShortArray(org.apache.uima.jcas.cas.ShortArray) IntegerArrayList(org.apache.uima.jcas.cas.IntegerArrayList) NonEmptyFloatList(org.apache.uima.jcas.cas.NonEmptyFloatList) FloatList(org.apache.uima.jcas.cas.FloatList) EmptyFloatList(org.apache.uima.jcas.cas.EmptyFloatList) IntegerArray(org.apache.uima.jcas.cas.IntegerArray) OfInt(java.util.PrimitiveIterator.OfInt) LongArray(org.apache.uima.jcas.cas.LongArray) DoubleArray(org.apache.uima.jcas.cas.DoubleArray) Test(org.junit.jupiter.api.Test)

Aggregations

OfInt (java.util.PrimitiveIterator.OfInt)22 Test (org.junit.jupiter.api.Test)12 Random (java.util.Random)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 TreeSet (java.util.TreeSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Hasher (org.apache.commons.collections4.bloomfilter.hasher.Hasher)2 Shape (org.apache.commons.collections4.bloomfilter.hasher.Shape)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 IntBuffer (java.nio.IntBuffer)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1