Constraint implements Writable { protected static boolean progressUntil(byte[] key, SeekingCurrentIterator resultIterator) { if (!resultIterator.isMarkedDoneWith()) { Result current = resultIterator.current(); byte[] currentKey = current == null ? EMPTY_START_ROW : current .getRecordId(); int comparison = Bytes.compareTo(currentKey, key); if (comparison == 0) { return true; } else if (comparison < 0) { resultIterator.seek(key); Result seeked = resultIterator.current(); if (seeked == null) { return false; } else if ((comparison = Bytes.compareTo(seeked.getRecordId(), key)) > 0) { return false; } else { assert (comparison == 0); return true; } } else { return false; } } return false; }  abstract SeekingCurrentIterator getResultIterator(); void writeToTable(TableAdapter outputTable); void writeToTable(TableAdapter outputTable, Handler filter); static Constraint readFromStream(DataInput in); static void write(Constraint constraint, DataOutput out);  }
@Test public void testCanProgressExists() { List<Result> resList = new ArrayList<Result>(); for (char c = 'a'; c <= 'z'; c++) { List<CKeyValue> ckv = new ArrayList<CKeyValue>(); for (int i = 1; i < 10; i++) { for (char C = 'A'; C <= 'Z'; C++) { ckv.add(new CKeyValue(Bytes.toBytes(String.format("%c", c)), Bytes .toBytes(String.format("%d", i)), Bytes.toBytes(String.format( "%c", C)))); } } resList.add(new Result(ckv)); } SeekingCurrentIterator ci = new DecoratingCurrentIterator( resList.iterator()); Assert.assertTrue(ExposingConstraint.progressUntil(Bytes.toBytes("c"), ci)); }
@Test public void testCanProgressDoesntExist() { List<Result> resList = new ArrayList<Result>(); for (char c = 'a'; c <= 'z'; c++) { List<CKeyValue> ckv = new ArrayList<CKeyValue>(); for (int i = 1; i < 10; i++) { for (char C = 'A'; C <= 'Z'; C++) { ckv.add(new CKeyValue(Bytes.toBytes(String.format("%c", c)), Bytes .toBytes(String.format("%d", i)), Bytes.toBytes(String.format( "%c", C)))); } } resList.add(new Result(ckv)); } SeekingCurrentIterator ci = new DecoratingCurrentIterator( resList.iterator()); Assert .assertFalse(ExposingConstraint.progressUntil(Bytes.toBytes("~"), ci)); }