List of usage examples for com.google.common.collect ImmutableSet.Builder add
boolean add(E e);
From source file:org.glowroot.local.store.Schemas.java
@VisibleForTesting static ImmutableSet<Index> getIndexes(String tableName, Connection connection) throws SQLException { ListMultimap</*@Untainted*/String, /*@Untainted*/String> indexColumns = ArrayListMultimap.create(); ResultSet resultSet = connection.getMetaData().getIndexInfo(null, null, tableName.toUpperCase(Locale.ENGLISH), false, false); ResultSetCloser closer = new ResultSetCloser(resultSet); try {/*from w ww . j a v a 2 s. c o m*/ while (resultSet.next()) { String indexName = checkNotNull(resultSet.getString("INDEX_NAME")); String columnName = checkNotNull(resultSet.getString("COLUMN_NAME")); // hack-ish to skip over primary key constraints which seem to be always // prefixed in H2 by PRIMARY_KEY_ if (!indexName.startsWith("PRIMARY_KEY_")) { indexColumns.put(castUntainted(indexName), castUntainted(columnName)); } } } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } ImmutableSet.Builder<Index> indexes = ImmutableSet.builder(); for (Entry</*@Untainted*/String, Collection</*@Untainted*/String>> entry : indexColumns.asMap() .entrySet()) { String name = entry.getKey().toLowerCase(Locale.ENGLISH); List<String> columns = Lists.newArrayList(); for (String column : entry.getValue()) { columns.add(column.toLowerCase(Locale.ENGLISH)); } indexes.add(Index.of(name, columns)); } return indexes.build(); }
From source file:com.facebook.presto.operator.aggregation.AggregationCompiler.java
private static Set<Class<?>> getStateClasses(Class<?> clazz) { ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder(); for (Method inputFunction : findPublicStaticMethodsWithAnnotation(clazz, InputFunction.class)) { checkArgument(inputFunction.getParameterTypes().length > 0, "Input function has no parameters"); Class<?> stateClass = inputFunction.getParameterTypes()[0]; checkArgument(AccumulatorState.class.isAssignableFrom(stateClass), "stateClass is not a subclass of AccumulatorState"); builder.add(stateClass); }/*from w ww . j av a 2s .co m*/ ImmutableSet<Class<?>> stateClasses = builder.build(); checkArgument(!stateClasses.isEmpty(), "No input functions found"); return stateClasses; }
From source file:com.facebook.buck.cxx.toolchain.nativelink.NativeLinkables.java
public static ImmutableMap<BuildTarget, NativeLinkable> getTransitiveNativeLinkables(CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder, Iterable<? extends NativeLinkable> inputs) { Map<BuildTarget, NativeLinkable> nativeLinkables = new HashMap<>(); for (NativeLinkable nativeLinkable : inputs) { nativeLinkables.put(nativeLinkable.getBuildTarget(), nativeLinkable); }// www . java 2 s . c o m AbstractBreadthFirstTraversal<BuildTarget> visitor = new AbstractBreadthFirstTraversal<BuildTarget>( nativeLinkables.keySet()) { @Override public Iterable<BuildTarget> visit(BuildTarget target) { NativeLinkable nativeLinkable = Objects.requireNonNull(nativeLinkables.get(target)); ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder(); for (NativeLinkable dep : Iterables.concat( nativeLinkable.getNativeLinkableDepsForPlatform(cxxPlatform, graphBuilder), nativeLinkable.getNativeLinkableExportedDepsForPlatform(cxxPlatform, graphBuilder))) { BuildTarget depTarget = dep.getBuildTarget(); deps.add(depTarget); nativeLinkables.put(depTarget, dep); } return deps.build(); } }; visitor.start(); return ImmutableMap.copyOf(nativeLinkables); }
From source file:com.facebook.buck.cxx.CxxInferEnhancer.java
private static <T extends BuildRule> ImmutableSet<T> requireTransitiveDependentLibraries( final CxxPlatform cxxPlatform, final Iterable<? extends BuildRule> deps, final Flavor requiredFlavor, final Class<T> ruleClass) throws NoSuchBuildTargetException { final ImmutableSet.Builder<T> depsBuilder = ImmutableSet.builder(); new AbstractBreadthFirstThrowingTraversal<BuildRule, NoSuchBuildTargetException>(deps) { @Override//from ww w . j a v a 2s.c om public ImmutableSet<BuildRule> visit(BuildRule buildRule) throws NoSuchBuildTargetException { if (buildRule instanceof CxxLibrary) { CxxLibrary library = (CxxLibrary) buildRule; depsBuilder.add( (ruleClass.cast(library.requireBuildRule(requiredFlavor, cxxPlatform.getFlavor())))); return buildRule.getDeps(); } return ImmutableSet.of(); } }.start(); return depsBuilder.build(); }
From source file:com.google.devtools.build.lib.skyframe.SkyframeLabelVisitor.java
private static Set<Label> getRootCausesOfCycles(Label labelToLoad, Iterable<CycleInfo> cycles) { ImmutableSet.Builder<Label> builder = ImmutableSet.builder(); for (CycleInfo cycleInfo : cycles) { // The root cause of a cycle depends on the type of a cycle. SkyKey culprit = Iterables.getFirst(cycleInfo.getCycle(), null); if (culprit == null) { continue; }/* w ww .j a v a2 s . co m*/ if (culprit.functionName().equals(SkyFunctions.TRANSITIVE_TARGET)) { // For a cycle between build targets, the root cause is the first element of the cycle. builder.add((Label) culprit.argument()); } else { // For other types of cycles (e.g. file symlink cycles), the root cause is the furthest // target dependency that itself depended on the cycle. Label furthestTarget = labelToLoad; for (SkyKey skyKey : cycleInfo.getPathToCycle()) { if (skyKey.functionName().equals(SkyFunctions.TRANSITIVE_TARGET)) { furthestTarget = (Label) skyKey.argument(); } else { break; } } builder.add(furthestTarget); } } return builder.build(); }
From source file:org.apache.brooklyn.core.BrooklynVersion.java
/** * @param mgmt The context to search for features. * @return An iterable containing all features found in the management context's classpath and catalogue. */// w w w .j a va 2s. c o m public static Iterable<BrooklynFeature> getFeatures(ManagementContext mgmt) { if (Osgis.isBrooklynInsideFramework()) { List<Bundle> bundles = Arrays .asList(FrameworkUtil.getBundle(BrooklynVersion.class).getBundleContext().getBundles()); Maybe<OsgiManager> osgi = ((ManagementContextInternal) mgmt).getOsgiManager(); for (CatalogItem<?, ?> catalogItem : mgmt.getCatalog().getCatalogItems()) { if (osgi.isPresentAndNonNull()) { for (CatalogItem.CatalogBundle catalogBundle : catalogItem.getLibraries()) { Maybe<Bundle> osgiBundle = osgi.get().findBundle(catalogBundle); if (osgiBundle.isPresentAndNonNull()) { bundles.add(osgiBundle.get()); } } } } // Set over list in case a bundle is reported more than once (e.g. from classpath and from OSGi). // Not sure of validity of this approach over just reporting duplicates. ImmutableSet.Builder<BrooklynFeature> features = ImmutableSet.builder(); for (Bundle bundle : bundles) { Optional<BrooklynFeature> fs = BrooklynFeature.newFeature(bundle.getHeaders()); if (fs.isPresent()) { features.add(fs.get()); } } return features.build(); } else { Iterable<URL> manifests = ResourceUtils.create(mgmt).getResources(MANIFEST_PATH); for (CatalogItem<?, ?> catalogItem : mgmt.getCatalog().getCatalogItems()) { OsgiBrooklynClassLoadingContext osgiContext = new OsgiBrooklynClassLoadingContext(mgmt, catalogItem.getCatalogItemId(), catalogItem.getLibraries()); manifests = Iterables.concat(manifests, osgiContext.getResources(MANIFEST_PATH)); } // Set over list in case a bundle is reported more than once (e.g. from classpath and from OSGi). // Not sure of validity of this approach over just reporting duplicates. ImmutableSet.Builder<BrooklynFeature> features = ImmutableSet.builder(); for (URL manifest : manifests) { ManifestHelper mh = null; try { mh = ManifestHelper.forManifest(manifest); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.debug("Error reading OSGi manifest from " + manifest + " when determining version properties: " + e, e); } if (mh == null) continue; Attributes attrs = mh.getManifest().getMainAttributes(); Optional<BrooklynFeature> fs = BrooklynFeature.newFeature(attrs); if (fs.isPresent()) { features.add(fs.get()); } } return features.build(); } }
From source file:org.tensorics.core.tensor.Positions.java
/** * Combines the both positions in such a way, that for each coordinate of the types given in the given set of * dimensions have to be//from ww w . j a va 2 s . co m * <ul> * <li>either present in both positions of the pair, and then have to be the same * <li>or be present in only one of the both positions * </ul> * * @param left the first of the two positions, whose dimensions should be united * @param right the second of the two positions whose dimensions should be combined * @param targetDimensions the dimension in which the positions shall be united * @return a new position, with the coordinates merged according to the above rules */ public static Position combineDimensions(Position left, Position right, Set<Class<?>> targetDimensions) { ImmutableSet.Builder<Object> builder = ImmutableSet.builder(); for (Class<?> dimension : targetDimensions) { Object leftCoordinate = left.coordinateFor(dimension); Object rightCoordinate = right.coordinateFor(dimension); if (Objects.equal(leftCoordinate, rightCoordinate) || oneIsNull(leftCoordinate, rightCoordinate)) { builder.add(MoreObjects.firstNonNull(leftCoordinate, rightCoordinate)); } else { throw new IllegalArgumentException("Coordinates for dimension '" + dimension + "' are neither the same in both positions (" + left + " and " + right + "), nor present only in one. Cannot consistently combine."); } } return Position.of(builder.build()); }
From source file:com.facebook.buck.cxx.platform.NativeLinkables.java
public static ImmutableMap<BuildTarget, NativeLinkable> getTransitiveNativeLinkables( final CxxPlatform cxxPlatform, Iterable<? extends NativeLinkable> inputs) { final Map<BuildTarget, NativeLinkable> nativeLinkables = new HashMap<>(); for (NativeLinkable nativeLinkable : inputs) { nativeLinkables.put(nativeLinkable.getBuildTarget(), nativeLinkable); }//from w w w. j av a 2 s . com final MutableDirectedGraph<BuildTarget> graph = new MutableDirectedGraph<>(); AbstractBreadthFirstTraversal<BuildTarget> visitor = new AbstractBreadthFirstTraversal<BuildTarget>( nativeLinkables.keySet()) { @Override public Iterable<BuildTarget> visit(BuildTarget target) { NativeLinkable nativeLinkable = Preconditions.checkNotNull(nativeLinkables.get(target)); graph.addNode(target); ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder(); for (NativeLinkable dep : Iterables.concat( nativeLinkable.getNativeLinkableDepsForPlatform(cxxPlatform), nativeLinkable.getNativeLinkableExportedDepsForPlatform(cxxPlatform))) { BuildTarget depTarget = dep.getBuildTarget(); graph.addEdge(target, depTarget); deps.add(depTarget); nativeLinkables.put(depTarget, dep); } return deps.build(); } }; visitor.start(); return ImmutableMap.copyOf(nativeLinkables); }
From source file:com.facebook.buck.android.relinker.Symbols.java
public static Symbols getSymbols(ProcessExecutor executor, Tool objdump, SourcePathResolver resolver, Path lib) throws IOException, InterruptedException { final ImmutableSet.Builder<String> undefined = ImmutableSet.builder(); final ImmutableSet.Builder<String> global = ImmutableSet.builder(); final ImmutableSet.Builder<String> all = ImmutableSet.builder(); runObjdump(executor, objdump, resolver, lib, ImmutableList.of("-T"), new LineProcessor<Void>() { @Override// w w w . j a v a 2 s .c om public boolean processLine(String line) throws IOException { SymbolInfo si = extractSymbolInfo(line); if (si == null) { return true; } if (si.isUndefined) { undefined.add(si.symbol); } else if (si.isGlobal) { global.add(si.symbol); } all.add(si.symbol); return true; } @Override public Void getResult() { return null; } }); return new Symbols(undefined.build(), global.build(), all.build()); }
From source file:com.facebook.buck.cxx.NativeLinkables.java
public static ImmutableMap<BuildTarget, NativeLinkable> getTransitiveNativeLinkables( final CxxPlatform cxxPlatform, Iterable<? extends NativeLinkable> inputs) { final Map<BuildTarget, NativeLinkable> nativeLinkables = Maps.newHashMap(); for (NativeLinkable nativeLinkable : inputs) { nativeLinkables.put(nativeLinkable.getBuildTarget(), nativeLinkable); }//from ww w .j a va 2 s. c o m final MutableDirectedGraph<BuildTarget> graph = new MutableDirectedGraph<>(); AbstractBreadthFirstTraversal<BuildTarget> visitor = new AbstractBreadthFirstTraversal<BuildTarget>( nativeLinkables.keySet()) { @Override public ImmutableSet<BuildTarget> visit(BuildTarget target) { NativeLinkable nativeLinkable = Preconditions.checkNotNull(nativeLinkables.get(target)); graph.addNode(target); ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder(); for (NativeLinkable dep : Iterables.concat( nativeLinkable.getNativeLinkableDepsForPlatform(cxxPlatform), nativeLinkable.getNativeLinkableExportedDepsForPlatform(cxxPlatform))) { BuildTarget depTarget = dep.getBuildTarget(); graph.addEdge(target, depTarget); deps.add(depTarget); nativeLinkables.put(depTarget, dep); } return deps.build(); } }; visitor.start(); return ImmutableMap.copyOf(nativeLinkables); }