@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 T getRecord(T reuse, int logicalPosition) throws IOException { final int buffer = logicalPosition / this.recordsPerSegment; final int inBuffer = (logicalPosition % this.recordsPerSegment) * this.recordSize; this.inView.set(this.sortBuffer.get(buffer), inBuffer); return this.comparator.readWithKeyDenormalization(reuse, this.inView); }
@Override public T getRecord(T reuse, int logicalPosition) throws IOException { final int buffer = logicalPosition / this.recordsPerSegment; final int inBuffer = (logicalPosition % this.recordsPerSegment) * this.recordSize; this.inView.set(this.sortBuffer.get(buffer), inBuffer); return this.comparator.readWithKeyDenormalization(reuse, this.inView); }
@Override public T getRecord(T reuse, int logicalPosition) throws IOException { final int buffer = logicalPosition / this.recordsPerSegment; final int inBuffer = (logicalPosition % this.recordsPerSegment) * this.recordSize; this.inView.set(this.sortBuffer.get(buffer), inBuffer); return this.comparator.readWithKeyDenormalization(reuse, this.inView); }
@Override public T getRecord(T reuse, int logicalPosition) throws IOException { final int buffer = logicalPosition / this.recordsPerSegment; final int inBuffer = (logicalPosition % this.recordsPerSegment) * this.recordSize; this.inView.set(this.sortBuffer.get(buffer), inBuffer); return this.comparator.readWithKeyDenormalization(reuse, this.inView); }
@Override public T next(T reuse) { if (this.currentTotal < this.numTotal) { if (this.currentInSegment >= this.numPerSegment) { this.currentInSegment = 0; this.currentSegmentIndex++; this.in.set(sortBuffer.get(this.currentSegmentIndex), 0); } this.currentTotal++; this.currentInSegment++; try { return this.comp.readWithKeyDenormalization(reuse, this.in); } catch (IOException ioe) { throw new RuntimeException(ioe); } } else { return null; } }
@Override public T next(T reuse) { if (this.currentTotal < this.numTotal) { if (this.currentInSegment >= this.numPerSegment) { this.currentInSegment = 0; this.currentSegmentIndex++; this.in.set(sortBuffer.get(this.currentSegmentIndex), 0); } this.currentTotal++; this.currentInSegment++; try { return this.comp.readWithKeyDenormalization(reuse, this.in); } catch (IOException ioe) { throw new RuntimeException(ioe); } } else { return null; } }
@Override public T next(T reuse) { if (this.currentTotal < this.numTotal) { if (this.currentInSegment >= this.numPerSegment) { this.currentInSegment = 0; this.currentSegmentIndex++; this.in.set(sortBuffer.get(this.currentSegmentIndex), 0); } this.currentTotal++; this.currentInSegment++; try { return this.comp.readWithKeyDenormalization(reuse, this.in); } catch (IOException ioe) { throw new RuntimeException(ioe); } } else { return null; } }
@Override public T next(T reuse) { if (this.currentTotal < this.numTotal) { if (this.currentInSegment >= this.numPerSegment) { this.currentInSegment = 0; this.currentSegmentIndex++; this.in.set(sortBuffer.get(this.currentSegmentIndex), 0); } this.currentTotal++; this.currentInSegment++; try { return this.comp.readWithKeyDenormalization(reuse, this.in); } catch (IOException ioe) { throw new RuntimeException(ioe); } } else { return null; } }
@Override public T next() { if (this.currentTotal < this.numTotal) { if (this.currentInSegment >= this.numPerSegment) { this.currentInSegment = 0; this.currentSegmentIndex++; this.in.set(sortBuffer.get(this.currentSegmentIndex), 0); } this.currentTotal++; this.currentInSegment++; try { return this.comp.readWithKeyDenormalization(serializer.createInstance(), this.in); } catch (IOException ioe) { throw new RuntimeException(ioe); } } else { return null; } } };
@Override public T next() { if (this.currentTotal < this.numTotal) { if (this.currentInSegment >= this.numPerSegment) { this.currentInSegment = 0; this.currentSegmentIndex++; this.in.set(sortBuffer.get(this.currentSegmentIndex), 0); } this.currentTotal++; this.currentInSegment++; try { return this.comp.readWithKeyDenormalization(serializer.createInstance(), this.in); } catch (IOException ioe) { throw new RuntimeException(ioe); } } else { return null; } } };
@Override public T next() { if (this.currentTotal < this.numTotal) { if (this.currentInSegment >= this.numPerSegment) { this.currentInSegment = 0; this.currentSegmentIndex++; this.in.set(sortBuffer.get(this.currentSegmentIndex), 0); } this.currentTotal++; this.currentInSegment++; try { return this.comp.readWithKeyDenormalization(serializer.createInstance(), this.in); } catch (IOException ioe) { throw new RuntimeException(ioe); } } else { return null; } } };
@Override public T next() { if (this.currentTotal < this.numTotal) { if (this.currentInSegment >= this.numPerSegment) { this.currentInSegment = 0; this.currentSegmentIndex++; this.in.set(sortBuffer.get(this.currentSegmentIndex), 0); } this.currentTotal++; this.currentInSegment++; try { return this.comp.readWithKeyDenormalization(serializer.createInstance(), this.in); } catch (IOException ioe) { throw new RuntimeException(ioe); } } else { return null; } } };
record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output); record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output);
record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output); record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output);
record = comparator.readWithKeyDenormalization(record, inView); output.writeRecord(record); record = comparator.readWithKeyDenormalization(record, inView); output.writeRecord(record);
record = comparator.readWithKeyDenormalization(record, inView); output.writeRecord(record); record = comparator.readWithKeyDenormalization(record, inView); output.writeRecord(record);
record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output); record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output);
record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output); record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output);
record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output); record = comparator.readWithKeyDenormalization(record, inView); serializer.serialize(record, output);