private int iFindKey(MapperKey<K> key) { for(int i = 0; i < keys.length; i++) { if (key.equals(keys[i])) { return i; } } return - keys.length - 1; }
private int iFindKey(MapperKey<K> key) { for(int i = 0; i < keys.length; i++) { if (key.equals(keys[i])) { return i; } } return - keys.length - 1; }
@Override public boolean equals(Object obj) { if (obj == null) return false; if (getClass() != obj.getClass()) return false; MapperKey<?> that = (MapperKey<?>) obj; return equals(columns, that.columns); }
@Override public boolean equals(Object obj) { if (obj == null) return false; if (getClass() != obj.getClass()) return false; MapperKey<?> that = (MapperKey<?>) obj; return equals(columns, that.columns); }
@SuppressWarnings("unchecked") public void add(final MapperKey<K> key, final M mapper) { SortedEntries<K> sortedEntries; SortedEntries<K> newSortedEntries; do { sortedEntries = this.sortedEntries.get(); final int i = sortedEntries.findInsertionPoint(key); if (i >= 0) { if (!key.equals(sortedEntries.keys[i])) { throw new IllegalStateException("Comparator find key " + key + " to be equal to " + sortedEntries.keys[i] + " but is not"); } return; } int insertionPoint = -1 - i; newSortedEntries = sortedEntries.insertEntry(key, mapper, insertionPoint); } while(!this.sortedEntries.compareAndSet(sortedEntries, newSortedEntries)); }
@SuppressWarnings("unchecked") public void add(final MapperKey<K> key, final M mapper) { SortedEntries<K> sortedEntries; SortedEntries<K> newSortedEntries; do { sortedEntries = this.sortedEntries.get(); final int i = sortedEntries.findInsertionPoint(key); if (i >= 0) { if (!key.equals(sortedEntries.keys[i])) { throw new IllegalStateException("Comparator find key " + key + " to be equal to " + sortedEntries.keys[i] + " but is not"); } return; } int insertionPoint = -1 - i; newSortedEntries = sortedEntries.insertEntry(key, mapper, insertionPoint); } while(!this.sortedEntries.compareAndSet(sortedEntries, newSortedEntries)); }
public static <K extends FieldKey<K>> void testComparator(KeyProducer<K> producer, MapperKeyComparator<K> comparator) throws Exception { MapperKey<K>[] keys = generateKeys(producer); for(int i = 0; i < keys.length; i++ ){ for (int j = 0; j < keys.length; j++) { MapperKey<K> key1 = keys[i]; MapperKey<K> key2 = keys[j]; if (key1.equals(key2)) { Assert.assertEquals(0, comparator.compare(key1, key2)); Assert.assertEquals(0, comparator.compare(key2, key1)); } else { int d = comparator.compare(key1, key2); Assert.assertFalse(d == 0); if (d < 0) { Assert.assertTrue(comparator.compare(key2, key1) > 0); } else { Assert.assertTrue(comparator.compare(key2, key1) < 0); } } Assert.assertEquals(0, comparator.compare(key2, key2)); Assert.assertEquals(0, comparator.compare(key1, key1)); } } }