本文整理了Java中java.util.stream.Stream.skip()
方法的一些代码示例,展示了Stream.skip()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stream.skip()
方法的具体详情如下:
包路径:java.util.stream.Stream
类名称:Stream
方法名:skip
[英]Returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream. If this stream contains fewer than n elements then an empty stream will be returned.
This is a stateful intermediate operation.
[中]在丢弃流的前n个元素后,返回由该流的其余元素组成的流。如果此流包含少于n个元素,则将返回一个空流。
这是一个stateful intermediate operation。
代码示例来源:origin: apache/storm
/**
* Drop the first N elements and create a new list.
*
* @param list the list
* @param count element count to drop
* @return newly created sublist that drops the first N elements from origin list. null if list is null.
*/
public static <T> List<T> drop(List<T> list, int count) {
if (list == null) {
return null;
}
return list.stream()
.skip(count)
.collect(Collectors.toList());
}
代码示例来源:origin: google/guava
@Override
public Spliterator<T> spliterator() {
if (iterable instanceof List) {
final List<T> list = (List<T>) iterable;
int toSkip = Math.min(list.size(), numberToSkip);
return list.subList(toSkip, list.size()).spliterator();
} else {
return Streams.stream(iterable).skip(numberToSkip).spliterator();
}
}
};
代码示例来源:origin: Vedenin/useful-java-links
private static void testLimit() {
System.out.println();
System.out.println("Test limit start");
Collection<String> collection = Arrays.asList("a1", "a2", "a3", "a1");
// Get the first two elements
List<String> limit = collection.stream().limit(2).collect(Collectors.toList());
System.out.println("limit = " + limit); // print limit = [a1, a2]
// Get two elements from second element
List<String> fromTo = collection.stream().skip(1).limit(2).collect(Collectors.toList());
System.out.println("fromTo = " + fromTo); // print fromTo = [a2, a3]
// Get the last element
String last = collection.stream().skip(collection.size() - 1).findAny().orElse("1");
System.out.println("last = " + last ); // print last = a1
}
代码示例来源:origin: yu199195/hmily
private List<HmilyCompensationVO> findByPage(final List<String> zNodePaths, final String rootPath,
final int start, final int pageSize) {
return zNodePaths.stream()
.skip(start)
.limit(pageSize)
.filter(StringUtils::isNoneBlank)
.map(zNodePath -> buildByNodePath(rootPath, zNodePath))
.collect(Collectors.toList());
}
代码示例来源:origin: prestodb/presto
@Override
public Spliterator<T> spliterator() {
if (iterable instanceof List) {
final List<T> list = (List<T>) iterable;
int toSkip = Math.min(list.size(), numberToSkip);
return list.subList(toSkip, list.size()).spliterator();
} else {
return Streams.stream(iterable).skip(numberToSkip).spliterator();
}
}
};
代码示例来源:origin: SonarSource/sonarqube
private static List<ComponentDto> paginateComponents(List<ComponentDto> components, Request wsRequest) {
return components.stream().skip(offset(wsRequest.getPage(), wsRequest.getPageSize()))
.limit(wsRequest.getPageSize()).collect(toList());
}
代码示例来源:origin: apache/incubator-druid
@Override
public Expr apply(final List<Expr> args)
{
if (args.size() < 2 || args.size() > 4) {
throw new IAE("Function[%s] must have 2 to 4 arguments", name());
}
if (args.stream().skip(1).allMatch(Expr::isLiteral)) {
return new TimestampFloorExpr(args);
} else {
return new TimestampFloorDynamicExpr(args);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public Expr apply(final List<Expr> args)
{
if (args.size() < 2 || args.size() > 4) {
throw new IAE("Function[%s] must have 2 to 4 arguments", name());
}
if (args.stream().skip(1).allMatch(Expr::isLiteral)) {
return new TimestampCeilExpr(args);
} else {
return new TimestampCeilDynamicExpr(args);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public Expr apply(final List<Expr> args)
{
if (args.size() < 3 || args.size() > 4) {
throw new IAE("Function[%s] must have 3 to 4 arguments", name());
}
if (args.stream().skip(1).allMatch(Expr::isLiteral)) {
return new TimestampShiftExpr(args);
} else {
// Use dynamic impl if any args are non-literal. Don't bother optimizing for the case where period is
// literal but step isn't.
return new TimestampShiftDynamicExpr(args);
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public Spliterator<T> spliterator() {
if (iterable instanceof List) {
final List<T> list = (List<T>) iterable;
int toSkip = Math.min(list.size(), numberToSkip);
return list.subList(toSkip, list.size()).spliterator();
} else {
return Streams.stream(iterable).skip(numberToSkip).spliterator();
}
}
};
代码示例来源:origin: SonarSource/sonarqube
private static List<ProjectQgateAssociationDto> getPaginatedProjects(List<ProjectQgateAssociationDto> projects, Paging paging) {
return projects.stream().skip(paging.offset()).limit(paging.pageSize()).collect(MoreCollectors.toList());
}
代码示例来源:origin: SonarSource/sonarqube
private void filterByCategory() {
ListMultimap<String, String> eventCategoriesByAnalysisUuid = events.stream()
.collect(MoreCollectors.index(EventDto::getAnalysisUuid, EventDto::getCategory));
Predicate<SnapshotDto> byCategory = a -> eventCategoriesByAnalysisUuid.get(a.getUuid()).contains(request.getCategory().getLabel());
this.countAnalyses = (int) analyses.stream().filter(byCategory).count();
this.analyses = analyses.stream()
.filter(byCategory)
.skip(Paging.offset(request.getPage(), request.getPageSize()))
.limit(request.getPageSize())
.collect(MoreCollectors.toList());
}
代码示例来源:origin: ctripcorp/apollo
@Override
public List<UserInfo> findByUserIds(List<String> userIds) {
if (CollectionUtils.isEmpty(userIds)) {
return null;
} else {
ContainerCriteria criteria = query().where(loginIdAttrName).is(userIds.get(0));
userIds.stream().skip(1).forEach(userId -> criteria.or(loginIdAttrName).is(userId));
return ldapTemplate.search(ldapQueryCriteria().and(criteria), ldapUserInfoMapper);
}
}
代码示例来源:origin: SonarSource/sonarqube
public List<Integer> selectUserIdsByQuery(DbSession dbSession, PermissionQuery query) {
return mapper(dbSession).selectUserIdsByQuery(query)
.stream()
// Pagination is done in Java because it's too complex to use SQL pagination in Oracle and MsSQL with the distinct
.skip(query.getPageOffset())
.limit(query.getPageSize())
.collect(MoreCollectors.toArrayList());
}
代码示例来源:origin: SonarSource/sonarqube
Builder setAnalyses(List<SnapshotDto> analyses) {
Stream<SnapshotDto> stream = analyses.stream();
// no filter by category, the pagination can be applied
if (request.getCategory() == null) {
stream = stream
.skip(Paging.offset(request.getPage(), request.getPageSize()))
.limit(request.getPageSize());
}
this.analyses = stream.collect(MoreCollectors.toList());
this.countAnalyses = analyses.size();
return this;
}
代码示例来源:origin: SonarSource/sonarqube
private static List<ComponentDto> paginateComponents(List<ComponentDto> components, ComponentTreeRequest wsRequest) {
return components.stream()
.skip(offset(wsRequest.getPage(), wsRequest.getPageSize()))
.limit(wsRequest.getPageSize())
.collect(MoreCollectors.toList(wsRequest.getPageSize()));
}
代码示例来源:origin: SonarSource/sonarqube
SearchHistoryResult setAnalyses(List<SnapshotDto> analyses) {
this.paging = Common.Paging.newBuilder().setPageIndex(page).setPageSize(pageSize).setTotal(analyses.size()).build();
this.analyses = analyses.stream().skip(offset(page, pageSize)).limit(pageSize).collect(MoreCollectors.toList());
return this;
}
代码示例来源:origin: SonarSource/sonarqube
private SearchResults toSearchResults(SearchRequest request) {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
List<ComponentDto> authorizedFavorites = getAuthorizedFavorites();
Paging paging = Paging.forPageIndex(Integer.parseInt(request.getP())).withPageSize(Integer.parseInt(request.getPs())).andTotal(authorizedFavorites.size());
List<ComponentDto> displayedFavorites = authorizedFavorites.stream()
.skip(paging.offset())
.limit(paging.pageSize())
.collect(MoreCollectors.toList());
Map<String, OrganizationDto> organizationsByUuid = getOrganizationsOfComponents(dbSession, displayedFavorites);
return new SearchResults(paging, displayedFavorites, organizationsByUuid);
}
}
代码示例来源:origin: ctripcorp/apollo
private ContainerCriteria ldapQueryCriteria() {
ContainerCriteria criteria = query()
.searchScope(SearchScope.SUBTREE)
.where("objectClass").is(objectClassAttrName);
if (memberOf.length > 0 && !StringUtils.isEmpty(memberOf[0])) {
ContainerCriteria memberOfFilters = query().where(MEMBER_OF_ATTR_NAME).is(memberOf[0]);
Arrays.stream(memberOf).skip(1)
.forEach(filter -> memberOfFilters.or(MEMBER_OF_ATTR_NAME).is(filter));
criteria.and(memberOfFilters);
}
return criteria;
}
代码示例来源:origin: resilience4j/resilience4j
@Test
public void testRingBitSetWithSlightlyLessCapacity() {
RingBitSet ringBitSet = new RingBitSet(100);
long expectedCardinality = Stream.generate(ThreadLocalRandom.current()::nextBoolean)
.limit(1000)
.peek(ringBitSet::setNextBit)
.skip(900)
.mapToInt(b -> b ? 1 : 0)
.sum();
assertThat(ringBitSet.cardinality()).isEqualTo((int) expectedCardinality);
assertThat(ringBitSet.size()).isEqualTo(128);
assertThat(ringBitSet.length()).isEqualTo(100);
}
内容来源于网络,如有侵权,请联系作者删除!