/** * Returns the smallest key in this symbol table greater than or equal to {@code key}. * * @param key the key * @return the smallest key in this symbol table greater than or equal to {@code key} * @throws NoSuchElementException if there is no such key * @throws IllegalArgumentException if {@code key} is {@code null} */ public Key ceiling(Key key) { if (key == null) throw new IllegalArgumentException("argument to ceiling() is null"); Key k = st.ceilingKey(key); if (k == null) throw new NoSuchElementException("all keys are less than " + key); return k; }
public MemcachedNode getNodeForKey(long _hash) { long start = (log.isDebugEnabled()) ? System.nanoTime() : 0; try { Long hash = Long.valueOf(_hash); hash = ketamaNodes.ceilingKey(hash); if (hash == null) { hash = ketamaNodes.firstKey(); } return ketamaNodes.get(hash); } finally { if (log.isDebugEnabled()) { final long end = System.nanoTime(); log.debug("getNodeForKey : \t" + (end - start) / 1000); } } }
public MemcachedNode getPrimary(String k) { if (partialStringHash.get()) { final int index = k.indexOf(hashDelimiter.get()); if (index > 0) { k = k.substring(0, index); } } final long _hash = hashingAlgorithm.hash(k); Long hash = Long.valueOf(_hash); hash = ketamaNodes.ceilingKey(hash); if (hash == null) { hash = ketamaNodes.firstKey(); } return ketamaNodes.get(hash); }
HeadPosition getSeparator(int nodeNum) { if (nodeNum >= stack.size()) { return null; } TreeShapedStack<Tree> stack = this.stack; for (int i = 0; i < nodeNum; ++i) { stack = stack.pop(); } Tree node = stack.peek(); int head = ShiftReduceUtils.headIndex(node); if (separators.get(head) != null) { return HeadPosition.HEAD; } int left = ShiftReduceUtils.leftIndex(node); Integer nextLeft = separators.floorKey(head); boolean hasLeft = (nextLeft != null && nextLeft >= left); int right = ShiftReduceUtils.rightIndex(node); Integer nextRight = separators.ceilingKey(head); boolean hasRight = (nextRight != null && nextRight <= right); if (hasLeft && hasRight) { return HeadPosition.BOTH; } else if (hasLeft) { return HeadPosition.LEFT; } else if (hasRight) { return HeadPosition.RIGHT; } else { return HeadPosition.NONE; } }
@Override public Bitmap get(int width, int height, Bitmap.Config config) { final int size = Util.getBitmapByteSize(width, height, config); Key key = keyPool.get(size); Integer possibleSize = sortedSizes.ceilingKey(size); if (possibleSize != null && possibleSize != size && possibleSize <= size * MAX_SIZE_MULTIPLE) { keyPool.offer(key); key = keyPool.get(possibleSize); } // Do a get even if we know we don't have a bitmap so that the key moves to the front in the lru pool final Bitmap result = groupedMap.get(key); if (result != null) { result.reconfigure(width, height, config); decrementBitmapOfSize(possibleSize); } return result; }
@Override public void requestNewTime(final int time) { Double ceil = timesteps.ceilingKey((double) time); if (ceil != null) { this.nextTime = ceil; } else if (!timesteps.isEmpty()) { this.nextTime = timesteps.lastKey(); } else { this.nextTime = -1; } this.currentBuffer = null; }
/** * Returns the smallest key in this symbol table greater than or equal to {@code key}. * * @param key the key * @return the smallest key in this symbol table greater than or equal to {@code key} * @throws NoSuchElementException if there is no such key * @throws IllegalArgumentException if {@code key} is {@code null} */ public Key ceiling(Key key) { if (key == null) throw new IllegalArgumentException("called ceiling() with null key"); Key k = st.ceilingKey(key); if (k == null) throw new NoSuchElementException("all keys are less than " + key); return k; }
/** * Returns the smallest key in this symbol table greater than or equal to <tt>key</tt>. * * @param key the key * @return the smallest key in this symbol table greater than or equal to <tt>key</tt> * @throws NoSuchElementException if there is no such key * @throws NullPointerException if <tt>key</tt> is <tt>null</tt> */ public Key ceiling(Key key) { if (key == null) throw new NullPointerException("called ceiling() with null key"); Key k = st.ceilingKey(key); if (k == null) throw new NoSuchElementException("all keys are less than " + key); return k; }
TreeMap<Integer, Integer> treeMap = new TreeMap<>(); int key = RandomUtils.ranInt(treeMap.lastKey()); int value = treeMap.ceilingKey(key);
public static boolean haveCommonKeys(TreeMap<String,?> map1, TreeMap<String,?> map2) { if(map1.isEmpty()) return false; for(String s=map1.firstKey(); s!=null; ) { String s2=map2.ceilingKey(s); if(s2==null) break; if(s2.equals(s)) return true; s=map1.ceilingKey(s2); if(s2.equals(s)) return true; } return false; }
public T findBy(String prefix) { if (prefix == null) return null; String nextKey = holder.ceilingKey(prefix); if (nextKey == null) return null; SortedMap<String, T> tail = holder.tailMap(nextKey); for (String key : tail.keySet()) { if (key.startsWith(prefix)) { return tail.get(key); } } return null; }
public Version getVersion(Long id) { if (id == null) { return null; } Version v = this.store.ceilingKey(new Version(id)); if (v != null && v.id.equals(id)) { return v; } else { return null; } }
public Version getVersion(Long id) { if (id == null) { return null; } Version v = this.store.ceilingKey(new Version(id)); if (v != null && v.id.equals(id)) { return v; } else { return null; } }
private T getNodeForKey(long hash) { final T rv; if (!ketamaNodes.containsKey(hash)) { // Java 1.6 adds a ceilingKey method, but I'm still stuck in 1.5 // in a lot of places, so I'm doing this myself. /*SortedMap<Long, T> tailMap = ketamaNodes.tailMap(hash); if (tailMap.isEmpty()) { hash = ketamaNodes.firstKey(); } else { hash = tailMap.firstKey(); }*/ Long newHash = ketamaNodes.ceilingKey(hash); if (newHash == null) { hash = ketamaNodes.firstKey(); } else { hash = newHash.longValue(); } } rv = ketamaNodes.get(hash); return rv; } }
private static Double getClosest(TreeMap<Double, String> mySet, Double d) { if (mySet.ceilingKey(d) != null && mySet.floorKey(d) != null){ if( Math.abs(d - mySet.ceilingKey(d)) < Math.abs(d - mySet.floorKey(d)) ) return mySet.ceilingKey(d); else return mySet.floorKey(d); } else if (mySet.ceilingKey(d) == null && mySet.floorKey(d) != null) { return mySet.floorKey(d); } else if (mySet.ceilingKey(d) != null && mySet.floorKey(d) == null) { return mySet.ceilingKey(d); } else return null; }
TreeMap<Integer, String> treeMap = new TreeMap<Integer, String>(); treeMap.put(100, "MarshalLib100"); treeMap.put(110, "MarshalLib110"); treeMap.put(102, "MarshalLib102"); treeMap.put(101, "MarshalLib101"); treeMap.put(150, "MarshalLib150"); System.out.println(treeMap.floorKey(102)); System.out.println(treeMap.floorEntry(102)); System.out.println(treeMap.ceilingKey(102)); System.out.println(treeMap.ceilingEntry(102));
private String findConsumerByPartition(final TreeMap<Long, String> consumerMap, final String partition) { final Long hash = this.alg.hash(partition); Long target = hash; if (!consumerMap.containsKey(hash)) { target = consumerMap.ceilingKey(hash); // if (hash == null) { // target = consumerMap.floorKey(hash); // } // else { // final Long floor = consumerMap.floorKey(hash); // if (floor != null) { // target = Math.abs(hash - floor) > Math.abs(hash - target) ? // target : floor; // } // } if (target == null && !consumerMap.isEmpty()) { target = consumerMap.firstKey(); } } final String targetConsumer = consumerMap.get(target); return targetConsumer; }
@Override public int read() throws IOException { if (act == null) { return -1; } if (pointerInAct < act.length) { return act[pointerInAct++] & 0xff; } else { Long next = map.ceilingKey(pointer + 1); if (next == null) { return -1; } seek(next); return read(); } }
public String getMatchingEntry(String name) { String key = this.header2ends.ceilingKey(name); if (key == null || !key.startsWith(name)) return null; int position = this.header2ends.get(key) - 1; Integer start = annotations.floorKey(position); // always "_" at start Integer end = annotations.higherKey(position); // exclusive if (start == null) start = 0; if (end == null) end = (int) this.getSize(); while (!isValid(end - 1)) end--; // ensure that the last character is valid (exclusive) return this.getSubsequence(start + 1, end); }
@Override @Nullable public Bitmap get(int width, int height, Bitmap.Config config) { final int size = Util.getBitmapByteSize(width, height, config); Key key = keyPool.get(size); Integer possibleSize = sortedSizes.ceilingKey(size); if (possibleSize != null && possibleSize != size && possibleSize <= size * MAX_SIZE_MULTIPLE) { keyPool.offer(key); key = keyPool.get(possibleSize); } // Do a get even if we know we don't have a bitmap so that the key moves to the front in the // lru pool final Bitmap result = groupedMap.get(key); if (result != null) { result.reconfigure(width, height, config); decrementBitmapOfSize(possibleSize); } return result; }