@Override public boolean hasNulls() { return dictionary.indexOf(null) >= 0; }
@Override public int getIndex(@Nullable String value) { // GenericIndexed.indexOf satisfies contract needed by BitmapIndex.indexOf return dictionary.indexOf(value); }
/** * Returns the index of "value" in this GenericIndexed object, or (-(insertion point) - 1) if the value is not * present, in the manner of Arrays.binarySearch. This strengthens the contract of Indexed, which only guarantees * that values-not-found will return some negative number. * * @param value value to search for * * @return index of value, or negative number equal to (-(insertion point) - 1). */ @Override public int indexOf(@Nullable T value) { return indexOf(this, value); }
@Benchmark public int indexOf() { int r = 0; for (byte[] elementToSearch : elementsToSearch) { r ^= genericIndexed.indexOf(elementToSearch); } return r; } }
@Test(expected = UnsupportedOperationException.class) public void testNotSortedNoIndexOf() { GenericIndexed.fromArray(new String[]{"a", "c", "b"}, GenericIndexed.STRING_STRATEGY).indexOf("a"); }
@Test public void testSortedSerialization() throws Exception { final String[] strings = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"}; GenericIndexed<String> deserialized = serializeAndDeserialize( GenericIndexed.fromArray(strings, GenericIndexed.STRING_STRATEGY) ); checkBasicAPIs(strings, deserialized, true); Assert.assertEquals(-13, deserialized.indexOf("q")); Assert.assertEquals(-9, deserialized.indexOf("howdydo")); Assert.assertEquals(-1, deserialized.indexOf("1111")); }
@Test(expected = UnsupportedOperationException.class) public void testSerializationNotSortedNoIndexOf() throws Exception { serializeAndDeserialize( GenericIndexed.fromArray( new String[]{"a", "c", "b"}, GenericIndexed.STRING_STRATEGY ) ).indexOf("a"); }
@Override public boolean hasNulls() { return dictionary.indexOf(null) >= 0; }
@Override public int getIndex(@Nullable String value) { // GenericIndexed.indexOf satisfies contract needed by BitmapIndex.indexOf return dictionary.indexOf(value); }
/** * Returns the index of "value" in this GenericIndexed object, or (-(insertion point) - 1) if the value is not * present, in the manner of Arrays.binarySearch. This strengthens the contract of Indexed, which only guarantees * that values-not-found will return some negative number. * * @param value value to search for * * @return index of value, or negative number equal to (-(insertion point) - 1). */ @Override public int indexOf(@Nullable T value) { return indexOf(this, value); }