List of usage examples for com.google.common.collect ImmutableList isEmpty
boolean isEmpty();
From source file:com.bennavetta.aeneas.zookeeper.manager.ZooKeeperManager.java
private ZooKeeper initialCluster() throws ZkException, IOException { ImmutableList<ZkServer> servers = registry.getServers(); if (servers.isEmpty()) { // TODO: wait for cluster members - https://github.com/coreos/etcd/issues/1516 would help throw new IllegalStateException("No cluster members"); } else {// w w w . j av a 2 s .c o m return new ZooKeeper(Servers.toConnectionString(servers), CONNECTION_TIMEOUT, this); } }
From source file:com.facebook.buck.rules.coercer.CxxGenruleFilterAndTargetsMacroTypeCoercer.java
@Override public M coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, TargetConfiguration targetConfiguration, ImmutableList<String> args) throws CoerceFailedException { if (args.isEmpty() && patternTypeCoercer.isPresent()) { throw new CoerceFailedException( String.format("expected at least one argument (found %d)", args.size())); }//from w ww . j a v a2s. c o m Queue<String> mArgs = new ArrayDeque<>(args); // Parse filter arg. Optional<Pattern> filter = Optional.empty(); if (patternTypeCoercer.isPresent()) { filter = Optional.of(patternTypeCoercer.get().coerce(cellRoots, filesystem, pathRelativeToProjectRoot, targetConfiguration, mArgs.remove())); } // Parse build target args. ImmutableList<BuildTarget> targets = buildTargetsTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, targetConfiguration, mArgs); return factory.apply(filter, targets); }
From source file:com.google.cloud.firestore.BasePath.java
/** * Returns the path of the parent element. * * @return The new Path or null if we are already at the root. *///w ww . j a v a 2s.c o m @Nullable B getParent() { ImmutableList<String> parts = getSegments(); if (parts.isEmpty()) { return null; } return createPathWithSegments(parts.subList(0, parts.size() - 1)); }
From source file:com.facebook.buck.rules.macros.QueryOutputsMacroExpander.java
@Override public Object extractRuleKeyAppendables(BuildTarget target, CellPathResolver cellNames, final BuildRuleResolver resolver, ImmutableList<String> input) throws MacroException { if (input.isEmpty()) { throw new MacroException("One quoted query expression is expected"); }/* www . j ava2s . c om*/ String queryExpression = CharMatcher.anyOf("\"'").trimFrom(input.get(0)); // Return a list of SourcePaths to the outputs of our query results. This enables input-based // rule key hits. return resolveQuery(target, cellNames, resolver, queryExpression).map(queryTarget -> { Preconditions.checkState(queryTarget instanceof QueryBuildTarget); try { return resolver.requireRule(((QueryBuildTarget) queryTarget).getBuildTarget()); } catch (NoSuchBuildTargetException e) { throw new RuntimeException(new MacroException("Error extracting rule key appendables", e)); } }).filter(rule -> rule.getPathToOutput() != null) .map(rule -> SourcePaths.getToBuildTargetSourcePath().apply(rule)) .collect(MoreCollectors.toImmutableSortedSet(Ordering.natural())); }
From source file:com.facebook.buck.rules.macros.QueryMacroExpander.java
private Stream<BuildTarget> extractTargets(BuildTarget target, CellPathResolver cellNames, Optional<BuildRuleResolver> resolver, ImmutableList<String> input) throws MacroException { if (input.isEmpty()) { throw new MacroException("One quoted query expression is expected with optional flags"); }//from w w w. j a v a 2 s.c o m String queryExpression = CharMatcher.anyOf("\"'").trimFrom(input.get(0)); final GraphEnhancementQueryEnvironment env = new GraphEnhancementQueryEnvironment(resolver, targetGraph, cellNames, target, ImmutableSet.of()); try { QueryExpression parsedExp = QueryExpression.parse(queryExpression, env); HashSet<String> targetLiterals = new HashSet<>(); parsedExp.collectTargetPatterns(targetLiterals); return targetLiterals.stream().flatMap(pattern -> { try { return env.getTargetsMatchingPattern(pattern, executorService).stream(); } catch (Exception e) { throw new RuntimeException(new MacroException("Error parsing target expression", e)); } }).map(queryTarget -> { Preconditions.checkState(queryTarget instanceof QueryBuildTarget); return ((QueryBuildTarget) queryTarget).getBuildTarget(); }); } catch (QueryException e) { throw new MacroException("Error parsing query from macro", e); } }
From source file:com.squareup.wire.schema.OneOf.java
OneOf retainAll(Schema schema, MarkSet markSet, ProtoType enclosingType) { ImmutableList<Field> retainedFields = Field.retainAll(schema, markSet, enclosingType, fields); if (retainedFields.isEmpty()) return null; return new OneOf(name, documentation, retainedFields); }
From source file:com.google.devtools.build.lib.analysis.ExtraActionUtils.java
/** * Scans {@code action_listeners} associated with this build to see if any * {@code extra_actions} should be added to this configured target. If any * action_listeners are present, a partial visit of the artifact/action graph * is performed (for as long as actions found are owned by this {@link * ConfiguredTarget}). Any actions that match the {@code action_listener} * get an {@code extra_action} associated. The output artifacts of the * extra_action are reported to the {@link AnalysisEnvironment} for * bookkeeping.//from w w w .j a va2s . c o m */ static ExtraActionArtifactsProvider createExtraActionProvider( Set<ActionAnalysisMetadata> actionsWithoutExtraAction, RuleContext ruleContext) { BuildConfiguration configuration = ruleContext.getConfiguration(); if (configuration.isHostConfiguration()) { return ExtraActionArtifactsProvider.EMPTY; } ImmutableList<Artifact> extraActionArtifacts = ImmutableList.of(); NestedSetBuilder<Artifact> builder = NestedSetBuilder.stableOrder(); List<Label> actionListenerLabels = configuration.getActionListeners(); if (!actionListenerLabels.isEmpty() && ruleContext.attributes().getAttributeDefinition(":action_listener") != null) { ExtraActionsVisitor visitor = new ExtraActionsVisitor(ruleContext, computeMnemonicsToExtraActionMap(ruleContext)); // The action list is modified within the body of the loop by the maybeAddExtraAction() call, // thus the copy for (ActionAnalysisMetadata action : ImmutableList .copyOf(ruleContext.getAnalysisEnvironment().getRegisteredActions())) { if (!actionsWithoutExtraAction.contains(action)) { visitor.maybeAddExtraAction(action); } } extraActionArtifacts = visitor.getAndResetExtraArtifacts(); if (!extraActionArtifacts.isEmpty()) { builder.addAll(extraActionArtifacts); } } // Add extra action artifacts from dependencies for (ExtraActionArtifactsProvider provider : AnalysisUtils .getProviders(ruleContext.getConfiguredTargetMap().values(), ExtraActionArtifactsProvider.class)) { builder.addTransitive(provider.getTransitiveExtraActionArtifacts()); } return ExtraActionArtifactsProvider.create( NestedSetBuilder.<Artifact>stableOrder().addAll(extraActionArtifacts).build(), builder.build()); }
From source file:com.github.hilcode.versionator.impl.DefaultReleaseExtractor.java
@Override public final Result<String, ImmutableList<GroupArtifact>> extract(final ImmutableList<String> arguments) { Preconditions.checkNotNull(arguments, "Missing 'arguments'."); if (arguments.isEmpty()) { return Result.success(ImmutableList.<GroupArtifact>of()); }//from w w w. j av a 2 s .c o m final String firstArgument = arguments.get(0); if (firstArgument.equals("-x") || firstArgument.equals("--exclude")) { final ImmutableList<String> exclusions = arguments.subList(1, arguments.size()); return extractExclusions(exclusions); } else { return Result.failure(String.format( "Expected '-x' or '--exclude' but found '%s' instead.\n\nPerhaps try --help?", firstArgument)); } }
From source file:com.google.devtools.build.lib.testutil.UnknownRuleConfiguredTarget.java
@Override public ConfiguredTarget create(RuleContext context) { // TODO(bazel-team): (2009) why isn't this an error? It would stop the build more promptly... context.ruleWarning("cannot build " + context.getRule().getRuleClass() + " rules"); ImmutableList<Artifact> outputArtifacts = context.getOutputArtifacts(); NestedSet<Artifact> filesToBuild; if (outputArtifacts.isEmpty()) { // Gotta build *something*... filesToBuild = NestedSetBuilder.create(Order.STABLE_ORDER, context.createOutputArtifact()); } else {//from ww w.j a v a2 s .c om filesToBuild = NestedSetBuilder.wrap(Order.STABLE_ORDER, outputArtifacts); } Rule rule = context.getRule(); context.registerAction(new FailAction(context.getActionOwner(), filesToBuild, "cannot build " + rule.getRuleClass() + " rules such as " + rule.getLabel())); return new RuleConfiguredTargetBuilder(context).setFilesToBuild(filesToBuild) .add(RunfilesProvider.class, RunfilesProvider.simple(Runfiles.EMPTY)).build(); }
From source file:com.squareup.wire.schema.EnclosingType.java
@Override Type retainAll(Schema schema, MarkSet markSet) { ImmutableList.Builder<Type> retainedNestedTypesBuilder = ImmutableList.builder(); for (Type nestedType : nestedTypes) { Type retainedNestedType = nestedType.retainAll(schema, markSet); if (retainedNestedType != null) { retainedNestedTypesBuilder.add(retainedNestedType); }// w w w. j a v a 2 s . c o m } ImmutableList<Type> retainedNestedTypes = retainedNestedTypesBuilder.build(); if (retainedNestedTypes.isEmpty()) { return null; } return new EnclosingType(location, type, documentation, retainedNestedTypes); }