@Override public boolean equalToReference(T candidate) { return comp.equalToReference(candidate); }
@Override public boolean equalToReference(T candidate) { // both values are null if (candidate == null && nullReference) { return true; } // one value is null else if (candidate == null || nullReference) { return false; } // no null value else { return wrappedComparator.equalToReference(candidate); } }
private E advanceToNext() { if (currentPosition < input.size()) { E next = input.get(currentPosition++); if (comparator.equalToReference(next)) { // same key return next; } else { // moved to the next key, no more values here lookahead = next; return null; } } else { // backing iterator is consumed this.done = true; return null; } }
@Override public boolean equalToReference(T candidate) { int i = 0; for (; i < this.keyFields.length; i++) { if (!this.comparators[i].equalToReference(accessField(keyFields[i], candidate))) { return false; } } return true; }
@Override public boolean equalToReference(Row candidate) { int i = 0; try { for (; i < keyPositions.length; i++) { TypeComparator<Object> comparator = comparators[i]; Object element = candidate.getField(keyPositions[i]); // element can be null // check if reference is not equal if (!comparator.equalToReference(element)) { return false; } } } catch (IndexOutOfBoundsException e) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } return true; }
@SuppressWarnings("unchecked") @Override public boolean equalToReference(T candidate) { int i = 0; try { for (; i < this.keyPositions.length; i++) { if (!this.comparators[i].equalToReference(candidate.getFieldNotNull(this.keyPositions[i]))) { return false; } } return true; } catch (NullFieldException nfex) { throw new NullKeyFieldException(nfex); } catch (IndexOutOfBoundsException iobex) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } }
while (true) { if (currentPosition < input.size() && (next = this.input.get(currentPosition++)) != null) { if (!this.comparator.equalToReference(next)) {
public class Prober<PT> { public Prober(TypeComparator<PT> probeComparator, TypePairComparator<PT, BT> pairComparator) { this.probeComparator = probeComparator; this.pairComparator = pairComparator; } private final TypeComparator<PT> probeComparator; private final TypePairComparator<PT, BT> pairComparator; @SuppressWarnings("unchecked") public BT lookupMatch(PT record) { int hashCode = hash(probeComparator.hash(record)); int index = hashIndex(hashCode, data.length); pairComparator.setReference(record); HashEntry entry = data[index]; while (entry != null) { if (entryHashCode(entry) == hashCode && pairComparator.equalToReference((BT) entry.getValue())) { return (BT) entry.getValue(); } entry = entryNext(entry); } return null; } } }
@Test public void testDuplicate() { try { TypeComparator<T> comparator = getComparator(true); TypeComparator<T> clone = comparator.duplicate(); T[] data = getSortedData(); comparator.setReference(data[0]); clone.setReference(data[1]); assertTrue("Comparator duplication does not work: Altering the reference in a duplicated comparator alters the original comparator's reference.", comparator.equalToReference(data[0]) && clone.equalToReference(data[1])); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); Assert.fail(e.getMessage()); } }
@SuppressWarnings("unchecked") public void insertOrReplace(BT record) { int hashCode = hash(buildComparator.hash(record)); int index = hashIndex(hashCode, data.length); buildComparator.setReference(record); HashEntry entry = data[index]; while (entry != null) { if (entryHashCode(entry) == hashCode && buildComparator.equalToReference((BT) entry.getValue())) { entry.setValue(record); return; } entry = entryNext(entry); } addMapping(index, hashCode, null, record); }
@Test public void testEqualityWithReference() { try { TypeSerializer<T> serializer = createSerializer(); TypeComparator<T> comparator = getComparator(true); TypeComparator<T> comparator2 = getComparator(true); T[] data = getSortedData(); for (T d : data) { comparator.setReference(d); // Make a copy to compare T copy = serializer.copy(d, serializer.createInstance()); // And then test equalTo and compareToReference method of comparator assertTrue(comparator.equalToReference(d)); comparator2.setReference(copy); assertTrue(comparator.compareToReference(comparator2) == 0); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
@Override public boolean equalToReference(T candidate) { return comp.equalToReference(candidate); }
@Override public boolean equalToReference(T candidate) { return comp.equalToReference(candidate); }
@Override public boolean equalToReference(T t) { if(t != null && !this.refNull) { return this.wrappedComparator.equalToReference(t); } else if(t == null && this.refNull) { return true; } else { return false; } }
@Override public boolean equalToReference(T candidate) { // both values are null if (candidate == null && nullReference) { return true; } // one value is null else if (candidate == null || nullReference) { return false; } // no null value else { return wrappedComparator.equalToReference(candidate); } }
@Override public boolean equalToReference(T candidate) { int i = 0; for (; i < this.keyFields.length; i++) { if (!this.comparators[i].equalToReference(accessField(keyFields[i], candidate))) { return false; } } return true; }
@Override public boolean equalToReference(T candidate) { int i = 0; for (; i < this.keyFields.length; i++) { if (!this.comparators[i].equalToReference(accessField(keyFields[i], candidate))) { return false; } } return true; }
@SuppressWarnings("unchecked") @Override public boolean equalToReference(Tuple candidate) { for (int i = 0; i < this.keyPositions.length; i++) { if (!this.comparators[i].equalToReference(candidate.getObject(this.keyPositions[i]))) { return false; } } return true; }
@SuppressWarnings("unchecked") @Override public boolean equalToReference(Tuple candidate) { if(!areKeysAbs) { makeKeysAbs(keyPositions, candidate.size()); areKeysAbs = true; } for (int i = 0; i < this.keyPositions.length; i++) { if (!this.comparators[i].equalToReference(candidate.getObject(keyPositions[i]))) { return false; } } return true; }
@SuppressWarnings("unchecked") public void insertOrReplace(BT record) { int hashCode = hash(buildComparator.hash(record)); int index = hashIndex(hashCode, data.length); buildComparator.setReference(record); HashEntry entry = data[index]; while (entry != null) { if (entryHashCode(entry) == hashCode && buildComparator.equalToReference((BT) entry.getValue())) { entry.setValue(record); return; } entry = entryNext(entry); } addMapping(index, hashCode, null, record); }