本文整理匯總了Java中java.util.TreeMap.tailMap方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeMap.tailMap方法的具體用法?Java TreeMap.tailMap怎麽用?Java TreeMap.tailMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.TreeMap
的用法示例。
在下文中一共展示了TreeMap.tailMap方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: route
import java.util.TreeMap; //導入方法依賴的package包/類
public String route(int jobId, ArrayList<String> addressList) {
// ------A1------A2-------A3------
// -----------J1------------------
TreeMap<Long, String> addressRing = new TreeMap<Long, String>();
for (String address: addressList) {
for (int i = 0; i < VIRTUAL_NODE_NUM; i++) {
long addressHash = hash("SHARD-" + address + "-NODE-" + i);
addressRing.put(addressHash, address);
}
}
long jobHash = hash(String.valueOf(jobId));
SortedMap<Long, String> lastRing = addressRing.tailMap(jobHash);
if (!lastRing.isEmpty()) {
return lastRing.get(lastRing.firstKey());
}
return addressRing.firstEntry().getValue();
}
示例2: getMatchingRequests
import java.util.TreeMap; //導入方法依賴的package包/類
@Override
public synchronized List<? extends Collection<T>> getMatchingRequests(
Priority priority,
String resourceName,
Resource capability) {
Preconditions.checkArgument(capability != null,
"The Resource to be requested should not be null ");
Preconditions.checkArgument(priority != null,
"The priority at which to request containers should not be null ");
List<LinkedHashSet<T>> list = new LinkedList<LinkedHashSet<T>>();
Map<String, TreeMap<Resource, ResourceRequestInfo>> remoteRequests =
this.remoteRequestsTable.get(priority);
if (remoteRequests == null) {
return list;
}
TreeMap<Resource, ResourceRequestInfo> reqMap = remoteRequests
.get(resourceName);
if (reqMap == null) {
return list;
}
ResourceRequestInfo resourceRequestInfo = reqMap.get(capability);
if (resourceRequestInfo != null &&
!resourceRequestInfo.containerRequests.isEmpty()) {
list.add(resourceRequestInfo.containerRequests);
return list;
}
// no exact match. Container may be larger than what was requested.
// get all resources <= capability. map is reverse sorted.
SortedMap<Resource, ResourceRequestInfo> tailMap =
reqMap.tailMap(capability);
for(Map.Entry<Resource, ResourceRequestInfo> entry : tailMap.entrySet()) {
if (canFit(entry.getKey(), capability) &&
!entry.getValue().containerRequests.isEmpty()) {
// match found that fits in the larger resource
list.add(entry.getValue().containerRequests);
}
}
// no match found
return list;
}
示例3: testTailMapContents
import java.util.TreeMap; //導入方法依賴的package包/類
/**
* headMap returns map with keys in requested range
*/
public void testTailMapContents() {
TreeMap map = map5();
NavigableMap sm = map.tailMap(two, true);
assertFalse(sm.containsKey(one));
assertTrue(sm.containsKey(two));
assertTrue(sm.containsKey(three));
assertTrue(sm.containsKey(four));
assertTrue(sm.containsKey(five));
Iterator i = sm.keySet().iterator();
Object k;
k = (Integer)(i.next());
assertEquals(two, k);
k = (Integer)(i.next());
assertEquals(three, k);
k = (Integer)(i.next());
assertEquals(four, k);
k = (Integer)(i.next());
assertEquals(five, k);
assertFalse(i.hasNext());
Iterator r = sm.descendingKeySet().iterator();
k = (Integer)(r.next());
assertEquals(five, k);
k = (Integer)(r.next());
assertEquals(four, k);
k = (Integer)(r.next());
assertEquals(three, k);
k = (Integer)(r.next());
assertEquals(two, k);
assertFalse(r.hasNext());
Iterator ei = sm.entrySet().iterator();
Map.Entry e;
e = (Map.Entry)(ei.next());
assertEquals(two, e.getKey());
assertEquals("B", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(three, e.getKey());
assertEquals("C", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(four, e.getKey());
assertEquals("D", e.getValue());
e = (Map.Entry)(ei.next());
assertEquals(five, e.getKey());
assertEquals("E", e.getValue());
assertFalse(i.hasNext());
NavigableMap ssm = sm.tailMap(four, true);
assertEquals(four, ssm.firstKey());
assertEquals(five, ssm.lastKey());
assertEquals("D", ssm.remove(four));
assertEquals(1, ssm.size());
assertEquals(3, sm.size());
assertEquals(4, map.size());
}
示例4: map0
import java.util.TreeMap; //導入方法依賴的package包/類
private static NavigableMap map0() {
TreeMap map = new TreeMap();
assertTrue(map.isEmpty());
return map.tailMap(one, true);
}