当前位置: 首页>>代码示例>>Java>>正文


Java TreeMap.tailMap方法代码示例

本文整理汇总了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();
    }
 
开发者ID:mmwhd,项目名称:stage-job,代码行数:20,代码来源:ExecutorRouteConsistentHash.java

示例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;          
}
 
开发者ID:naver,项目名称:hadoop,代码行数:44,代码来源:AMRMClientImpl.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:TreeMapTest.java

示例4: map0

import java.util.TreeMap; //导入方法依赖的package包/类
private static NavigableMap map0() {
    TreeMap map = new TreeMap();
    assertTrue(map.isEmpty());
    return map.tailMap(one, true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TreeSubMapTest.java


注:本文中的java.util.TreeMap.tailMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。