本文整理匯總了Java中java.util.stream.Stream.limit方法的典型用法代碼示例。如果您正苦於以下問題:Java Stream.limit方法的具體用法?Java Stream.limit怎麽用?Java Stream.limit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.stream.Stream
的用法示例。
在下文中一共展示了Stream.limit方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseArtistFile
import java.util.stream.Stream; //導入方法依賴的package包/類
private List<Artist> parseArtistFile(long size) {
List<Artist> artists = null;
//read file into stream, try-with-resources
try (Stream<String> stream = Files.lines(Paths.get(artistFilePath))) {
Stream<String[]> rows = stream.map(strRow ->
Arrays.stream(strRow.split(TAB_SYMBOL))
.map(val -> VALUE_NOT_DEFINED_SYMBOL.equals(val) ? EMPTY_STRING : val)
.toArray(String[]::new)
);
if (size > 0) {
rows = rows.limit(size);
}
artists = rows.map(this::parseArtistRow).collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
}
return artists;
}
示例2: applyLimitToResults
import java.util.stream.Stream; //導入方法依賴的package包/類
private Stream<MemgraphCypherScope.Item> applyLimitToResults(
MemgraphCypherQueryContext ctx,
Stream<MemgraphCypherScope.Item> results,
CypherLimit limitClause,
MemgraphCypherScope scope
) {
Object limitObj = ctx.getExpressionExecutor().executeExpression(ctx, limitClause.getExpression(), scope);
int limit;
if (limitObj instanceof Integer || limitObj instanceof Long) {
limit = ((Number) limitObj).intValue();
} else {
throw new MemgraphException("limit with a none integer not supported: " + limitObj);
}
if (limit < 0) {
limit = 0;
}
results = results.limit(limit);
return results;
}
示例3: build
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public void build() {
List<ExplodedGraph.Node> egNodes = new ArrayList<>(explodedGraph.nodes().keySet());
int index = 0;
for (ExplodedGraph.Node node : egNodes) {
Collection<ExplodedGraph.Edge> egEdges = node.edges();
addNode(new EGDotNode(index, node, behaviorCache, semanticModel, !egEdges.isEmpty(), cfgFirstBlockId));
Stream<ExplodedGraph.Edge> edgeStream = egEdges.stream();
if (!SHOW_MULTIPLE_PARENTS) {
edgeStream = edgeStream.limit(1);
}
int finalIndex = index;
edgeStream.map(e -> new EGDotEdge(egNodes.indexOf(e.parent()), finalIndex, e, semanticModel)).forEach(this::addEdge);
index++;
}
}
示例4: retrieve
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public List<Movie> retrieve(Query query) throws PersistException {
List<Movie> movies = getMovies();
Stream<Movie> stream = movies.stream();
// filter
if (query.hasFilters() || query.getSearch() != null) {
stream = stream.filter(movie -> query.match(new JsonMatcher(movie.toJson())));
}
// sort
if ((query.getSort() != null && !"title".equals(query.getSort())) || query.isDescending()) {
stream = stream.sorted(new JsonableComparator(query, (j1, j2) -> {
return getSortTitle(j1).compareToIgnoreCase(getSortTitle(j2));
}));
}
// paginate
if (query.getStart() > 0)
stream = stream.skip(query.getStart());
if (query.getMax() != Query.MAX_ALL)
stream = stream.limit(query.getMax());
return stream.collect(Collectors.toList());
}
示例5: getRelationEntityTypes
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Get stream of entity types to based on given strategy, relation row will be created for each one
*
* @param instance instance to get types from
* @return stream of entity types based on given strategy, relation row will be created for each one
*/
private Stream<Integer> getRelationEntityTypes(Instance instance) {
RelationSchemaStrategy strategy = config.getSchemaStrategy();
// in default, return all types
Stream<Integer> types = instance.getTypes().stream();
if (strategy == Predicates || strategy == SingleTable) {
// create row for one type only
types = types.limit(1);
} else if (config.isRootTypesOnly()) {
// filter out types that have a superclass to ensure relations are only created between root classes
if (instance.getTypes().size() > 1) {
types = types.filter(type -> !classGraph.hasSuperClasses(type));
}
}
return types;
}
示例6: getFibNos
import java.util.stream.Stream; //導入方法依賴的package包/類
@GET
@Timed
public Response getFibNos(@QueryParam("limit") Optional<Long> limit) {
List<BigInteger> fibonacciWindow = new LinkedList<>(Arrays.asList(BigInteger.ZERO, BigInteger.ONE));
Stream<BigInteger> fibonacciStream = Stream.generate(() -> {
BigInteger nextValue = fibonacciWindow.get(1).add(fibonacciWindow.get(0));
fibonacciWindow.add(nextValue);
return fibonacciWindow.remove(0);
});
if(limit.isPresent()) {
fibonacciStream = fibonacciStream.limit(limit.get());
}
return Response.ok(new ResponseSequenceStreamer(fibonacciStream)).build();
}
示例7: getEvenNos
import java.util.stream.Stream; //導入方法依賴的package包/類
@GET
@Timed
public Response getEvenNos(@QueryParam("limit") Optional<Long> limit) {
Stream<BigInteger> evenNoStream = Stream.iterate(BigInteger.ONE, v -> v.add(BigInteger.ONE))
.filter(v -> v.remainder(new BigInteger("2")).compareTo(BigInteger.ZERO) == 0);
if(limit.isPresent()) {
evenNoStream = evenNoStream.limit(limit.get());
}
return Response.ok(new ResponseSequenceStreamer(evenNoStream)).build();
}
示例8: execute
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
protected void execute() {
EventHistoryService eventHistoryService = get(EventHistoryService.class);
Stream<Event<?, ?>> events = eventHistoryService.history().stream();
boolean dumpAll = all || !(mastership || device || link || topology || host);
if (!dumpAll) {
Predicate<Event<?, ?>> filter = (defaultIs) -> false;
if (mastership) {
filter = filter.or(evt -> evt instanceof MastershipEvent);
}
if (device) {
filter = filter.or(evt -> evt instanceof DeviceEvent);
}
if (link) {
filter = filter.or(evt -> evt instanceof LinkEvent);
}
if (topology) {
filter = filter.or(evt -> evt instanceof TopologyEvent);
}
if (host) {
filter = filter.or(evt -> evt instanceof HostEvent);
}
if (cluster) {
filter = filter.or(evt -> evt instanceof ClusterEvent);
}
events = events.filter(filter);
}
if (maxSize > 0) {
events = events.limit(maxSize);
}
if (outputJson()) {
ArrayNode jsonEvents = events.map(this::json).collect(toArrayNode());
printJson(jsonEvents);
} else {
events.forEach(this::printEvent);
}
}