bitmap4 implements XdrAble, Iterable<Integer> { public static bitmap4 of(int ... values) { if(values.length == 0) { throw new IllegalArgumentException("No values provided"); } int max = values[0]; for(int v: values) { if( v > max) max = v; } int n = max/Integer.SIZE + 1; bitmap4 bitmap = new bitmap4(new int[n]); for (int v : values) { int bit = v % Integer.SIZE; bitmap.value[v / Integer.SIZE] |= 1 << bit; } return bitmap; } bitmap4();  bitmap4(int [] value);  bitmap4(XdrDecodingStream xdr); void xdrEncode(XdrEncodingStream xdr); void xdrDecode(XdrDecodingStream xdr); static bitmap4 of(int ... values); void set(int bit); boolean isSet(int bit); boolean isEmpty(); @Override Iterator<Integer> iterator(); @Override int hashCode(); @Override boolean equals(Object obj); public int[] value; }
@Test public void testCountOfValues() { bitmap4 bitmap = bitmap4.of(5, 34, 80, 129); int count = 0; for(Integer i: bitmap) { count ++; } assertEquals(4, count); }
@Test public void testValues() { int[] values = new int[] { 7, 15, 62, 63, 129 }; int[] testArray = new int[values.length]; bitmap4 bitmap = bitmap4.of(values); int count = 0; for (Integer i : bitmap) { testArray[count++] = i; } assertArrayEquals(values, testArray); }