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()); }
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)); }
private OperationsNodeInfo getNearest(byte[] hash) { if (circle.isEmpty()) { return null; } if (circle.size() == 1) { return circle.get(circle.firstKey()); } SortedMap<byte[], OperationsNodeInfo> tailMap = circle.tailMap(hash); hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey(); return circle.get(hash); }
/** * with a specified key, route the nearest Node instance in the current hash ring * * @param objectKey the object key to find a nearest Node */ public T routeNode(String objectKey) { if (ring.isEmpty()) { return null; } Long hashVal = hashFunction.hash(objectKey); SortedMap<Long, VirtualNode<T>> tailMap = ring.tailMap(hashVal); Long nodeHashVal = !tailMap.isEmpty() ? tailMap.firstKey() : ring.firstKey(); return ring.get(nodeHashVal).getPhysicalNode(); }
/** * Gets weighted node in random fashion. * * @return Weighted node. */ ClusterNode pickWeightedNode() { double weight = RAND.nextDouble(); SortedMap<Double, ClusterNode> pick = circle.tailMap(weight); ClusterNode node = pick.get(pick.firstKey()); rwLock.readLock().lock(); try { AtomicInteger cnt = nodeJobs.get(node.id()); if (cnt != null) cnt.incrementAndGet(); } finally { rwLock.readLock().unlock(); } return node; } }
@Override public void finishTree(DetailAST rootAST) { if (!lineNumberTypeMap.isEmpty()) { if (!publicTypeFound) { // skip first top-level type. lineNumberTypeMap.remove(lineNumberTypeMap.firstKey()); } for (Map.Entry<Integer, String> entry : lineNumberTypeMap.entrySet()) { log(entry.getKey(), MSG_KEY, entry.getValue()); } } }
/** * 获得一个最近的顺时针节点 * @param key 为给定键取Hash,取得顺时针方向上最近的一个虚拟节点对应的实际节点 * @return 节点对象 */ public T get(Object key) { if (circle.isEmpty()) { return null; } int hash = hashFunc.hash(key); if (!circle.containsKey(hash)) { SortedMap<Integer, T> tailMap = circle.tailMap(hash); //返回此映射的部分视图,其键大于等于 hash hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey(); } //正好命中 return circle.get(hash); }
public void testSortOrder() { SortedMap map = makeTestSortedMap(oneFactory); map.put("A", "a"); map.get("B"); // Entry with value "One" created map.put("C", "c"); assertEquals("First key should be A", map.firstKey(), "A"); assertEquals("Last key should be C", map.lastKey(), "C"); assertEquals("First key in tail map should be B", map.tailMap("B").firstKey(), "B"); assertEquals("Last key in head map should be B", map.headMap("C").lastKey(), "B"); assertEquals("Last key in submap should be B", map.subMap("A","C").lastKey(), "B"); Comparator c = map.comparator(); assertTrue("natural order, so comparator should be null", c == null); }