List of usage examples for com.google.common.collect Streams stream
public static DoubleStream stream(OptionalDouble optional)
From source file:com.google.gerrit.elasticsearch.AbstractElasticIndex.java
private String toDoc(V v) throws IOException { XContentBuilder builder = jsonBuilder().startObject(); for (Values<V> values : schema.buildFields(v, fillArgs)) { String name = values.getField().getName(); if (values.getField().isRepeatable()) { builder.field(name,/* ww w. j a va 2 s.co m*/ Streams.stream(values.getValues()).filter(e -> shouldAddElement(e)).collect(toList())); } else { Object element = Iterables.getOnlyElement(values.getValues(), ""); if (shouldAddElement(element)) { builder.field(name, element); } } } return builder.endObject().string(); }
From source file:com.google.errorprone.bugpatterns.android.WakelockReleasedDangerously.java
/** Return whether the given try-tree will catch the given exception type. */ private boolean tryCatchesException(TryTree tryTree, Type exceptionToCatch, VisitorState state) { Types types = state.getTypes(); return tryTree.getCatches().stream().anyMatch((CatchTree catchClause) -> { Type catchesException = getType(catchClause.getParameter().getType()); // Examine all alternative types of a union type. if (catchesException != null && catchesException.isUnion()) { return Streams.stream(((UnionClassType) catchesException).getAlternativeTypes()) .anyMatch(caught -> types.isSuperType(caught, exceptionToCatch)); }// ww w. j av a2 s . com // Simple type, just check superclass. return types.isSuperType(catchesException, exceptionToCatch); }); }
From source file:com.google.errorprone.bugpatterns.AssertionFailureIgnored.java
private static Optional<JCCatch> catchesType(JCTry tryStatement, Type assertionErrorType, VisitorState state) { return tryStatement.getCatches().stream().filter(catchTree -> { Type type = ASTHelpers.getType(catchTree.getParameter()); return (type.isUnion() ? Streams.stream(((UnionClassType) type).getAlternativeTypes()) : Stream.of(type)).anyMatch(caught -> isSubtype(assertionErrorType, caught, state)); }).findFirst();// ww w. j av a 2 s.c o m }
From source file:com.google.devtools.build.lib.query2.RdepsBoundedVisitor.java
@Override protected Visit getVisitResult(Iterable<DepAndRdepAtDepth> depAndRdepAtDepths) throws InterruptedException { Map<SkyKey, Integer> shallowestRdepDepthMap = new HashMap<>(); depAndRdepAtDepths.forEach(depAndRdepAtDepth -> shallowestRdepDepthMap .merge(depAndRdepAtDepth.depAndRdep.rdep, depAndRdepAtDepth.rdepDepth, Integer::min)); Collection<SkyKey> validRdeps = new ArrayList<>(); // Multimap of dep to all the reverse deps in this visitation. Used to filter out the // disallowed deps. Multimap<SkyKey, SkyKey> reverseDepMultimap = ArrayListMultimap.create(); for (DepAndRdepAtDepth depAndRdepAtDepth : depAndRdepAtDepths) { // The "roots" of our visitation (see #preprocessInitialVisit) have a null 'dep' field. if (depAndRdepAtDepth.depAndRdep.dep == null) { validRdeps.add(depAndRdepAtDepth.depAndRdep.rdep); } else {/* ww w . j a v a 2 s . c om*/ reverseDepMultimap.put(depAndRdepAtDepth.depAndRdep.dep, depAndRdepAtDepth.depAndRdep.rdep); } } Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap = env .makePackageKeyToTargetKeyMap(Iterables.concat(reverseDepMultimap.values())); Set<PackageIdentifier> pkgIdsNeededForTargetification = packageKeyToTargetKeyMap.keySet().stream() .map(SkyQueryEnvironment.PACKAGE_SKYKEY_TO_PACKAGE_IDENTIFIER).collect(toImmutableSet()); packageSemaphore.acquireAll(pkgIdsNeededForTargetification); try { // Filter out disallowed deps. We cannot defer the targetification any further as we do not // want to retrieve the rdeps of unwanted nodes (targets). if (!reverseDepMultimap.isEmpty()) { Collection<Target> filteredTargets = env.filterRawReverseDepsOfTransitiveTraversalKeys( reverseDepMultimap.asMap(), packageKeyToTargetKeyMap); filteredTargets.stream().map(SkyQueryEnvironment.TARGET_TO_SKY_KEY).forEachOrdered(validRdeps::add); } } finally { packageSemaphore.releaseAll(pkgIdsNeededForTargetification); } ImmutableList<SkyKey> uniqueValidRdeps = validRdeps.stream().filter(validRdep -> validRdepMinDepthUniquifier .uniqueAtDepthLessThanOrEqualTo(validRdep, shallowestRdepDepthMap.get(validRdep))) .collect(ImmutableList.toImmutableList()); // Don't bother getting the rdeps of the rdeps that are already at the depth bound. Iterable<SkyKey> uniqueValidRdepsBelowDepthBound = Iterables.filter(uniqueValidRdeps, uniqueValidRdep -> shallowestRdepDepthMap.get(uniqueValidRdep) < depth); // Retrieve the reverse deps as SkyKeys and defer the targetification and filtering to next // recursive visitation. Map<SkyKey, Iterable<SkyKey>> unfilteredRdepsOfRdeps = env.graph .getReverseDeps(uniqueValidRdepsBelowDepthBound); ImmutableList.Builder<DepAndRdepAtDepth> depAndRdepAtDepthsToVisitBuilder = ImmutableList.builder(); unfilteredRdepsOfRdeps.entrySet().forEach(entry -> { SkyKey rdep = entry.getKey(); int depthOfRdepOfRdep = shallowestRdepDepthMap.get(rdep) + 1; Streams.stream(entry.getValue()).filter(Predicates.and(SkyQueryEnvironment.IS_TTV, universe)) .forEachOrdered(rdepOfRdep -> { depAndRdepAtDepthsToVisitBuilder .add(new DepAndRdepAtDepth(new DepAndRdep(rdep, rdepOfRdep), depthOfRdepOfRdep)); }); }); return new Visit(/*keysToUseForResult=*/ uniqueValidRdeps, /*keysToVisit=*/ depAndRdepAtDepthsToVisitBuilder.build()); }
From source file:ec.tss.TsCollection.java
public Ts[] retain(Iterable<Ts> all) { synchronized (m_moniker) { if (all == null) { return new Ts[0]; } else {/* www .j a v a2s . c o m*/ if (m_set == null) { buildSet(); } return Streams.stream(all).filter(o -> m_set.contains(o.getMoniker())).toArray(Ts[]::new); } } }
From source file:com.yahoo.bard.webservice.data.PreResponseDeserializer.java
/** * Generates ResultSet object from the JsonNode which contains the serialized ResultSet. * * @param serializedResultSet JsonNode which contains the serialized ResultSet * * @return ResultSet object generated from JsonNode *//*from ww w . ja v a 2s .com*/ private ResultSet getResultSet(JsonNode serializedResultSet) { ResultSetSchema resultSetSchema = getResultSetSchema(serializedResultSet.get(SCHEMA_KEY)); List<Result> results = Streams.stream(serializedResultSet.get(RESULTS_KEY)) .map(serializedResult -> getResult(serializedResult, resultSetSchema)).collect(Collectors.toList()); return new ResultSet(resultSetSchema, results); }
From source file:com.google.errorprone.bugpatterns.android.WakelockReleasedDangerously.java
private ClassTree getTopLevelClass(VisitorState state) { return (ClassTree) Streams .findLast(Streams.stream(state.getPath().iterator()).filter((Tree t) -> t.getKind() == Kind.CLASS)) .orElseThrow(() -> new IllegalArgumentException("No enclosing class found")); }
From source file:org.onosproject.artemis.impl.ArtemisConfig.java
/** * Get the information about MOAS. Including remote MOAS server IPs, OVSDB ID and local tunnel IP. * * @return MOAS information//from w w w . java2 s . c om */ MoasInfo moasInfo() { MoasInfo moasInfo = new MoasInfo(); JsonNode moasNode = object.path(MOAS); if (!moasNode.isMissingNode()) { JsonNode legitIpsNode = moasNode.path(MOAS_LEGIT); if (!legitIpsNode.isMissingNode()) { if (legitIpsNode.isArray()) { moasInfo.setMoasAddresses(Streams.stream(legitIpsNode) .map(ipAddress -> IpAddress.valueOf(ipAddress.asText())).collect(Collectors.toSet())); } else { log.warn("Legit MOAS field need to be a list"); } } else { log.warn("No IPs for legit MOAS specified in configuration"); } JsonNode tunnelPointsNode = moasNode.path(TUNNEL_POINTS); if (!tunnelPointsNode.isMissingNode()) { if (tunnelPointsNode.isArray()) { tunnelPointsNode.forEach(tunnelPoint -> { JsonNode idNode = tunnelPoint.path(TUNNEL_OVSDB_IP), localNode = tunnelPoint.path(TUNNEL_LOCAL_IP), ovsNode = tunnelPoint.path(TUNNEL_OVS_PORT); if (!idNode.isMissingNode() && !localNode.isMissingNode()) { moasInfo.addTunnelPoint(new MoasInfo.TunnelPoint(IpAddress.valueOf(idNode.asText()), IpAddress.valueOf(localNode.asText()), ovsNode.asText())); } else { log.warn("Tunnel point need to have an ID and a Local IP"); } }); } else { log.warn("Tunnel points field need to be a list"); } } } else { log.warn("No tunnel points specified in configuration"); } return moasInfo; }
From source file:com.google.errorprone.bugpatterns.LambdaFunctionalInterface.java
private static ClassTree getTopLevelClassTree(VisitorState state) { return (ClassTree) Streams .findLast(Streams.stream(state.getPath().iterator()).filter((Tree t) -> t.getKind() == Kind.CLASS)) .orElseThrow(() -> new IllegalArgumentException("No enclosing class found")); }
From source file:com.yahoo.bard.webservice.data.PreResponseDeserializer.java
/** * Generates ZonedSchema object from given JsonNode. * * @param schemaNode JsonNode which contains all the columns, timezone and granularity * * @return ResultSetSchema object generated from the JsonNode *//*w w w.jav a2 s. c o m*/ private ResultSetSchema getResultSetSchema(JsonNode schemaNode) { DateTimeZone timezone = generateTimezone(schemaNode.get(SCHEMA_TIMEZONE).asText(), DateTimeZone .forID(SYSTEM_CONFIG.getStringProperty(SYSTEM_CONFIG.getPackageVariableName("timezone"), "UTC"))); //Recreate ResultSetSchema LinkedHashSet<Column> columns = Stream .concat(Streams.stream(schemaNode.get(SCHEMA_DIM_COLUMNS)).map(JsonNode::asText) .map(this::resolveDimensionName).map(DimensionColumn::new), Streams.stream(() -> schemaNode.get(SCHEMA_METRIC_COLUMNS_TYPE).fields()).map( entry -> new MetricColumnWithValueType(entry.getKey(), entry.getValue().asText()))) .collect(Collectors.toCollection(LinkedHashSet::new)); return new ResultSetSchema(generateGranularity(schemaNode.get(SCHEMA_GRANULARITY).asText(), timezone), columns); }