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


Java SortedMap.headMap方法代码示例

本文整理汇总了Java中java.util.SortedMap.headMap方法的典型用法代码示例。如果您正苦于以下问题:Java SortedMap.headMap方法的具体用法?Java SortedMap.headMap怎么用?Java SortedMap.headMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.SortedMap的用法示例。


在下文中一共展示了SortedMap.headMap方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testHeadMap

import java.util.SortedMap; //导入方法依赖的package包/类
@Test
public void testHeadMap() throws Exception {
    for (int i = 0; i < 100; i++) {
        map.put(i, String.valueOf(i));
    }
    SortedMap<Integer, String> headMap = map.headMap(74);
    Assert.assertEquals(74, headMap.size());
    for (int i = 0; i < 74; i++) {
        Assert.assertTrue(headMap.containsKey(i));
    }
    Assert.assertFalse(headMap.containsKey(74));

    SortedMap<Integer, String> headHeadMap = headMap.headMap(53);
    Assert.assertEquals(53, headHeadMap.size());
    for (int i = 0; i < 53; i++) {
        Assert.assertTrue(headHeadMap.containsKey(i));
    }
    Assert.assertFalse(headHeadMap.containsKey(53));

}
 
开发者ID:MottoX,项目名称:SkipList,代码行数:21,代码来源:SkipListMapTest.java

示例2: getRangeMap

import java.util.SortedMap; //导入方法依赖的package包/类
public static SortedMap<IMKey, RegionEntry> getRangeMap(
    final SortedMap<IMKey, RegionEntry> rowMap, final IMKey startRow, final IMKey stopRow,
    final boolean includeStartRow) {
  SortedMap<IMKey, RegionEntry> result;
  if (startRow == null && stopRow == null) {
    result = rowMap;
  } else if (startRow == null) {
    // result = rowMap.headMap(stopRow, false);
    result = rowMap instanceof NavigableMap
        ? ((NavigableMap<IMKey, RegionEntry>) rowMap).headMap(stopRow, false)
        : rowMap.headMap(stopRow);
  } else if (stopRow == null) {
    // result = rowMap.tailMap(startRow, includeStartRow);
    result = rowMap instanceof NavigableMap
        ? ((NavigableMap<IMKey, RegionEntry>) rowMap).tailMap(startRow, includeStartRow)
        : rowMap.tailMap(startRow);
  } else {
    // result = rowMap.subMap(startRow, includeStartRow, stopRow, false);
    result = subMap(rowMap, startRow, includeStartRow, stopRow, false);
  }
  return result;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:ScanUtils.java

示例3: doMetaGetResponse

import java.util.SortedMap; //导入方法依赖的package包/类
static GetResponse doMetaGetResponse(final SortedMap<byte [], Pair<HRegionInfo, ServerName>> meta,
    final GetRequest request) {
  ClientProtos.Result.Builder resultBuilder = ClientProtos.Result.newBuilder();
  ByteString row = request.getGet().getRow();
  Pair<HRegionInfo, ServerName> p = meta.get(row.toByteArray());
  if (p == null) {
    if (request.getGet().getClosestRowBefore()) {
      byte [] bytes = row.toByteArray();
      SortedMap<byte [], Pair<HRegionInfo, ServerName>> head =
        bytes != null? meta.headMap(bytes): meta;
      p = head == null? null: head.get(head.lastKey());
    }
  }
  if (p != null) {
    resultBuilder.addCell(getRegionInfo(row, p.getFirst()));
    resultBuilder.addCell(getServer(row, p.getSecond()));
  }
  resultBuilder.addCell(getStartCode(row));
  GetResponse.Builder builder = GetResponse.newBuilder();
  builder.setResult(resultBuilder.build());
  return builder.build();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:23,代码来源:TestClientNoCluster.java

示例4: computeBackingRowMap

import java.util.SortedMap; //导入方法依赖的package包/类
@Override
SortedMap<C, V> computeBackingRowMap() {
  SortedMap<C, V> map = wholeRow();
  if (map != null) {
    if (lowerBound != null) {
      map = map.tailMap(lowerBound);
    }
    if (upperBound != null) {
      map = map.headMap(upperBound);
    }
    return map;
  }
  return null;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:15,代码来源:TreeBasedTable.java

示例5: createSubMap

import java.util.SortedMap; //导入方法依赖的package包/类
/**
 * Calls the smallest subMap overload that filters out the extreme values. This method is
 * overridden in NavigableMapTestSuiteBuilder.
 */
SortedMap<K, V> createSubMap(SortedMap<K, V> map, K firstExclusive, K lastExclusive) {
  if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
    return map.headMap(lastExclusive);
  } else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
    return map.tailMap(firstInclusive);
  } else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
    return map.subMap(firstInclusive, lastExclusive);
  } else {
    throw new IllegalArgumentException();
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:DerivedCollectionGenerators.java

示例6: testAsMapSortedReadsThrough

import java.util.SortedMap; //导入方法依赖的package包/类
public void testAsMapSortedReadsThrough() {
  SortedSet<String> strings = new NonNavigableSortedSet();
  Collections.addAll(strings, "one", "two", "three");
  SortedMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION);
  assertNull(map.comparator());
  assertEquals(ImmutableSortedMap.of("one", 3, "two", 3, "three", 5), map);
  assertNull(map.get("four"));
  strings.add("four");
  assertEquals(
      ImmutableSortedMap.of("one", 3, "two", 3, "three", 5, "four", 4),
      map);
  assertEquals(Integer.valueOf(4), map.get("four"));
  SortedMap<String, Integer> headMap = map.headMap("two");
  assertEquals(
      ImmutableSortedMap.of("four", 4, "one", 3, "three", 5),
      headMap);
  strings.add("five");
  strings.remove("one");
  assertEquals(
      ImmutableSortedMap.of("five", 4, "four", 4, "three", 5),
      headMap);
  assertThat(map.entrySet()).containsExactly(
      mapEntry("five", 4),
      mapEntry("four", 4),
      mapEntry("three", 5),
      mapEntry("two", 3)).inOrder();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:28,代码来源:MapsTest.java

示例7: previousQuestion

import java.util.SortedMap; //导入方法依赖的package包/类
private ActionForward previousQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) {
AnswerForm answerForm = (AnswerForm) form;
Integer questionSeqID = answerForm.getQuestionSeqID();
String sessionMapID = answerForm.getSessionMapID();

SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
SortedMap<Integer, AnswerDTO> surveyItemMap = getQuestionList(sessionMap);

ActionErrors errors = getAnswer(request, surveyItemMap.get(questionSeqID));
if (!errors.isEmpty()) {
    return mapping.getInputForward();
}

SortedMap<Integer, AnswerDTO> subMap = surveyItemMap.headMap(questionSeqID);
if (subMap.isEmpty()) {
    questionSeqID = surveyItemMap.firstKey();
} else {
    questionSeqID = subMap.lastKey();
}

// get current question index of total questions
int currIdx = new ArrayList<Integer>(surveyItemMap.keySet()).indexOf(questionSeqID) + 1;
answerForm.setCurrentIdx(currIdx);

if (questionSeqID.equals(surveyItemMap.firstKey())) {
    answerForm.setPosition(SurveyConstants.POSITION_FIRST);
} else {
    answerForm.setPosition(SurveyConstants.POSITION_INSIDE);
}
answerForm.setQuestionSeqID(questionSeqID);
return mapping.findForward(SurveyConstants.SUCCESS);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:LearningAction.java

示例8: addEdge

import java.util.SortedMap; //导入方法依赖的package包/类
/**
 * Add an edge to this graph.
 * 
 * @param timestamp
 * @param edgeName
 * @param source
 * @param dest
 * @param isFromPattern
 */
public void addEdge(long timestamp, String edgeName, String state, String source, String dest,
    boolean isFromPattern) {

  Vertex destVertex = new Vertex(this, dest, state, timestamp);
  SortedMap<Long, Vertex> map = this.indexedVertices.get(dest);
  if (map == null) {
    map = new TreeMap<Long, Vertex>();
    this.indexedVertices.put(dest, map);
  }

  // If this edge is being added by a pattern event, only
  // add the edge if the destination changes state as a result
  // of this edge. This cuts down on noise in the graph.
  if (isFromPattern) {
    SortedMap<Long, Vertex> headMap = map.headMap(timestamp);
    if (headMap != null && !headMap.isEmpty()) {
      Long previousKey = headMap.lastKey();
      Vertex previousVertex = headMap.get(previousKey);
      if (previousVertex.getState().equals(state)) {
        return;
      }
    } else {
      // Super hack here. Don't add a transition from the non existent state to
      // the destroyed state in a lifeline.
      if (state.equals("destroyed")) {
        return;
      }
    }
  }
  map.put(timestamp, destVertex);

  edges.add(new Edge(this, timestamp, edgeName, source, destVertex));
}
 
开发者ID:ampool,项目名称:monarch,代码行数:43,代码来源:Graph.java

示例9: getSource

import java.util.SortedMap; //导入方法依赖的package包/类
public Vertex getSource() {
  SortedMap<Long, Vertex> sourceMap = graph.getIndexedVertices().get(source);
  if (sourceMap == null) {
    return null;
  }
  SortedMap<Long, Vertex> headMap = sourceMap.headMap(dest.getTimestamp() + 1);
  if (headMap.isEmpty()) {
    return null;
  }
  Long closestTimestamp = headMap.lastKey();
  return headMap.get(closestTimestamp);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:13,代码来源:Edge.java

示例10: previousKey

import java.util.SortedMap; //导入方法依赖的package包/类
@Override
public K previousKey(final K key) {
    if (isEmpty()) {
        return null;
    }
    if (normalMap instanceof OrderedMap) {
        return ((OrderedMap<K, V>) normalMap).previousKey(key);
    }
    final SortedMap<K, V> sm = (SortedMap<K, V>) normalMap;
    final SortedMap<K, V> hm = sm.headMap(key);
    if (hm.isEmpty()) {
        return null;
    }
    return hm.lastKey();
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:16,代码来源:DualTreeBidiMap.java


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