@Test public void testHardToFindFid() throws Exception { long offset = reader.search(5, 3, 7, 5); assertEquals(4, offset); }
long search(long desired, long minRec, long maxRec, long predictedRec) throws IOException { if (minRec == maxRec) { return -1; } goTo(predictedRec); hasNext(); next(); buffer.limit(buffer.capacity()); if (currentId == desired) { return currentShxIndex; } if (maxRec - minRec < 10) { return search(desired, minRec + 1, maxRec, minRec + 1); } else { long newOffset = desired - currentId; long newPrediction = predictedRec + newOffset; if (newPrediction <= minRec) { newPrediction = minRec + ((predictedRec - minRec) / 2); } if (newPrediction >= maxRec) { newPrediction = predictedRec + ((maxRec - predictedRec) / 2); } if (newPrediction == predictedRec) { return -1; } if (newPrediction < predictedRec) { return search(desired, minRec, predictedRec, newPrediction); } else { return search(desired, predictedRec, maxRec, newPrediction); } } }
IndexedFidReader implements FIDReader, FileReader { long search(long desired, long minRec, long maxRec, long predictedRec) throws IOException { if (minRec == maxRec) { return -1; } goTo(predictedRec); hasNext(); next(); buffer.limit(buffer.capacity()); if (currentId == desired) { return currentShxIndex; } if (maxRec - minRec < 10) { return search(desired, minRec + 1, maxRec, minRec + 1); } else { long newOffset = desired - currentId; long newPrediction = predictedRec + newOffset; if (newPrediction <= minRec) { newPrediction = minRec + ((predictedRec - minRec) / 2); } if (newPrediction >= maxRec) { newPrediction = predictedRec + ((maxRec - predictedRec) / 2); } if (newPrediction == predictedRec) { return -1; } if (newPrediction < predictedRec) { return search(desired, minRec, predictedRec, newPrediction); } else { return search(desired, predictedRec, maxRec, newPrediction); } } } }
IndexedFidReader implements FIDReader, FileReader { long search(long desired, long minRec, long maxRec, long predictedRec) throws IOException { if (minRec == maxRec) { return -1; } goTo(predictedRec); hasNext(); next(); buffer.limit(buffer.capacity()); if (currentId == desired) { return currentShxIndex; } if (maxRec - minRec < 10) { return search(desired, minRec + 1, maxRec, minRec + 1); } else { long newOffset = desired - currentId; long newPrediction = predictedRec + newOffset; if (newPrediction <= minRec) { newPrediction = minRec + ((predictedRec - minRec) / 2); } if (newPrediction >= maxRec) { newPrediction = predictedRec + ((maxRec - predictedRec) / 2); } if (newPrediction == predictedRec) { return -1; } if (newPrediction < predictedRec) { return search(desired, minRec, predictedRec, newPrediction); } else { return search(desired, predictedRec, maxRec, newPrediction); } } } IndexedFidReader(ShpFiles shpFiles);  IndexedFidReader(ShpFiles shpFiles, ReadableByteChannel in); }
IndexedFidReader implements FIDReader, FileReader { long search(long desired, long minRec, long maxRec, long predictedRec) throws IOException { if (minRec == maxRec) { return -1; } goTo(predictedRec); hasNext(); next(); buffer.limit(buffer.capacity()); if (currentId == desired) { return currentShxIndex; } if (maxRec - minRec < 10) { return search(desired, minRec + 1, maxRec, minRec + 1); } else { long newOffset = desired - currentId; long newPrediction = predictedRec + newOffset; if (newPrediction <= minRec) { newPrediction = minRec + ((predictedRec - minRec) / 2); } if (newPrediction >= maxRec) { newPrediction = predictedRec + ((maxRec - predictedRec) / 2); } if (newPrediction == predictedRec) { return -1; } if (newPrediction < predictedRec) { return search(desired, minRec, predictedRec, newPrediction); } else { return search(desired, predictedRec, maxRec, newPrediction); } } } IndexedFidReader(ShpFiles shpFiles);  IndexedFidReader(ShpFiles shpFiles, ReadableByteChannel in); long getCount(); int getRemoves(); long findFid(String fid); @SuppressWarnings("PMD.CloseResource") // FileChannel managed as a field void goTo(long recno); void close(); @SuppressWarnings("PMD.CloseResource") // FileChannel managed as a field boolean hasNext(); String next(); int currentSHXIndex(); long getCurrentFIDIndex(); String id(); }
IndexedFidReader implements FIDReader, FileReader { long search(long desired, long minRec, long maxRec, long predictedRec) throws IOException { if (minRec == maxRec) { return -1; } goTo(predictedRec); hasNext(); next(); buffer.limit(buffer.capacity()); if (currentId == desired) { return currentShxIndex; } if (maxRec - minRec < 10) { return search(desired, minRec + 1, maxRec, minRec + 1); } else { long newOffset = desired - currentId; long newPrediction = predictedRec + newOffset; if (newPrediction <= minRec) { newPrediction = minRec + ((predictedRec - minRec) / 2); } if (newPrediction >= maxRec) { newPrediction = predictedRec + ((maxRec - predictedRec) / 2); } if (newPrediction == predictedRec) { return -1; } if (newPrediction < predictedRec) { return search(desired, minRec, predictedRec, newPrediction); } else { return search(desired, predictedRec, maxRec, newPrediction); } } } IndexedFidReader(ShpFiles shpFiles);  IndexedFidReader(ShpFiles shpFiles, ReadableByteChannel in); long getCount(); int getRemoves(); long findFid(String fid); @SuppressWarnings("PMD.CloseResource") // FileChannel managed as a field void goTo(long recno); void close(); @SuppressWarnings("PMD.CloseResource") // FileChannel managed as a field boolean hasNext(); String next(); int currentSHXIndex(); long getCurrentFIDIndex(); String id();  }