List of usage examples for com.google.common.collect ImmutableList stream
default Stream<E> stream()
From source file:com.publictransitanalytics.scoregenerator.console.InteractiveNetworkConsole.java
private void showDeltas(final String route, final String beginningStopId, final String endingStopId) { final TransitStop beginningStop = stopIdMap.get(beginningStopId); final TransitStop endingStop = stopIdMap.get(endingStopId); final Set<EntryPoint> entryPoints = transitNetwork.getEntryPoints(beginningStop); final ImmutableListMultimap.Builder<Hop, Duration> durationsBuilder = ImmutableListMultimap.builder(); for (final EntryPoint entryPoint : entryPoints) { final Trip trip = entryPoint.getTrip(); if (trip.getRouteNumber().equals(route)) { final String tripId = trip.getTripId().toString(); final LocalDateTime beginningTime = entryPoint.getTime(); System.out.println(String.format("Trip %s %s", tripId, beginningTime)); TransitStop stop = beginningStop; LocalDateTime time = beginningTime; final Iterator<VehicleEvent> iterator = trip.getForwardIterator(entryPoint.getSequence()); while (iterator.hasNext() && !stop.equals(endingStop)) { final VehicleEvent nextScheduledLocation = iterator.next(); final LocalDateTime nextTime = nextScheduledLocation.getScheduledTime(); final TransitStop nextStop = nextScheduledLocation.getLocation(); final Duration delta = Duration.between(time, nextTime); final Hop hop = new Hop(stop, nextStop); durationsBuilder.put(hop, delta); System.out//from w w w .j a v a 2s .c om .println(String.format("%s -> %s: %s", stop.getStopId(), nextStop.getStopId(), delta)); stop = nextStop; time = nextTime; } System.out.println("---"); } } final ImmutableListMultimap<Hop, Duration> hopDurations = durationsBuilder.build(); for (final Hop hop : hopDurations.keySet()) { final ImmutableList<Duration> durations = hopDurations.get(hop); final Duration min = durations.stream().min(Comparator.naturalOrder()).get(); final Duration max = durations.stream().max(Comparator.naturalOrder()).get(); final double averageSeconds = durations.stream() .collect(Collectors.averagingLong(Duration::getSeconds)); final Duration average = Duration.ofSeconds(Math.round(averageSeconds)); System.out.println(String.format("%s -> %s: min: %s max: %s avg: %s", hop.getStart().getStopId(), hop.getEnd().getStopId(), min, max, average)); } }
From source file:grakn.core.graql.reasoner.atom.binary.RelationAtom.java
public static RelationAtom create(Statement pattern, Variable predicateVar, @Nullable ConceptId predicateId, ReasonerQuery parent) {/*from www .jav a2s . com*/ List<RelationProperty.RolePlayer> rps = new ArrayList<>(); pattern.getProperty(RelationProperty.class).ifPresent(prop -> prop.relationPlayers().stream() .sorted(Comparator.comparing(Object::hashCode)).forEach(rps::add)); ImmutableList<RelationProperty.RolePlayer> relationPlayers = ImmutableList.copyOf(rps); ImmutableSet<Label> roleLabels = ImmutableSet.<Label>builder() .addAll(relationPlayers.stream().map(RelationProperty.RolePlayer::getRole) .flatMap(CommonUtil::optionalToStream).map(Statement::getType) .flatMap(CommonUtil::optionalToStream).map(Label::of).iterator()) .build(); return new AutoValue_RelationAtom(pattern.var(), pattern, parent, predicateVar, predicateId, relationPlayers, roleLabels); }
From source file:com.spectralogic.ds3autogen.java.generators.requestmodels.CreateNotificationRequestGenerator.java
/** * Gets the list of constructor models from a Ds3Request *//*from w w w .jav a 2 s . c o m*/ @Override public ImmutableList<RequestConstructor> toConstructorList(final Ds3Request ds3Request, final String requestName, final Ds3DocSpec docSpec) { final ImmutableList<Arguments> constructorArguments = toConstructorArgumentsList(ds3Request); final ImmutableList<String> argNames = constructorArguments.stream().map(Arguments::getName) .collect(GuavaCollectors.immutableList()); final RequestConstructor constructor = new RequestConstructor(constructorArguments, toConstructorAssignmentList(constructorArguments), toQueryParamsList(ds3Request), toConstructorDocs(requestName, argNames, docSpec, 1)); return ImmutableList.of(constructor); }
From source file:com.spectralogic.ds3autogen.python.generators.request.BaseRequestGenerator.java
/** * Gets the list of required Arguments for the Ds3Request */// w w w . ja v a 2 s .co m @Override public ImmutableList<String> toAssignments(final Ds3Request ds3Request) { final ImmutableList<Arguments> args = getAssignmentArguments(ds3Request); return args.stream().map(param -> camelToUnderscore(param.getName())) .collect(GuavaCollectors.immutableList()); }
From source file:com.spectralogic.ds3autogen.java.generators.responsemodels.BaseResponseGenerator.java
/** * Converts a list of Arguments into a comma-separated list of parameters *//* ww w . j a v a 2 s .co m*/ @Override public String toConstructorParams(final ImmutableList<Arguments> params) { if (isEmpty(params)) { return ""; } return params.stream().map(i -> "final " + i.getType() + " " + uncapFirst(i.getName())) .collect(Collectors.joining(", ")); }
From source file:com.spectralogic.ds3autogen.java.generators.requestmodels.BulkRequestGenerator.java
/** * Gets the list of constructor models from a Ds3Request *//*w ww. jav a2s . co m*/ @Override public ImmutableList<RequestConstructor> toConstructorList(final Ds3Request ds3Request, final String requestName, final Ds3DocSpec docSpec) { final ImmutableList<Arguments> constructorArguments = toConstructorArgumentsList(ds3Request); final ImmutableList<String> argNames = constructorArguments.stream().map(Arguments::getName) .collect(GuavaCollectors.immutableList()); final RequestConstructor constructor = new RequestConstructor(constructorArguments, toConstructorAssignmentList(constructorArguments), toQueryParamsList(ds3Request), toConstructorDocs(requestName, argNames, docSpec, 1)); return ImmutableList.of(constructor); }
From source file:com.facebook.buck.features.ocaml.OcamlDependencyGraphGenerator.java
public ImmutableList<String> generate(String depToolOutput) { parseDependencies(depToolOutput);/* w w w.j a v a 2s . c o m*/ Objects.requireNonNull(graph); ImmutableList<String> sortedDeps = TopologicalSort.sort(graph); // Two copies of dependencies as .cmo can map to .ml or .re return Stream .concat(sortedDeps.stream().map(input -> replaceObjExtWithSourceExt(input, false /* isReason */)), sortedDeps.stream().map(input -> replaceObjExtWithSourceExt(input, true /* isReason */))) .collect(ImmutableList.toImmutableList()); }
From source file:com.spectralogic.ds3autogen.python.generators.request.BaseRequestGenerator.java
/** * Gets the sorted list of optional constructor parameters for a Ds3Request *///from w w w .j a va2 s . c om @Override public ImmutableList<ConstructorParam> toOptionalConstructorParams(final Ds3Request ds3Request) { final ImmutableList<Arguments> optionalArgs = toOptionalArgumentsList(ds3Request.getOptionalQueryParams()); return optionalArgs.stream().sorted(new CustomArgumentComparator()) .map(arg -> new ConstructorParam(camelToUnderscore(arg.getName()), true)) .collect(GuavaCollectors.immutableList()); }
From source file:com.facebook.buck.ocaml.OcamlDependencyGraphGenerator.java
public ImmutableList<String> generate(String depToolOutput) { parseDependencies(depToolOutput);/*w w w . j a v a 2 s . c o m*/ Preconditions.checkNotNull(graph); final ImmutableList<String> sortedDeps = TopologicalSort.sort(graph); // Two copies of dependencies as .cmo can map to .ml or .re return Stream .concat(sortedDeps.stream().map(input -> replaceObjExtWithSourceExt(input, false /* isReason */)), sortedDeps.stream().map(input -> replaceObjExtWithSourceExt(input, true /* isReason */))) .collect(MoreCollectors.toImmutableList()); }
From source file:org.apache.james.jmap.methods.SetFilterMethod.java
private void ensureNoMultipleMailboxesRules(ImmutableList<Rule> rules) throws MultipleMailboxIdException { ImmutableList<Rule.Id> idWithMultipleMailboxes = rules.stream() .filter(rule -> rule.getAction().getAppendInMailboxes().getMailboxIds().size() > 1).map(Rule::getId) .collect(ImmutableList.toImmutableList()); if (!idWithMultipleMailboxes.isEmpty()) { throw new MultipleMailboxIdException(idWithMultipleMailboxes); }//w ww .j av a 2 s .c om }