List of usage examples for com.google.common.collect ImmutableSet builder
public static <E> Builder<E> builder()
From source file:org.jclouds.ibm.smartcloud.compute.suppliers.IBMSmartCloudLocationSupplier.java
@Override public Set<? extends Location> get() { Builder<Location> locations = ImmutableSet.builder(); Set<? extends org.jclouds.ibm.smartcloud.domain.Location> list = sync.listLocations(); Location provider = Iterables.getOnlyElement(super.get()); if (list.size() == 0) locations.add(provider);/* ww w . j a va 2 s . c om*/ else for (org.jclouds.ibm.smartcloud.domain.Location from : list) { if (from.getState() != State.OFFLINE) { LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(from.getId() + "") .description(from.getName()).parent(provider); if (isoCodesById.containsKey(from.getId() + "")) builder.iso3166Codes(isoCodesById.get(from.getId() + "")); locations.add(builder.build()); } } return locations.build(); }
From source file:org.codice.ddf.admin.common.fields.base.scalar.StringField.java
@Override public Set<String> getErrorCodes() { return new ImmutableSet.Builder<String>().addAll(super.getErrorCodes()).add(DefaultMessages.EMPTY_FIELD) .build();/*from w w w . j a v a 2 s .c o m*/ }
From source file:org.androidtransfuse.transaction.TransactionProcessorChannel.java
@Override public ImmutableSet<Exception> getErrors() { ImmutableSet.Builder<Exception> exceptions = ImmutableSet.builder(); exceptions.addAll(completionProcessor.getErrors()); exceptions.addAll(afterCompletionProcessor.getErrors()); return exceptions.build(); }
From source file:com.google.devtools.build.lib.actions.CompositeRunfilesSupplier.java
@Override public ImmutableSet<PathFragment> getRunfilesDirs() { ImmutableSet.Builder<PathFragment> result = ImmutableSet.builder(); for (RunfilesSupplier supplier : suppliers) { result.addAll(supplier.getRunfilesDirs()); }/* ww w. ja v a2 s .co m*/ return result.build(); }
From source file:auto.http.internal.codegen.AutoHttpProcessingStep.java
@Override public Set<Element> process(SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) { ImmutableSet.Builder<TypeElement> validAutoHttpTypesBuilder = ImmutableSet.builder(); for (Element autoHttpElement : elementsByAnnotation.get(AutoHttp.class)) { TypeElement autoHttpTypeElement = MoreElements.asType(autoHttpElement); ValidationReport<TypeElement> report = autoHttpValidator.validate(autoHttpTypeElement); report.printMessagesTo(messager); if (report.isClean()) { validAutoHttpTypesBuilder.add(autoHttpTypeElement); }/*from w w w. j av a2 s . c om*/ } for (TypeElement validAutoHttpTypeElement : validAutoHttpTypesBuilder.build()) { ImmutableList.Builder<ExecutableElement> validMethodsBuilder = ImmutableList.builder(); for (Element declaredElement : validAutoHttpTypeElement.getEnclosedElements()) { if (declaredElement.getKind() == ElementKind.METHOD) { ExecutableElement methodElement = MoreElements.asExecutable(declaredElement); ValidationReport<ExecutableElement> report = methodValidator.validate(methodElement); report.printMessagesTo(messager); if (report.isClean()) { validMethodsBuilder.add(methodElement); } } } try { AutoHttpDescriptor autoHttpDescriptor = AutoHttpDescriptor.Factory.create(validAutoHttpTypeElement, validMethodsBuilder.build()); for (AutoHttpDescriptor.MethodDescriptor methodDescriptor : autoHttpDescriptor.methodElements()) { messager.printMessage(Diagnostic.Kind.NOTE, "returnType = " + methodDescriptor.returnType()); messager.printMessage(Diagnostic.Kind.NOTE, "converterType = " + methodDescriptor.converterType()); } autoHttpGenerator.generate(autoHttpDescriptor); } catch (SourceFileGenerationException e) { e.printMessageTo(messager); } catch (ClassNotFoundException e) { messager.printMessage(Diagnostic.Kind.ERROR, "class not found!-->" + e.getMessage()); } } return ImmutableSet.of(); }
From source file:com.facebook.buck.io.ProjectFilesystemDelegateFactory.java
/** * Must always create a new delegate for the specified {@code root}. *///from w ww . ja va 2s . c o m public static ProjectFilesystemDelegate newInstance(Path root, String hgCmd, boolean enableAutosparse, ImmutableList<String> autosparseIgnore) { Optional<EdenClient> client = tryToCreateEdenClient(); if (client.isPresent()) { try { EdenMount mount = client.get().getMountFor(root); if (mount != null) { return new EdenProjectFilesystemDelegate(mount); } } catch (TException | EdenError e) { // If Eden is running but root is not a mount point, Eden getMountFor() should just return // null rather than throw an error. LOG.error(e, "Failed to find Eden client for %s.", root); } } if (enableAutosparse) { // We can't access BuckConfig because that class requires a // ProjectFileSystem, which we are in the process of building // Access the required info from the Config instead HgCmdLineInterface hgCmdLine = new HgCmdLineInterface(new PrintStreamProcessExecutorFactory(), root, hgCmd, ImmutableMap.of()); ImmutableSet.Builder<Path> ignoredPaths = ImmutableSet.builder(); for (String path : autosparseIgnore) { ignoredPaths.add(Paths.get(path)); } AutoSparseState autoSparseState = AbstractAutoSparseFactory.getAutoSparseState(root, hgCmdLine, ignoredPaths.build()); if (autoSparseState != null) { LOG.debug("Autosparse enabled, using AutoSparseProjectFilesystemDelegate"); return new AutoSparseProjectFilesystemDelegate(autoSparseState, root); } } // No Eden or Mercurial info available, use the default return new DefaultProjectFilesystemDelegate(root); }
From source file:com.google.caliper.runner.instrument.InstrumentModule.java
@RunScoped @Provides// w w w . j a v a 2 s . c o m static ImmutableSet<Instrument> provideInstruments(CaliperOptions options, final CaliperConfig config, Map<Class<? extends Instrument>, Provider<Instrument>> availableInstruments, ImmutableSet<VmType> vmTypes, @Stderr PrintWriter stderr) throws InvalidCommandException { ImmutableSet.Builder<Instrument> builder = ImmutableSet.builder(); ImmutableSet<String> configuredInstruments = config.getConfiguredInstruments(); ImmutableSet<String> selectedInstruments = options.instrumentNames(); if (selectedInstruments.isEmpty()) { selectedInstruments = config.getDefaultInstruments(); } for (final String instrumentName : selectedInstruments) { if (!configuredInstruments.contains(instrumentName)) { throw new InvalidCommandException( "%s is not a configured instrument (%s). " + "use --print-config to see the configured instruments.", instrumentName, configuredInstruments); } final InstrumentConfig instrumentConfig = config.getInstrumentConfig(instrumentName); String className = instrumentConfig.className(); try { Class<? extends Instrument> clazz = Util.lenientClassForName(className) .asSubclass(Instrument.class); Provider<Instrument> instrumentProvider = availableInstruments.get(clazz); if (instrumentProvider == null) { throw new InvalidInstrumentException("Instrument %s not supported", className); } if (isSupportedByAllVms(clazz, vmTypes)) { Instrument instrument = instrumentProvider.get(); InstrumentInjectorModule injectorModule = new InstrumentInjectorModule(instrumentConfig, instrumentName); InstrumentComponent instrumentComponent = DaggerInstrumentComponent.builder() .instrumentInjectorModule(injectorModule).build(); instrumentComponent.injectInstrument(instrument); builder.add(instrument); } else { stderr.format("Instrument %s not supported on at least one target VM; ignoring\n", className); } } catch (ClassNotFoundException e) { throw new InvalidCommandException("Cannot find instrument class '%s'", className); } } return builder.build(); }
From source file:com.b2international.snowowl.snomed.core.mrcm.io.ConceptModelSemanticValidator.java
public Collection<ConstraintBase> validate(final IBranchPath branchPath, ConceptModel model) { checkNotNull(branchPath, "branchPath"); checkNotNull(model, "model"); final Builder<ConstraintBase> invalidConstraints = ImmutableSet.builder(); new EObjectWalker(new NoopTreeVisitor<EObjectTreeNode>() { @Override//from w ww . j a v a 2s.c o m protected void doVisit(EObjectTreeNode node) { if (node != null && ConceptModelUtils.CONCEPT_ID_FEATURES.contains(node.getFeature()) && !exists(branchPath, node.getFeatureValue())) { final EObject obj = node.getEObject(); if (obj instanceof ConceptModelPredicate) { invalidConstraints.add(getContainerConstraint((ConceptModelPredicate) obj)); } else if (obj instanceof ConceptSetDefinition) { invalidConstraints.add(getContainerConstraint((ConceptSetDefinition) obj)); } } } }, new EObjectContainmentTreeNodeProvider()).walk(model); return invalidConstraints.build(); }
From source file:org.jclouds.location.suppliers.all.RegionToProviderOrJustProvider.java
@Override public Set<? extends Location> get() { Builder<Location> locations = ImmutableSet.builder(); Location provider = Iterables.getOnlyElement(justProvider.get()); Set<String> regions = regionsSupplier.get(); Map<String, Supplier<Set<String>>> isoCodesById = isoCodesByIdSupplier.get(); if (regions.size() == 0) return locations.add(provider).build(); else//from w ww. j ava2s. co m for (String region : regions) { LocationBuilder builder = new LocationBuilder().scope(LocationScope.REGION).id(region) .description(region).parent(provider); if (isoCodesById.containsKey(region)) builder.iso3166Codes(isoCodesById.get(region).get()); locations.add(builder.build()); } return locations.build(); }
From source file:es.udc.pfc.gamelib.board.AbstractPiece.java
/** * Returns all the possible moves to a given direction. * //from w ww . j ava 2 s . c o m * @param board * the board this piece is on. * @param dir * the direction to get the piece moves * @return a set of positions the piece can move to */ protected final ImmutableSet<Position> getMovesTo(final Board<?> board, final Direction dir) { checkNotNull(board); checkNotNull(dir); final ImmutableSet.Builder<Position> moves = ImmutableSet.builder(); Position pos = board.getPositionFor(this).relative(dir.i(), dir.j()); while (board.isValidPosition(pos) && (!board.isPieceAt(pos) || isEnemy(board.getPieceAt(pos)))) { moves.add(pos); if (board.isPieceAt(pos)) { break; } pos = pos.relative(dir.i(), dir.j()); } return moves.build(); }