List of usage examples for com.google.common.collect Streams zip
public static <A, B, R> Stream<R> zip(Stream<A> streamA, Stream<B> streamB, BiFunction<? super A, ? super B, R> function)
From source file:no.ssb.vtl.script.operations.join.CrossJoinOperation.java
@Override public Optional<Stream<DataPoint>> getData(Order requestedOrder, Filtering filtering, Set<String> components) { Iterator<Dataset> iterator = getChildren().iterator(); // Optimization if (getChildren().size() == 1) return Optional.of(order(requestedOrder, filtering, components, iterator.next())); Dataset left = iterator.next();/* w ww .jav a2 s . c o m*/ Dataset right = left; // Create the resulting data points. final DataStructure joinStructure = getDataStructure(); final DataStructure structure = left.getDataStructure(); Stream<DataPoint> result = order(requestedOrder, filtering, components, left) .map(dataPoint -> joinStructure.fromMap(structure.asMap(dataPoint))); while (iterator.hasNext()) { left = right; right = iterator.next(); result = Streams.zip(result, order(requestedOrder, filtering, components, right), getMerger(left, right)); } return Optional.of(result); }
From source file:org.eclipse.milo.opcua.sdk.client.api.services.AttributeServices.java
/** * This service is used to read one or more attributes of one or more nodes. * * @param maxAge the requested max age of the value, in milliseconds. If maxAge is set to 0, the Server * shall attempt to read a new value from the data source. If maxAge is set to the max * Int32 value or greater, the Server shall attempt to get a cached value. Negative values * are invalid for maxAge. * @param timestampsToReturn the requested {@link TimestampsToReturn}. * @param nodeIds the {@link NodeId}s identifying the nodes to read. * @param attributeIds the attribute ids to read, the size and order matching the provided {@link NodeId}s. * @return a {@link CompletableFuture} containing a list of {@link DataValue}s, the size and order matching the * provided {@link NodeId}s./* ww w.ja v a2s . co m*/ */ default CompletableFuture<List<DataValue>> read(double maxAge, TimestampsToReturn timestampsToReturn, List<NodeId> nodeIds, List<UInteger> attributeIds) { if (nodeIds.size() != attributeIds.size()) { CompletableFuture<List<DataValue>> failed = new CompletableFuture<>(); failed.completeExceptionally(new IllegalArgumentException("nodeIds.size() != attributeIds.size()")); return failed; } else { Stream<ReadValueId> stream = Streams.zip(nodeIds.stream(), attributeIds.stream(), (nId, aId) -> new ReadValueId(nId, aId, null, QualifiedName.NULL_VALUE)); return read(maxAge, timestampsToReturn, stream.collect(Collectors.toList())) .thenApply(r -> l(r.getResults())); } }
From source file:com.google.errorprone.bugpatterns.UnusedException.java
private static boolean typesEqual(List<Type> typesA, List<Type> typesB, VisitorState state) { return Streams.zip(typesA.stream(), typesB.stream(), (a, b) -> ASTHelpers.isSameType(a, b, state)) .allMatch(x -> x);/*from w w w. j a va2 s. c o m*/ }
From source file:org.eclipse.milo.opcua.sdk.client.api.services.AttributeServices.java
/** * This service is used to write to the value attribute of one or more nodes. * * @param nodeIds the {@link NodeId}s identifying the nodes to write to. * @param values the {@link DataValue}s to write. * @return a {@link CompletableFuture} containing a list of results for the writes. *//*from ww w.j a va2 s. c o m*/ default CompletableFuture<List<StatusCode>> writeValues(List<NodeId> nodeIds, List<DataValue> values) { if (nodeIds.size() != values.size()) { CompletableFuture<List<StatusCode>> failed = new CompletableFuture<>(); failed.completeExceptionally(new IllegalArgumentException("nodeIds.size() != values.size()")); return failed; } else { Stream<WriteValue> stream = Streams.zip(nodeIds.stream(), values.stream(), (nodeId, value) -> new WriteValue(nodeId, uint(13), null, value)); return write(stream.collect(Collectors.toList())).thenApply(response -> l(response.getResults())); } }
From source file:com.google.errorprone.bugpatterns.FutureReturnValueIgnored.java
private static Multimap<TypeVariableSymbol, TypeInfo> getResolvedGenerics(MethodInvocationTree tree) { Type type = ASTHelpers.getType(tree.getMethodSelect()); List<Type> from = new ArrayList<>(); List<Type> to = new ArrayList<>(); getSubst(type, from, to);// w w w .j a v a 2 s . c om Multimap<TypeVariableSymbol, TypeInfo> result = Streams .zip(from.stream(), to.stream(), (f, t) -> new TypeInfo((TypeVariableSymbol) f.asElement(), t, tree)) .collect(toMultimap(k -> k.sym, k -> k, MultimapBuilder.linkedHashKeys().arrayListValues()::build)); return result; }
From source file:com.google.errorprone.bugpatterns.threadsafety.ThreadSafety.java
/** * Check that the super-type of a {@code @ThreadSafe}-annotated type is instantiated with * threadsafe type arguments where required by its annotation's containerOf element, and that any * type arguments that correspond to containerOf type parameters on the sub-type are also in the * super-type's containerOf spec.//from ww w. ja v a 2s .com * * @param containerTypeParameters the in-scope threadsafe type parameters, declared on some * enclosing class. * @param annotation the type's {@code @ThreadSafe} info * @param type the type to check */ public Violation checkSuperInstantiation(Set<String> containerTypeParameters, AnnotationInfo annotation, Type type) { Violation info = threadSafeInstantiation(containerTypeParameters, annotation, type); if (info.isPresent()) { return info; } return Streams.zip(type.asElement().getTypeParameters().stream(), type.getTypeArguments().stream(), (typaram, argument) -> { if (containerOfSubtyping(containerTypeParameters, annotation, typaram, argument)) { return Violation.of( String.format("'%s' is not a container of '%s'", annotation.typeName(), typaram)); } return Violation.absent(); }).filter(Violation::isPresent).findFirst().orElse(Violation.absent()); }
From source file:com.google.errorprone.bugpatterns.threadsafety.ThreadSafety.java
/** Checks that any thread-safe type parameters are instantiated with thread-safe types. */ public Violation checkInstantiation(Collection<TypeVariableSymbol> typeParameters, Collection<Type> typeArguments) { return Streams.zip(typeParameters.stream(), typeArguments.stream(), (sym, type) -> { if (!hasThreadSafeTypeParameterAnnotation(sym)) { return Violation.absent(); }// w w w.ja v a 2 s . co m Violation info = isThreadSafeType(/* allowContainerTypeParameters= */ true, /* containerTypeParameters= */ ImmutableSet.of(), type); if (!info.isPresent()) { return Violation.absent(); } return info.plus(String.format("instantiation of '%s' is %s", sym, purpose.mutableOrNotThreadSafe())); }).filter(Violation::isPresent).findFirst().orElse(Violation.absent()); }
From source file:org.eclipse.milo.opcua.sdk.client.session.SessionFsmFactory.java
@SuppressWarnings("Duplicates") private static CompletableFuture<Unit> transferSubscriptions(FsmContext<State, Event> ctx, OpcUaClient client, OpcUaSession session) {/* w w w . ja va 2 s . com*/ UaStackClient stackClient = client.getStackClient(); OpcUaSubscriptionManager subscriptionManager = client.getSubscriptionManager(); ImmutableList<UaSubscription> subscriptions = subscriptionManager.getSubscriptions(); if (subscriptions.isEmpty()) { return completedFuture(Unit.VALUE); } CompletableFuture<Unit> transferFuture = new CompletableFuture<>(); UInteger[] subscriptionIdsArray = subscriptions.stream().map(UaSubscription::getSubscriptionId) .toArray(UInteger[]::new); TransferSubscriptionsRequest request = new TransferSubscriptionsRequest( client.newRequestHeader(session.getAuthenticationToken()), subscriptionIdsArray, true); LOGGER.debug("[{}] Sending TransferSubscriptionsRequest...", ctx.getInstanceId()); stackClient.sendRequest(request).thenApply(TransferSubscriptionsResponse.class::cast) .whenComplete((tsr, ex) -> { if (tsr != null) { List<TransferResult> results = l(tsr.getResults()); LOGGER.debug("[{}] TransferSubscriptions supported: {}", ctx.getInstanceId(), tsr.getResponseHeader().getServiceResult()); if (LOGGER.isDebugEnabled()) { try { Stream<UInteger> subscriptionIds = subscriptions.stream() .map(UaSubscription::getSubscriptionId); Stream<StatusCode> statusCodes = results.stream() .map(TransferResult::getStatusCode); //noinspection UnstableApiUsage String[] ss = Streams .zip(subscriptionIds, statusCodes, (i, s) -> String .format("id=%s/%s", i, StatusCodes.lookup(s.getValue()).map(sa -> sa[0]) .orElse(s.toString()))) .toArray(String[]::new); LOGGER.debug("[{}] TransferSubscriptions results: {}", ctx.getInstanceId(), Arrays.toString(ss)); } catch (Throwable t) { LOGGER.error("[{}] error logging TransferSubscription results", ctx.getInstanceId(), t); } } client.getConfig().getExecutor().execute(() -> { for (int i = 0; i < results.size(); i++) { TransferResult result = results.get(i); if (!result.getStatusCode().isGood()) { UaSubscription subscription = subscriptions.get(i); subscriptionManager.transferFailed(subscription.getSubscriptionId(), result.getStatusCode()); } } }); transferFuture.complete(Unit.VALUE); } else { StatusCode statusCode = UaException.extract(ex).map(UaException::getStatusCode) .orElse(StatusCode.BAD); // Bad_ServiceUnsupported is the correct response when transfers aren't supported but // server implementations tend to interpret the spec in their own unique way... if (statusCode.getValue() == StatusCodes.Bad_NotImplemented || statusCode.getValue() == StatusCodes.Bad_NotSupported || statusCode.getValue() == StatusCodes.Bad_OutOfService || statusCode.getValue() == StatusCodes.Bad_ServiceUnsupported) { LOGGER.debug("[{}] TransferSubscriptions not supported: {}", ctx.getInstanceId(), statusCode); client.getConfig().getExecutor().execute(() -> { // transferFailed() will remove the subscription, but that is okay // because the list from getSubscriptions() above is a copy. for (UaSubscription subscription : subscriptions) { subscriptionManager.transferFailed(subscription.getSubscriptionId(), statusCode); } }); transferFuture.complete(Unit.VALUE); } else { transferFuture.completeExceptionally(ex); } } }); return transferFuture; }