/** * Get the shard entry that should hold this value */ public ShardEntryGroup getShardId( final Long seek ) { Map.Entry<Long, ShardEntryGroup> entry = shards.floorEntry( seek ); if ( entry == null ) { throw new NullPointerException( "Entry should never be null, this is a bug" ); } return entry.getValue(); } }
/** * lookup the node containing the specified procId. * @param node cached node to check before doing a lookup * @param procId the procId to lookup * @return the node that may contains the procId or null */ private BitSetNode lookupClosestNode(final BitSetNode node, final long procId) { if (node != null && node.contains(procId)) return node; final Map.Entry<Long, BitSetNode> entry = map.floorEntry(procId); return entry != null ? entry.getValue() : null; }
@Override public T sample() { final double randomValue = random.nextDouble(); Integer valueIndex = probabilityRanges.floorEntry(randomValue).getValue(); return normalizedPmf.get(valueIndex).getFirst(); } }
@Override public Position lookup(long index) { Map.Entry<Long, Integer> entry = positions.floorEntry(index); return entry != null ? new Position(entry.getKey(), entry.getValue()) : null; }
private static <K, V> V mappedValue(TreeMap<K, V> map, K key) { Entry<K, V> e = map.floorEntry(key); if (e != null && e.getValue() == null) { e = map.lowerEntry(key); } return e == null ? null : e.getValue(); }
@Override public ByteBuffer readFully(long pos, int len) { Entry<Long, ByteBuffer> memEntry = memory.floorEntry(pos); if (memEntry == null) { throw DataUtils.newIllegalStateException( DataUtils.ERROR_READING_FAILED, "Could not read from position {0}", pos); } readCount.incrementAndGet(); readBytes.addAndGet(len); ByteBuffer buff = memEntry.getValue(); ByteBuffer read = buff.duplicate(); int offset = (int) (pos - memEntry.getKey()); read.position(offset); read.limit(len + offset); return read.slice(); }
public int segment(T value) { Map.Entry<T, Integer> e = index.floorEntry(value); if (e == null) { throw new SegmenterException("Could not find bucket for: " + value); } return e.getValue(); }
public boolean isModified(long procId) { final Map.Entry<Long, BitSetNode> entry = map.floorEntry(procId); return entry != null && entry.getValue().contains(procId) && entry.getValue().isModified(procId); }
@Override public ByteBuffer readFully(long pos, int len) { Entry<Long, ByteBuffer> memEntry = memory.floorEntry(pos); if (memEntry == null) { throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, "Could not read from position {0}", pos); } readCount++; readBytes += len; ByteBuffer buff = memEntry.getValue(); ByteBuffer read = buff.duplicate(); int offset = (int) (pos - memEntry.getKey()); read.position(offset); read.limit(len + offset); return read.slice(); }
@Implementation protected void restat(String path) { Map.Entry<String, Stats> mapEntry = stats.floorEntry(path); for (;;) { // We will hit all matching paths, longest one first. We may hit non-matching paths before we // find the right one. if (mapEntry == null) { stat = DEFAULT_STATS; return; } String key = mapEntry.getKey(); if (path.startsWith(key)) { stat = mapEntry.getValue(); return; } mapEntry = stats.lowerEntry(key); } }
private SortedMap<Long, Long> getAndValidateMissingChunks( int maxAlloc, long from, long to) { Map.Entry<Long, Long> firstMissing = chunkIndex.floorEntry(from); if (firstMissing == null) { throw new AssertionError("No lower bound for start offset " + from); } if (firstMissing.getValue() <= from || ((from - firstMissing.getKey()) % maxAlloc) != 0) { // The data does not belong to a recognized chunk, or is split wrong. throw new AssertionError("Lower bound for start offset " + from + " is [" + firstMissing.getKey() + ", " + firstMissing.getValue() + ")"); } SortedMap<Long, Long> missingChunks = chunkIndex.subMap(firstMissing.getKey(), to); if (missingChunks.isEmpty()) { throw new AssertionError("No chunks for [" + from + ", " + to + ")"); } long lastMissingOffset = missingChunks.lastKey(), lastMissingEnd = missingChunks.get(lastMissingOffset); if (lastMissingEnd < to || (to != lastMissingEnd && ((to - lastMissingOffset) % maxAlloc) != 0)) { // The data does not belong to a recognized chunk, or is split wrong. throw new AssertionError("Lower bound for end offset " + to + " is [" + lastMissingOffset + ", " + lastMissingEnd + ")"); } return missingChunks; }
private double arcToParameter(double arc) { if (cache.isEmpty()) throw new IllegalStateException("Must call setNodes first."); if (arc > 1) arc = 1; arc *= totalArcLength; Entry<Double, Double> floorEntry = cache.floorEntry(arc); final double leftArc = floorEntry.getKey(); final double leftParameter = floorEntry.getValue(); if (leftArc == arc) { return leftParameter; } Entry<Double, Double> ceilingEntry = cache.ceilingEntry(arc); if (ceilingEntry == null) { log.warning("Error in arcToParameter: no ceiling entry for " + arc + " found!"); return 0; } final double rightArc = ceilingEntry.getKey(); final double rightParameter = ceilingEntry.getValue(); if (rightArc == arc) { return rightParameter; } return evaluate(arc, leftArc, leftParameter, rightArc, rightParameter); }
/** * If {@link #partial} is false, returns state from the bitmap. If no state is found for * {@code procId}, returns YES. * If partial is true, tracker doesn't have complete view of system state, so it returns MAYBE * if there is no update for the procedure or if it doesn't have a state in bitmap. Otherwise, * returns state from the bitmap. */ public DeleteState isDeleted(long procId) { Map.Entry<Long, BitSetNode> entry = map.floorEntry(procId); if (entry != null && entry.getValue().contains(procId)) { BitSetNode node = entry.getValue(); DeleteState state = node.isDeleted(procId); return partial && !node.isModified(procId) ? DeleteState.MAYBE : state; } return partial ? DeleteState.MAYBE : DeleteState.YES; }
@Override public void writeFully(long pos, ByteBuffer src) { fileSize = Math.max(fileSize, pos + src.remaining()); Entry<Long, ByteBuffer> mem = memory.floorEntry(pos); if (mem == null) {
@Override public void writeFully(long pos, ByteBuffer src) { fileSize = Math.max(fileSize, pos + src.remaining()); Entry<Long, ByteBuffer> mem = memory.floorEntry(pos); if (mem == null) { // not found: create a new entry writeNewEntry(pos, src); return; } long prevPos = mem.getKey(); ByteBuffer buff = mem.getValue(); int prevLength = buff.capacity(); int length = src.remaining(); if (prevPos == pos) { if (prevLength != length) { throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, "Could not write to position {0}; " + "partial overwrite is not supported", pos); } writeCount++; writeBytes += length; buff.rewind(); buff.put(src); return; } if (prevPos + prevLength > pos) { throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, "Could not write to position {0}; " + "partial overwrite is not supported", pos); } writeNewEntry(pos, src); }
Map.Entry<Long, BlockLocation> startEntry = locations.floorEntry(offset); BlockLocation start = startEntry.getValue(); if (offset + length <= start.getOffset() + start.getLength()) { Map.Entry<Long, BlockLocation> endEntry = locations.floorEntry(offset + length);
assert aliveSrvs.size() > 1 : aliveSrvs; Map.Entry<Long, String> prevE = aliveSrvs.floorEntry(locInternalOrder - 1);
while (it.hasNext()) { Interval interval = it.next().getInterval(); Map.Entry<Long, Long> floor = granularThresholds.floorEntry(granularity.bucketStart(interval.getStart()).getMillis()); if (floor == null || interval.getEndMillis() <= floor.getValue()) { it.remove();
assert aliveClients.size() > 1 : aliveClients; Map.Entry<Long, String> prevE = aliveClients.floorEntry(locInternalOrder - 1);
Map.Entry<Long, BitSetNode> leftEntry = map.floorEntry(procId); if (leftEntry != null) { leftNode = leftEntry.getValue();