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());
}
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);
}
}
Aggregations