Refine search
/** * 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}); }
/** * @param key the metric name to lookup * @param whiteList * * @return <tt>null</tt> if the key does not match with any of the prefixes keys in @code metricsWhiteList, * or the prefix in @code whiteListDimsMapper */ private String getPrefixKey(String key, SortedMap<String, ?> whiteList) { String prefixKey = null; if (whiteList.containsKey(key)) { return key; } SortedMap<String, ?> headMap = whiteList.headMap(key); if (!headMap.isEmpty() && key.startsWith(headMap.lastKey())) { prefixKey = headMap.lastKey(); } return prefixKey; }
/** * @param key the metric name to lookup * @param whiteList * * @return <tt>null</tt> if the key does not match with any of the prefixes keys in @code metricsWhiteList, * or the prefix in @code whiteListDimsMapper */ private String getPrefixKey(String key, SortedMap<String, ?> whiteList) { String prefixKey = null; if (whiteList.containsKey(key)) { return key; } SortedMap<String, ?> headMap = whiteList.headMap(key); if (!headMap.isEmpty() && key.startsWith(headMap.lastKey())) { prefixKey = headMap.lastKey(); } return prefixKey; }
/** * 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()); }
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()); }
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; }
/** * Gets the index of the last cell contained in this row <b>PLUS ONE</b>. The result also * happens to be the 1-based column number of the last cell. This value can be used as a * standard upper bound when iterating over cells: * <pre> * short minColIx = row.getFirstCellNum(); * short maxColIx = row.getLastCellNum(); * for(short colIx=minColIx; colIx<maxColIx; colIx++) { * Cell cell = row.getCell(colIx); * if(cell == null) { * continue; * } * //... do something with cell * } * </pre> * * @return short representing the last logical cell in the row <b>PLUS ONE</b>, * or -1 if the row does not contain any cells. */ @Override public short getLastCellNum() { return _cells.isEmpty() ? -1 : (short)(_cells.lastKey() + 1); }
public boolean intersects(LongRangeSet other) { for (Entry<Long, Long> entry : map.entrySet()) { SortedMap<Long, Long> subMap = entry.getValue() == Long.MAX_VALUE ? other.map.tailMap(entry.getKey()) : other.map .subMap(entry.getKey(), entry.getValue() + 1); if (!subMap.isEmpty()) { return true; } SortedMap<Long, Long> headMap = other.map.headMap(entry.getKey()); if (!headMap.isEmpty() && headMap.get(headMap.lastKey()) >= entry.getKey()) { return true; } } return false; }
public void splitGreater(long number) { Long lNumber = number; if(number == Long.MAX_VALUE) { return; } Long nextNumber = number + 1; SortedMap<Long, Long> headMap = map.headMap(nextNumber); if (headMap.isEmpty()) { return; } Long lastKey = headMap.lastKey(); Long lastValue = headMap.get(lastKey); if (number >= lastValue) { return; } map.put(lastKey, lNumber); map.put(nextNumber, lastValue); }
public Vertex getSource() { SortedMap<Long, Vertex> sourceMap = graph.getIndexedVertices().get(source); if (sourceMap == null) { return null; } SortedMap<Long, Vertex> headMap = sourceMap.headMap(dest.getTimestamp() + 1); if (headMap.isEmpty()) { return null; } Long closestTimestamp = headMap.lastKey(); return headMap.get(closestTimestamp); }
/** * Find the relevant compression codec for the given file based on its * filename suffix. * @param file the filename to check * @return the codec object */ public CompressionCodec getCodec(Path file) { CompressionCodec result = null; if (codecs != null) { String filename = file.getName(); String reversedFilename = new StringBuilder(filename).reverse().toString(); SortedMap<String, CompressionCodec> subMap = codecs.headMap(reversedFilename); if (!subMap.isEmpty()) { String potentialSuffix = subMap.lastKey(); if (reversedFilename.startsWith(potentialSuffix)) { result = codecs.get(potentialSuffix); } } } return result; }
private void add(Long start, Long end) { SortedMap<Long, Long> headMap; if (end < Long.MAX_VALUE) { headMap = map.headMap(end + 1); Long tailEnd = map.remove(end + 1); if (tailEnd != null) { end = tailEnd; } if (!headMap.isEmpty()) { tailEnd = headMap.get(headMap.lastKey()); if (tailEnd > end) { end = tailEnd; } } } headMap = map.headMap(start); if (!headMap.isEmpty()) { Long headStart = headMap.lastKey(); Long headEnd = map.get(headStart); if (headEnd >= start - 1) { map.remove(headStart); start = headStart; } } map.subMap(start, end).clear(); map.remove(end); map.put(start, end); }