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


Java NavigableMap.tailMap方法代码示例

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


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

示例1: streamBooks

import java.util.NavigableMap; //导入方法依赖的package包/类
@Override
public synchronized void streamBooks(
    ListBooksRequest request, StreamObserver<ListBooksResponse> responseObserver) {

  NavigableMap<String, Book> cursor = booksById;

  // Resume iteration from the page token.
  if (!request.getPageToken().isEmpty()) {
    String pageToken = decodePageToken(request.getPageToken());
    cursor = cursor.tailMap(pageToken, false);
  }

  cursor
      .values()
      .stream()
      .limit(request.getPageSize() > 0 ? request.getPageSize() : DEFAULT_PAGE_SIZE)
      .forEach(
          book ->
              responseObserver.onNext(
                  ListBooksResponse.newBuilder()
                      .addBooks(book)
                      .setNextPageToken(encodePageToken(book.getId()))
                      .build()));
  responseObserver.onCompleted();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:26,代码来源:BookService.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:paul-hammant,项目名称:googles-monorepo-demo,代码行数: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: testTailMapRanges

import java.util.NavigableMap; //导入方法依赖的package包/类
@Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class)
public void testTailMapRanges(String description, NavigableMap navigableMap) {
    NavigableMap subMap = navigableMap.tailMap(BigInteger.ONE, true);

    // same subset
    subMap.tailMap(BigInteger.ONE, true);

    // slightly smaller
    NavigableMap ns = subMap.tailMap(BigInteger.ONE, false);

    // slight exapansion
    assertThrows(() -> {
        ns.tailMap(BigInteger.ONE, true);
    },
        IllegalArgumentException.class,
        description + ": Expansion should not be allowed");

    // much smaller
    subMap.tailMap(isDescending(subMap) ? BigInteger.ZERO : BigInteger.TEN, false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:EmptyNavigableMap.java

示例5: testTailMap

import java.util.NavigableMap; //导入方法依赖的package包/类
/**
 * Tests the tailMap() method.
 */
@Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class)
public void testTailMap(String description, NavigableMap navigableMap) {
    assertThrowsNPE(() -> {
        navigableMap.tailMap(null);
    },
        description + ": Must throw NullPointerException for null element");

    assertThrowsCCE(() -> {
        navigableMap.tailMap(new Object());
    },
        description);

    NavigableMap ss = navigableMap.tailMap("1", true);

    assertEmptyNavigableMap(ss, description + ": Returned value is not empty navigable set.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:EmptyNavigableMap.java

示例6: matchExtensions

import java.util.NavigableMap; //导入方法依赖的package包/类
/**
 * Match a set of strings of new types to be imported against the set of existing extensions
 * based on package names and type names. This method returns a set of old extensions that
 * are a subset of the new types based on the type names. For example, if you have an old
 * extension com.foo.Bar and you import a new extension that is package name com.foo, then we
 * will need to check that com.foo.Bar is inside com.foo and, if so, perform an upgrade.
 *
 * @param existing Existing set of extensions in the project
 * @param newTypes New type(s) defined by the extension being imported
 * @return A subset of the existing extensions that will need to be checked against the new
 * extension to determine whether we are performing an upgrade or adding a fresh extension.
 */
private static Set<String> matchExtensions(NavigableMap<String, Set<String>> existing,
    Set<String> newTypes) {
  Set<String> results = new HashSet<>();
  String packageName = getPackageName(newTypes.iterator().next());
  if (existing.containsKey(packageName)) {
    results.add(packageName);
  }
  NavigableMap<String, Set<String>> related = existing.tailMap(packageName, true);
  for (String k : related.navigableKeySet()) {
    if (!k.startsWith(packageName)) {
      break;  // no longer in the same package
    }
    results.add(k);
  }
  return results;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:29,代码来源:ComponentServiceImpl.java

示例7: listShelves

import java.util.NavigableMap; //导入方法依赖的package包/类
@Override
public synchronized void listShelves(
    ListShelvesRequest request, StreamObserver<ListShelvesResponse> responseObserver) {
  NavigableMap<String, Shelf> cursor = shelfsById;

  // Resume iteration from the page token.
  if (!request.getPageToken().isEmpty()) {
    String pageToken = decodePageToken(request.getPageToken());
    cursor = cursor.tailMap(pageToken, false);
  }

  ImmutableList<Shelf> shelves =
      cursor
          .values()
          .stream()
          .limit(request.getPageSize() > 0 ? request.getPageSize() : DEFAULT_PAGE_SIZE)
          .collect(ImmutableList.toImmutableList());

  // Return one page of results.
  ListShelvesResponse.Builder responseBuilder =
      ListShelvesResponse.newBuilder().addAllShelves(shelves);
  // Set next page token to resume iteration in the next request.
  if (cursor.values().size() > shelves.size()) {
    String nextPageToken = encodePageToken(shelves.get(shelves.size() - 1).getId());
    responseBuilder.setNextPageToken(nextPageToken);
  }

  responseObserver.onNext(responseBuilder.build());
  responseObserver.onCompleted();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:31,代码来源:ShelfService.java

示例8: listBooks

import java.util.NavigableMap; //导入方法依赖的package包/类
@Override
public synchronized void listBooks(
    ListBooksRequest request, StreamObserver<ListBooksResponse> responseObserver) {
  NavigableMap<String, Book> cursor = booksById;

  // Resume iteration from the page token.
  if (!request.getPageToken().isEmpty()) {
    String pageToken = decodePageToken(request.getPageToken());
    cursor = cursor.tailMap(pageToken, false);
  }

  ImmutableList<Book> books =
      cursor
          .values()
          .stream()
          .limit(request.getPageSize() > 0 ? request.getPageSize() : DEFAULT_PAGE_SIZE)
          .collect(ImmutableList.toImmutableList());

  // Return one page of results.
  ListBooksResponse.Builder responseBuilder = ListBooksResponse.newBuilder().addAllBooks(books);
  // Set next page token to resume iteration in the next request.
  if (cursor.values().size() > books.size()) {
    String nextPageToken = encodePageToken(books.get(books.size() - 1).getId());
    responseBuilder.setNextPageToken(nextPageToken);
  }

  responseObserver.onNext(responseBuilder.build());
  responseObserver.onCompleted();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:30,代码来源:BookService.java

示例9: getRegionLocations

import java.util.NavigableMap; //导入方法依赖的package包/类
/**
 * Returns an HRegionLocationList extracted from the result.
 * @return an HRegionLocationList containing all locations for the region range or null if
 *  we can't deserialize the result.
 */
public static RegionLocations getRegionLocations(final Result r) {
  if (r == null) return null;
  HRegionInfo regionInfo = getHRegionInfo(r, getRegionInfoColumn());
  if (regionInfo == null) return null;

  List<HRegionLocation> locations = new ArrayList<HRegionLocation>(1);
  NavigableMap<byte[],NavigableMap<byte[],byte[]>> familyMap = r.getNoVersionMap();

  locations.add(getRegionLocation(r, regionInfo, 0));

  NavigableMap<byte[], byte[]> infoMap = familyMap.get(getFamily());
  if (infoMap == null) return new RegionLocations(locations);

  // iterate until all serverName columns are seen
  int replicaId = 0;
  byte[] serverColumn = getServerColumn(replicaId);
  SortedMap<byte[], byte[]> serverMap = null;
  serverMap = infoMap.tailMap(serverColumn, false);

  if (serverMap.isEmpty()) return new RegionLocations(locations);

  for (Map.Entry<byte[], byte[]> entry : serverMap.entrySet()) {
    replicaId = parseReplicaIdFromServerColumn(entry.getKey());
    if (replicaId < 0) {
      break;
    }
    HRegionLocation location = getRegionLocation(r, regionInfo, replicaId);
    // In case the region replica is newly created, it's location might be null. We usually do not
    // have HRL's in RegionLocations object with null ServerName. They are handled as null HRLs.
    if (location == null || location.getServerName() == null) {
      locations.add(null);
    } else {
      locations.add(location);
    }
  }

  return new RegionLocations(locations);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:44,代码来源:MetaTableAccessor.java

示例10: testTailMap_K_B

import java.util.NavigableMap; //导入方法依赖的package包/类
public void testTailMap_K_B() {
  NavigableMap<String, Integer> map = create();
  NavigableMap<String, Integer> subMap = map.tailMap("a", true);
  assertTrue(subMap instanceof SynchronizedNavigableMap);
  assertSame(
      mutex, ((SynchronizedNavigableMap<String, Integer>) subMap).mutex);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:SynchronizedNavigableMapTest.java

示例11: findMatchingValues

import java.util.NavigableMap; //导入方法依赖的package包/类
private void findMatchingValues(NavigableMap<Endpoint, Integer> map, Endpoint endpoint, List<UUID> result) {
    // Mark this endpoint as a marker, because it is used to do a tailMap traversal to query matching edges
    endpoint.setMarker();
    
    // Find the first key 
    Endpoint floorKey = map.floorKey(endpoint);
    
    Map<Endpoint, Integer> view;
    if (floorKey == null) {
        // This means that the element being searched is the minimum
        view = map;
    } else {
        view = map.tailMap(floorKey);
    }
    
    boolean isFirst = true;
    for (Map.Entry<Endpoint, Integer> entry : view.entrySet()) {
        Endpoint key = entry.getKey();

        if (endpoint.isMatch(key)) {
            // Matching entry, must be added to result
            result.add(key.getEdgeId());
        } else {
            // Done with the search -- the tree map is sorted
            
            if (isFirst) {
                // continue
            } else {
                break;
            }
        }
        
        isFirst = false;
    }
}
 
开发者ID:lambdazen,项目名称:bitsy,代码行数:36,代码来源:AdjacencyMap.java

示例12: CyclicIteration

import java.util.NavigableMap; //导入方法依赖的package包/类
/** Construct an {@link Iterable} object,
 * so that an {@link Iterator} can be created  
 * for iterating the given {@link NavigableMap}.
 * The iteration begins from the starting key exclusively.
 */
public CyclicIteration(NavigableMap<K, V> navigablemap, K startingkey) {
  if (navigablemap == null || navigablemap.isEmpty()) {
    this.navigablemap = null;
    this.tailmap = null;
  }
  else {
    this.navigablemap = navigablemap;
    this.tailmap = navigablemap.tailMap(startingkey, false); 
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:CyclicIteration.java

示例13: 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

示例14: removeMatchingKeys

import java.util.NavigableMap; //导入方法依赖的package包/类
private boolean removeMatchingKeys(NavigableMap<Endpoint, Integer> map, Endpoint endpoint, Map<UUID, TreeMap<Endpoint, Integer>> otherMap, Direction dir) {
    if (map == null) {
        return false;
    }
    
    // Mark this endpoint as a marker, because it is used to do a tailMap traversal to remove matching edges
    endpoint.setMarker();
    
    // Find the first key 
    Endpoint floorKey = map.floorKey(endpoint);
    
    Map<Endpoint, Integer> view;
    if (floorKey == null) {
        // This means that the element being searched is the minimum
        view = map;
    } else {
        view = map.tailMap(floorKey);
    }
    
    Iterator<Map.Entry<Endpoint, Integer>> entryIter = view.entrySet().iterator();

    boolean isFirst = true;
    while (entryIter.hasNext()) {
        Map.Entry<Endpoint, Integer> entry = entryIter.next();
        Endpoint key = entry.getKey();
        
        if (endpoint.isMatch(key)) {
            // Remove it from this index
            entryIter.remove();
            
            // and from the underlying edge map if necessary
            if (dir != null) { // Direction is null if this is a recursive all
                // Remove the edge if the map is provided for this purpose 
                UUID edgeId = key.getEdgeId();

                IEdge edge = edgeRemover.removeEdge(edgeId);
                
                assert (edge != null);
                
                // Remove the other endpoint of this edge. NOTE: Self loops are not allowed.
                Endpoint otherEndpoint;
                UUID otherVertexId;
                if (dir == Direction.OUT) {
                    otherVertexId = edge.getInVertexId();
                    otherEndpoint = new Endpoint(key.getEdgeLabel(), key.getEdgeId());
                } else {
                    otherVertexId = edge.getOutVertexId();
                    otherEndpoint = new Endpoint(key.getEdgeLabel(), key.getEdgeId());
                }

                if (removeMatchingKeys(otherMap.get(otherVertexId), otherEndpoint, null, null)) {
                    otherMap.remove(otherVertexId);
                }
            }
        } else {
            // Done with removes -- the tree map is sorted
            if (isFirst) {
                // continue
            } else {
                break;
            }
        }
        
        isFirst = false;
    }
    
    return (map.size() == 0);
}
 
开发者ID:lambdazen,项目名称:bitsy,代码行数:69,代码来源:AdjacencyMap.java

示例15: removeInterval

import java.util.NavigableMap; //导入方法依赖的package包/类
/**
 * Removes a resource for the specified interval
 * 
 * @param reservationInterval the interval for which the resource is to be
 *          removed
 * @param capacity the resource to be removed
 * @return true if removal is successful, false otherwise
 */
public boolean removeInterval(ReservationInterval reservationInterval,
    ReservationRequest capacity) {
  Resource totCap =
      Resources.multiply(capacity.getCapability(),
          (float) capacity.getNumContainers());
  if (totCap.equals(ZERO_RESOURCE)) {
    return true;
  }
  writeLock.lock();
  try {
    long startKey = reservationInterval.getStartTime();
    long endKey = reservationInterval.getEndTime();
    // update the start key
    NavigableMap<Long, Resource> ticks =
        cumulativeCapacity.headMap(endKey, false);
    // Decrease all the capacities of overlapping intervals
    SortedMap<Long, Resource> overlapSet = ticks.tailMap(startKey);
    if (overlapSet != null && !overlapSet.isEmpty()) {
      Resource updatedCapacity = Resource.newInstance(0, 0, 0);
      long currentKey = -1;
      for (Iterator<Entry<Long, Resource>> overlapEntries =
          overlapSet.entrySet().iterator(); overlapEntries.hasNext();) {
        Entry<Long, Resource> entry = overlapEntries.next();
        currentKey = entry.getKey();
        updatedCapacity = Resources.subtract(entry.getValue(), totCap);
        // update each entry between start and end key
        cumulativeCapacity.put(currentKey, updatedCapacity);
      }
      // Remove the first overlap entry if it is same as previous after
      // updation
      Long firstKey = overlapSet.firstKey();
      if (isSameAsPrevious(firstKey, overlapSet.get(firstKey))) {
        cumulativeCapacity.remove(firstKey);
      }
      // Remove the next entry if it is same as end entry after updation
      if ((currentKey != -1) && (isSameAsNext(currentKey, updatedCapacity))) {
        cumulativeCapacity.remove(cumulativeCapacity.higherKey(currentKey));
      }
    }
    return true;
  } finally {
    writeLock.unlock();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:53,代码来源:RLESparseResourceAllocation.java


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