public CaptureSearchResult getClosest() { if (closest != null) { return closest; } if (!results.isEmpty()) { // If no target timestamp, always return the latest capture, // otherwise first or last based on reverse state if (targetTimestamp != null) { return getLastAdded(); } else { return results.getResults().getLast(); } } return null; }
public CaptureSearchResult getClosest() { if (closest != null) { return closest; } if (!results.isEmpty()) { // If no target timestamp, always return the latest capture, // otherwise first or last based on reverse state if (targetTimestamp != null) { return getLastAdded(); } else { return results.getResults().getLast(); } } return null; }
protected CaptureSearchResult determineClosest( CaptureSearchResult nextResult) { int compare = targetTimestamp.compareTo(nextResult .getCaptureTimestamp()) * flip; if (compare == 0) { return nextResult; } else if (compare > 0) { // Too early to tell return null; } // First result that is greater/less than target if (results.isEmpty()) { return nextResult; } CaptureSearchResult lastResult = getLastAdded(); // Now compare date diff long nextTime = nextResult.getCaptureDate().getTime(); long lastTime = lastResult.getCaptureDate().getTime(); long targetTime = Timestamp.parseAfter(targetTimestamp).getDate() .getTime(); if (Math.abs(nextTime - targetTime) < Math.abs(lastTime - targetTime)) { return nextResult; } else { return lastResult; } }
protected CaptureSearchResult determineClosest( CaptureSearchResult nextResult) { int compare = targetTimestamp.compareTo(nextResult .getCaptureTimestamp()) * flip; if (compare == 0) { return nextResult; } else if (compare > 0) { // Too early to tell return null; } // First result that is greater/less than target if (results.isEmpty()) { return nextResult; } CaptureSearchResult lastResult = getLastAdded(); // Now compare date diff long nextTime = nextResult.getCaptureDate().getTime(); long lastTime = lastResult.getCaptureDate().getTime(); long targetTime = Timestamp.parseAfter(targetTimestamp).getDate() .getTime(); if (Math.abs(nextTime - targetTime) < Math.abs(lastTime - targetTime)) { return nextResult; } else { return lastResult; } }