當前位置: 首頁>>代碼示例>>Java>>正文


Java NavigableMap.subMap方法代碼示例

本文整理匯總了Java中java.util.NavigableMap.subMap方法的典型用法代碼示例。如果您正苦於以下問題:Java NavigableMap.subMap方法的具體用法?Java NavigableMap.subMap怎麽用?Java NavigableMap.subMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.NavigableMap的用法示例。


在下文中一共展示了NavigableMap.subMap方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: markDeepChildrenActive

import java.util.NavigableMap; //導入方法依賴的package包/類
/**
 * Sets outlines of all children to 'active'. Assuming yFrom and yTo are from-to Y-coordinates of the parent
 * fold, it finds all nested folds (folds, which are in between yFrom and yTo) and changes their in/out lines
 * as active.
 * The method returns Y start coordinate of the 1st child found.
 * 
 * @param infos fold infos collected so far
 * @param yFrom upper Y-coordinate of the parent fold
 * @param yTo lower Y-coordinate of the parent fold
 * @param level level of the parent fold
 * @return Y-coordinate of the 1st child.
 */
private int markDeepChildrenActive(NavigableMap<Integer, PaintInfo> infos, int yFrom, int yTo, int level) {
    int result = Integer.MAX_VALUE;
    Map<Integer, PaintInfo> m = infos.subMap(yFrom, yTo);
    for (Map.Entry<Integer, PaintInfo> me : m.entrySet()) {
        PaintInfo pi = me.getValue();
        int y = pi.getPaintY();
        if (y > yFrom && y < yTo) {
            if (LOG.isLoggable(Level.FINEST)) {
                LOG.log(Level.FINEST, "Marking chind as active: {0}", pi);
            }
            pi.markActive(false, true, true);
            if (y < result) {
                y = result;
            }
        }
    }
    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:CodeFoldingSideBar.java

示例2: subMap

import java.util.NavigableMap; //導入方法依賴的package包/類
/**
 * Returns a view of the portion of {@code map} whose keys are contained by {@code range}.
 *
 * <p>This method delegates to the appropriate methods of {@link NavigableMap} (namely
 * {@link NavigableMap#subMap(Object, boolean, Object, boolean) subMap()},
 * {@link NavigableMap#tailMap(Object, boolean) tailMap()}, and
 * {@link NavigableMap#headMap(Object, boolean) headMap()}) to actually construct the view.
 * Consult these methods for a full description of the returned view's behavior.
 *
 * <p><b>Warning:</b> {@code Range}s always represent a range of values using the values' natural
 * ordering. {@code NavigableMap} on the other hand can specify a custom ordering via a
 * {@link Comparator}, which can violate the natural ordering. Using this method (or in general
 * using {@code Range}) with unnaturally-ordered maps can lead to unexpected and undefined
 * behavior.
 *
 * @since 20.0
 */
@Beta
@GwtIncompatible // NavigableMap
public static <K extends Comparable<? super K>, V> NavigableMap<K, V> subMap(
    NavigableMap<K, V> map, Range<K> range) {
  if (map.comparator() != null
      && map.comparator() != Ordering.natural()
      && range.hasLowerBound()
      && range.hasUpperBound()) {
    checkArgument(
        map.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0,
        "map is using a custom comparator which is inconsistent with the natural ordering.");
  }
  if (range.hasLowerBound() && range.hasUpperBound()) {
    return map.subMap(
        range.lowerEndpoint(),
        range.lowerBoundType() == BoundType.CLOSED,
        range.upperEndpoint(),
        range.upperBoundType() == BoundType.CLOSED);
  } else if (range.hasLowerBound()) {
    return map.tailMap(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED);
  } else if (range.hasUpperBound()) {
    return map.headMap(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED);
  }
  return checkNotNull(map);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:43,代碼來源:Maps.java

示例3: createSubMap

import java.util.NavigableMap; //導入方法依賴的package包/類
@Override
NavigableMap<K, V> createSubMap(SortedMap<K, V> sortedMap, K firstExclusive, K lastExclusive) {
  NavigableMap<K, V> map = (NavigableMap<K, V>) sortedMap;
  if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) {
    return map.headMap(lastInclusive, true);
  } else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) {
    return map.tailMap(firstExclusive, false);
  } else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) {
    return map.subMap(firstExclusive, false, lastExclusive, false);
  } else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) {
    return map.subMap(firstExclusive, false, lastInclusive, true);
  } else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) {
    return map.subMap(firstInclusive, true, lastInclusive, true);
  } else {
    return (NavigableMap<K, V>) super.createSubMap(map, firstExclusive, lastExclusive);
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:NavigableMapTestSuiteBuilder.java

示例4: testSubMapRanges

import java.util.NavigableMap; //導入方法依賴的package包/類
@Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class)
public void testSubMapRanges(String description, NavigableMap navigableMap) {
    Object first = isDescending(navigableMap) ? BigInteger.TEN : BigInteger.ZERO;
    Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;

    NavigableMap subMap = navigableMap.subMap(first, true, last, true);

    // same subset
    subMap.subMap(first, true, last, true);

    // slightly smaller
    NavigableMap ns = subMap.subMap(first, false, last, false);
    // slight exapansion
    assertThrows(() -> {
        ns.subMap(first, true, last, true);
    },
        IllegalArgumentException.class,
        description + ": Expansion should not be allowed");

    // much smaller
    subMap.subMap(first, false, BigInteger.ONE, false);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:EmptyNavigableMap.java

示例5: testSubMapRanges

import java.util.NavigableMap; //導入方法依賴的package包/類
@Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class)
public void testSubMapRanges(String description, NavigableMap navigableMap) {
    Object first = isDescending(navigableMap) ? BigInteger.TEN : BigInteger.ZERO;
    Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;

    NavigableMap subMap = navigableMap.subMap(first, true, last, true);

    // same subset
    subMap.subMap(first, true, last, true);

    // slightly smaller
    NavigableMap ns = subMap.subMap(first, false, last, false);
    // slight expansion
    assertThrowsIAE(() -> {
        ns.subMap(first, true, last, true);
    },
        description + ": Expansion should not be allowed");

    // much smaller
    subMap.subMap(first, false, BigInteger.ONE, false);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:EmptyNavigableMap.java

示例6: testSubMapContents2

import java.util.NavigableMap; //導入方法依賴的package包/類
public void testSubMapContents2() {
    NavigableMap map = map5();
    SortedMap sm = map.subMap(two, three);
    assertEquals(1, sm.size());
    assertEquals(two, sm.firstKey());
    assertEquals(two, sm.lastKey());
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertFalse(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    assertFalse(i.hasNext());
    Iterator j = sm.keySet().iterator();
    j.next();
    j.remove();
    assertFalse(map.containsKey(two));
    assertEquals(4, map.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertSame(sm.remove(three), null);
    assertEquals(4, map.size());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:TreeSubMapTest.java

示例7: testDescendingSubMapContents2

import java.util.NavigableMap; //導入方法依賴的package包/類
public void testDescendingSubMapContents2() {
    NavigableMap map = dmap5();
    SortedMap sm = map.subMap(m2, m3);
    assertEquals(1, sm.size());
    assertEquals(m2, sm.firstKey());
    assertEquals(m2, sm.lastKey());
    assertFalse(sm.containsKey(m1));
    assertTrue(sm.containsKey(m2));
    assertFalse(sm.containsKey(m3));
    assertFalse(sm.containsKey(m4));
    assertFalse(sm.containsKey(m5));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(m2, k);
    assertFalse(i.hasNext());
    Iterator j = sm.keySet().iterator();
    j.next();
    j.remove();
    assertFalse(map.containsKey(m2));
    assertEquals(4, map.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertSame(sm.remove(m3), null);
    assertEquals(4, map.size());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:TreeSubMapTest.java

示例8: testSubMap_K_B_K_B

import java.util.NavigableMap; //導入方法依賴的package包/類
public void testSubMap_K_B_K_B() {
  NavigableMap<String, Integer> map = create();
  NavigableMap<String, Integer> subMap = map.subMap("a", true, "b", false);
  assertTrue(subMap instanceof SynchronizedNavigableMap);
  assertSame(
      mutex, ((SynchronizedNavigableMap<String, Integer>) subMap).mutex);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:8,代碼來源:SynchronizedNavigableMapTest.java

示例9: testSubMapContents

import java.util.NavigableMap; //導入方法依賴的package包/類
/**
 * subMap returns map with keys in requested range
 */
public void testSubMapContents() {
    NavigableMap map = map5();
    SortedMap sm = map.subMap(two, four);
    assertEquals(two, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals(2, sm.size());
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    Iterator j = sm.keySet().iterator();
    j.next();
    j.remove();
    assertFalse(map.containsKey(two));
    assertEquals(4, map.size());
    assertEquals(1, sm.size());
    assertEquals(three, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals("C", sm.remove(three));
    assertTrue(sm.isEmpty());
    assertEquals(3, map.size());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:TreeSubMapTest.java

示例10: testDescendingSubMapContents

import java.util.NavigableMap; //導入方法依賴的package包/類
/**
 * subMap returns map with keys in requested range
 */
public void testDescendingSubMapContents() {
    NavigableMap map = dmap5();
    SortedMap sm = map.subMap(m2, m4);
    assertEquals(m2, sm.firstKey());
    assertEquals(m3, sm.lastKey());
    assertEquals(2, sm.size());
    assertFalse(sm.containsKey(m1));
    assertTrue(sm.containsKey(m2));
    assertTrue(sm.containsKey(m3));
    assertFalse(sm.containsKey(m4));
    assertFalse(sm.containsKey(m5));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(m2, k);
    k = (Integer)(i.next());
    assertEquals(m3, k);
    assertFalse(i.hasNext());
    Iterator j = sm.keySet().iterator();
    j.next();
    j.remove();
    assertFalse(map.containsKey(m2));
    assertEquals(4, map.size());
    assertEquals(1, sm.size());
    assertEquals(m3, sm.firstKey());
    assertEquals(m3, sm.lastKey());
    assertEquals("C", sm.remove(m3));
    assertTrue(sm.isEmpty());
    assertEquals(3, map.size());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:TreeSubMapTest.java

示例11: testAsMapNavigableReadsThrough

import java.util.NavigableMap; //導入方法依賴的package包/類
@GwtIncompatible // NavigableMap
public void testAsMapNavigableReadsThrough() {
  NavigableSet<String> strings = Sets.newTreeSet();
  Collections.addAll(strings, "one", "two", "three");
  NavigableMap<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();

  NavigableMap<String, Integer> tailMap = map.tailMap("s", true);
  NavigableMap<String, Integer> subMap = map.subMap("a", true, "t", false);

  strings.add("six");
  strings.remove("two");
  assertThat(tailMap.entrySet()).containsExactly(
      mapEntry("six", 3),
      mapEntry("three", 5)).inOrder();
  assertThat(subMap.entrySet()).containsExactly(
      mapEntry("five", 4),
      mapEntry("four", 4),
      mapEntry("six", 3)).inOrder();
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:42,代碼來源:MapsTest.java

示例12: testSubMap_K_K

import java.util.NavigableMap; //導入方法依賴的package包/類
public void testSubMap_K_K() {
  NavigableMap<String, Integer> map = create();
  SortedMap<String, Integer> subMap = map.subMap("a", "b");
  assertTrue(subMap instanceof SynchronizedSortedMap);
  assertSame(mutex, ((SynchronizedSortedMap<String, Integer>) subMap).mutex);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:7,代碼來源:SynchronizedNavigableMapTest.java


注:本文中的java.util.NavigableMap.subMap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。