abstract class MeteredSearcher<T extends Comparable<T>> extends Searcher<T> implements IMetered { private Meter meter; private long startReading, endReading; private long startTime, endTime; // Constructors public MeteredSearcher() { meter = new Meter(); } public MeteredSearcher(Meter m) { meter = m; } // Private metering methods private void startMetering() { startReading = meter.reading(); startTime = System.nanoTime(); } private void stopMetering() { endTime = System.nanoTime(); endReading = meter.reading(); } // IMetered methods public boolean tick() { meter.tick(); return true; } public long unitsCounted() { return endReading - startReading; } public long timeConsumed() { return endTime - startTime; } // ISearch methods public int find(T[] seq, T key) throws IllegalArgumentException { int result; startMetering(); result = super.find(seq, key); stopMetering(); return result; } public int find(T[] seq, T key, int from, int to) throws IllegalArgumentException, IndexOutOfBoundsException { int result; startMetering(); result = super.find(seq, key, from, to); stopMetering(); return result; } }