Refine search
/** * Gets the latest build #m that satisfies {@code m<=n}. * * This is useful when you'd like to fetch a build but the exact build might * be already gone (deleted, rotated, etc.) * @see LazyBuildMixIn#getNearestOldBuild */ public RunT getNearestOldBuild(int n) { SortedMap<Integer, ? extends RunT> m = _getRuns().tailMap(n); if (m.isEmpty()) return null; return m.get(m.firstKey()); }
/** * Gets the youngest build #m that satisfies {@code n<=m}. * * This is useful when you'd like to fetch a build but the exact build might * be already gone (deleted, rotated, etc.) * @see LazyBuildMixIn#getNearestBuild */ public RunT getNearestBuild(int n) { SortedMap<Integer, ? extends RunT> m = _getRuns().headMap(n - 1); // the map should // include n, so n-1 if (m.isEmpty()) return null; return m.get(m.lastKey()); }
static private long getAppropriateSeq(SortedMap<Long, AppVersion> timeStamps, long when, boolean roundToLaterVersion) { if (roundToLaterVersion) { SortedMap<Long, AppVersion> geq = timeStamps.tailMap(when); if (geq.isEmpty()) { return Long.MAX_VALUE; } return geq.get(geq.firstKey()).getSequenceNumber(); } else { SortedMap<Long, AppVersion> leq = timeStamps.headMap(when); if (leq.isEmpty()) { return Long.MIN_VALUE; } return leq.get(leq.lastKey()).getSequenceNumber(); } }
private synchronized Pair<Long, SocketAddress> get(long hash) { if (circle.isEmpty()) { return null; } if (!circle.containsKey(hash)) { SortedMap<Long, SocketAddress> tailMap = circle.tailMap(hash); hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey(); } return Pair.of(hash, circle.get(hash)); }
public Object getPreviousState(long txid) { final SortedMap<Long, Object> prevMap = _curr.headMap(txid); Object state; if (prevMap.isEmpty()) { state = null; } else { state = prevMap.get(prevMap.lastKey()); } LOG.debug("Getting previous [state = {}], [txid = {}]", state, txid); LOG.trace("[{}]", this); return state; }
private void patchDepartureTimeline(ZoneId zoneId, NavigableMap<Integer, Integer> timeline, int platformNode) { NavigableMap<Integer, Integer> staticDepartureTimelineForRoute = findDepartureTimelineForPlatform(platformNode); timeline.forEach((time, node) -> { SortedMap<Integer, Integer> headMap = staticDepartureTimelineForRoute.headMap(time); if (!headMap.isEmpty()) { EdgeIteratorState edge = graph.edge(headMap.get(headMap.lastKey()), node); edge.setFlags(encoder.setAccess(edge.getFlags(), true, false)); setEdgeTypeAndClearDistance(edge, GtfsStorage.EdgeType.WAIT); edge.setFlags(encoder.setTime(edge.getFlags(), time - headMap.lastKey())); } SortedMap<Integer, Integer> tailMap = staticDepartureTimelineForRoute.tailMap(time); if (!tailMap.isEmpty()) { EdgeIteratorState edge = graph.edge(node, tailMap.get(tailMap.firstKey())); edge.setFlags(encoder.setAccess(edge.getFlags(), true, false)); setEdgeTypeAndClearDistance(edge, GtfsStorage.EdgeType.WAIT); edge.setFlags(encoder.setTime(edge.getFlags(), tailMap.firstKey() - time)); } EdgeIteratorState edge = graph.edge(platformNode, node); edge.setFlags(encoder.setAccess(edge.getFlags(), true, false)); setEdgeTypeAndClearDistance(edge, GtfsStorage.EdgeType.ENTER_TIME_EXPANDED_NETWORK); edge.setFlags(encoder.setTime(edge.getFlags(), time)); setFeedIdWithTimezone(edge, new GtfsStorage.FeedIdWithTimezone(id, zoneId)); }); }
private byte[] buildOS2Table() throws IOException if (os2 == null || uniToGID.isEmpty() || keepTables != null && !keepTables.contains("OS/2")) writeUint16(out, uniToGID.firstKey()); writeUint16(out, uniToGID.lastKey()); writeUint16(out, os2.getTypoAscender()); writeUint16(out, os2.getTypoDescender());
private int getOffset(SortedMap<Integer, Integer> duplicates, int i) { SortedMap<Integer, Integer> headMap = duplicates.headMap(i+1); if(headMap.isEmpty()) { return -1; } int end = headMap.get(headMap.lastKey()); if(end <= i) { return -1; } return getInstructionNumber(positions, i)-getInstructionNumber(positions, headMap.lastKey()); }
/** * Splits the range set at the given timestamp (if it hasn't been split yet) */ private void splitAt(long t) { if (data.containsKey(t)) return; // already split at this timestamp SortedMap<Long, int[]> head = data.headMap(t); int v = head.isEmpty() ? 0 : data.get(head.lastKey())[0]; data.put(t, new int[]{v}); }
public void printHistory() { for (final PseudoTime time : history.keySet()) { System.out.println(" " + time + ": " + history.get(time)); } if (!history.isEmpty()) { System.out.println(" " + history.firstKey() + ": " + getProperties(history.firstKey())); System.out.println(" " + history.lastKey() + ": " + getProperties(history.lastKey())); } }
@Test public void getMetrics() { final int FILES_PINNED_TEST_VALUE = 100; String filesPinnedProperty = MetricsSystem.getMetricName(MasterMetrics.FILES_PINNED); Gauge<Integer> filesPinnedGauge = () -> FILES_PINNED_TEST_VALUE; MetricSet mockMetricsSet = mock(MetricSet.class); Map<String, Metric> map = new HashMap<>(); map.put(filesPinnedProperty, filesPinnedGauge); when(mockMetricsSet.getMetrics()).thenReturn(map); MetricsSystem.METRIC_REGISTRY.registerAll(mockMetricsSet); Response response = mHandler.getMetrics(); try { assertNotNull("Response must be not null!", response); assertNotNull("Response must have a entry!", response.getEntity()); assertTrue("Entry must be a SortedMap!", (response.getEntity() instanceof SortedMap)); SortedMap<String, Long> metricsMap = (SortedMap<String, Long>) response.getEntity(); assertFalse("Metrics Map must be not empty!", (metricsMap.isEmpty())); assertTrue("Map must contain key " + filesPinnedProperty + "!", metricsMap.containsKey(filesPinnedProperty)); assertEquals(FILES_PINNED_TEST_VALUE, metricsMap.get(filesPinnedProperty).longValue()); } finally { response.close(); } }