@Override public void setReference(T reference) { comp.setReference(reference); }
@Override public void setReference(T toCompare) { if (toCompare == null) { nullReference = true; } else { nullReference = false; wrappedComparator.setReference(toCompare); } }
@Override public int compareToReference(T candidate) { comp2.setReference(candidate); return comp.compareToReference(comp2); } }
@Override public void setReference(T toCompare) { int i = 0; for (; i < this.keyFields.length; i++) { this.comparators[i].setReference(accessField(keyFields[i], toCompare)); } }
this.comparator.setReference(this.lookahead); this.valuesIterator.next = this.lookahead; this.lookahead = null; if (!this.comparator.equalToReference(next)) { this.comparator.setReference(next); this.valuesIterator.next = next; this.valuesIterator.iteratorAvailable = true; this.comparator.setReference(first); this.valuesIterator = new ValuesIterator(first, serializer); return true;
@Override public void setReference(Row toCompare) { int i = 0; try { for (; i < keyPositions.length; i++) { TypeComparator<Object> comparator = comparators[i]; Object element = toCompare.getField(keyPositions[i]); comparator.setReference(element); // element can be null } } catch (IndexOutOfBoundsException e) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } }
@SuppressWarnings("unchecked") @Override public void setReference(T toCompare) { int i = 0; try { for (; i < this.keyPositions.length; i++) { this.comparators[i].setReference(toCompare.getFieldNotNull(this.keyPositions[i])); } } catch (NullFieldException nfex) { throw new NullKeyFieldException(nfex); } catch (IndexOutOfBoundsException iobex) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } }
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()); } }
protected void testGreatSmallAscDescWithReference(boolean ascending, boolean greater) { try { T[] data = getSortedData(); TypeComparator<T> comparatorLow = getComparator(ascending); TypeComparator<T> comparatorHigh = getComparator(ascending); //compares every element in high with every element in low for (int x = 0; x < data.length - 1; x++) { for (int y = x + 1; y < data.length; y++) { comparatorLow.setReference(data[x]); comparatorHigh.setReference(data[y]); if (greater && ascending) { assertTrue(comparatorLow.compareToReference(comparatorHigh) > 0); } if (greater && !ascending) { assertTrue(comparatorLow.compareToReference(comparatorHigh) < 0); } if (!greater && ascending) { assertTrue(comparatorHigh.compareToReference(comparatorLow) < 0); } if (!greater && !ascending) { assertTrue(comparatorHigh.compareToReference(comparatorLow) > 0); } } } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
@Test public void testNormalizedKeyReadWriter() { try { T[] data = getSortedData(); T reuse = getSortedData()[0]; TypeComparator<T> comp1 = getComparator(true); if(!comp1.supportsSerializationWithKeyNormalization()){ return; } TypeComparator<T> comp2 = comp1.duplicate(); comp2.setReference(reuse); TestOutputView out = new TestOutputView(); TestInputView in; for (T value : data) { comp1.setReference(value); comp1.writeWithKeyNormalization(value, out); in = out.getInputView(); comp1.readWithKeyDenormalization(reuse, in); assertTrue(comp1.compareToReference(comp2) == 0); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
@Override public void setReference(T t) { if(t == null) { this.refNull = true; } else { this.wrappedComparator.setReference(t); this.refNull = false; } }
public boolean nextHead() throws IOException { if ((this.head = this.iterator.next()) != null) { this.comparator.setReference(this.head); return true; } else { return false; } } }
public boolean nextHead(E reuse) throws IOException { if ((this.head = this.iterator.next(reuse)) != null) { this.comparator.setReference(this.head); return true; } else { return false; } }
public boolean nextHead(E reuse) throws IOException { if ((this.head = this.iterator.next(reuse)) != null) { this.comparator.setReference(this.head); return true; } else { return false; } }
public boolean nextHead(E reuse) throws IOException { if ((this.head = this.iterator.next(reuse)) != null) { this.comparator.setReference(this.head); return true; } else { return false; } }
@Override public void setReference(Row toCompare) { int i = 0; try { for (; i < keyPositions.length; i++) { TypeComparator<Object> comparator = comparators[i]; Object element = toCompare.getField(keyPositions[i]); comparator.setReference(element); // element can be null } } catch (IndexOutOfBoundsException e) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } }
@SuppressWarnings("unchecked") @Override public void setReference(Tuple toCompare) { if(!areKeysAbs) { makeKeysAbs(keyPositions, toCompare.size()); areKeysAbs = true; } for (int i = 0; i < this.keyPositions.length; i++) { this.comparators[i].setReference(toCompare.getObject(keyPositions[i])); } }