@Test public void testClosestElement2() { List<VDouble> data = new ArrayList<VDouble>(); Instant reference = Instant.now(); data.add(newVDouble(-2.0, newTime(reference.minus(ofMillis(5))))); data.add(newVDouble(-1.0, newTime(reference.minus(ofMillis(1))))); data.add(newVDouble(1.0, newTime(reference.plus(ofMillis(2))))); data.add(newVDouble(2.0, newTime(reference.plus(ofMillis(3))))); VDouble result = SynchronizedVDoubleAggregator.closestElement(data, TimeInterval.around(ofMillis(10), reference), reference); assertEquals(-1.0, result.getValue(), 0.000001); }
static <T extends Time> T closestElement(List<T> data, TimeInterval interval, Instant reference) { StringBuilder buffer = new StringBuilder(); T latest = null; long latestDistance = Long.MAX_VALUE; for (T value : data) { Instant newTime = value.getTimestamp(); if (log.isLoggable(Level.FINEST)) { buffer.append(newTime.getNano()).append(", "); } if (interval.contains(newTime)) { if (latest == null) { latest = value; latestDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); } else { long newDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); if (newDistance < latestDistance) { latest = value; latestDistance = newDistance; } } } } if (log.isLoggable(Level.FINEST)) { buffer.append("[").append(latest.getTimestamp().getNano()).append("|").append(reference.getNano()).append("]"); log.finest(buffer.toString()); } return latest; }
SynchronizedVDoubleAggregator implements ReadFunction<VMultiDouble> { static <T extends Time> T closestElement(List<T> data, TimeInterval interval, Instant reference) { StringBuilder buffer = new StringBuilder(); T latest = null; long latestDistance = Long.MAX_VALUE; for (T value : data) { Instant newTime = value.getTimestamp(); if (log.isLoggable(Level.FINEST)) { buffer.append(newTime.getNano()).append(", "); } if (interval.contains(newTime)) { if (latest == null) { latest = value; latestDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); } else { long newDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); if (newDistance < latestDistance) { latest = value; latestDistance = newDistance; } } } } if (log.isLoggable(Level.FINEST)) { buffer.append("[").append(latest.getTimestamp().getNano()).append("|").append(reference.getNano()).append("]"); log.finest(buffer.toString()); } return latest; } }
SynchronizedVDoubleAggregator implements ReadFunction<VMultiDouble> { static <T extends Time> T closestElement(List<T> data, TimeInterval interval, Instant reference) { StringBuilder buffer = new StringBuilder(); T latest = null; long latestDistance = Long.MAX_VALUE; for (T value : data) { Instant newTime = value.getTimestamp(); if (log.isLoggable(Level.FINEST)) { buffer.append(newTime.getNano()).append(", "); } if (interval.contains(newTime)) { if (latest == null) { latest = value; latestDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); } else { long newDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); if (newDistance < latestDistance) { latest = value; latestDistance = newDistance; } } } } if (log.isLoggable(Level.FINEST)) { buffer.append("[").append(latest.getTimestamp().getNano()).append("|").append(reference.getNano()).append("]"); log.finest(buffer.toString()); } return latest; } @SuppressWarnings("unchecked")  SynchronizedVDoubleAggregator(List<String> names, List<ReadFunction<List<VDouble>>> collectors, Duration tolerance); }
SynchronizedVDoubleAggregator implements ReadFunction<VMultiDouble> { static <T extends Time> T closestElement(List<T> data, TimeInterval interval, Instant reference) { StringBuilder buffer = new StringBuilder(); T latest = null; long latestDistance = Long.MAX_VALUE; for (T value : data) { Instant newTime = value.getTimestamp(); if (log.isLoggable(Level.FINEST)) { buffer.append(newTime.getNano()).append(", "); } if (interval.contains(newTime)) { if (latest == null) { latest = value; latestDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); } else { long newDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); if (newDistance < latestDistance) { latest = value; latestDistance = newDistance; } } } } if (log.isLoggable(Level.FINEST)) { buffer.append("[").append(latest.getTimestamp().getNano()).append("|").append(reference.getNano()).append("]"); log.finest(buffer.toString()); } return latest; } @SuppressWarnings("unchecked")  SynchronizedVDoubleAggregator(List<String> names, List<ReadFunction<List<VDouble>>> collectors, Duration tolerance); @Override VMultiDouble readValue(); }
SynchronizedVDoubleAggregator implements ReadFunction<VMultiDouble> { static <T extends Time> T closestElement(List<T> data, TimeInterval interval, Instant reference) { StringBuilder buffer = new StringBuilder(); T latest = null; long latestDistance = Long.MAX_VALUE; for (T value : data) { Instant newTime = value.getTimestamp(); if (log.isLoggable(Level.FINEST)) { buffer.append(newTime.getNano()).append(", "); } if (interval.contains(newTime)) { if (latest == null) { latest = value; latestDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); } else { long newDistance = Math.abs(reference.until(newTime, ChronoUnit.NANOS)); if (newDistance < latestDistance) { latest = value; latestDistance = newDistance; } } } } if (log.isLoggable(Level.FINEST)) { buffer.append("[").append(latest.getTimestamp().getNano()).append("|").append(reference.getNano()).append("]"); log.finest(buffer.toString()); } return latest; } @SuppressWarnings("unchecked")  SynchronizedVDoubleAggregator(List<String> names, List<ReadFunction<List<VDouble>>> collectors, Duration tolerance); @Override VMultiDouble readValue();  }