Example usage for com.google.common.collect ImmutableList isEmpty

List of usage examples for com.google.common.collect ImmutableList isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:com.google.api.tools.framework.aspects.authentication.AuthConfigAspect.java

@Override
public String getDocumentation(ProtoElement element) {
    ImmutableList<String> scopes = getOauthScopes(element);
    return scopes.isEmpty() ? null : snippet.authDocumentation(scopes, scopes.size() == 1).prettyPrint();
}

From source file:com.google.gcloud.datastore.BaseKey.java

BaseKey(String projectId, String namespace, ImmutableList<PathElement> path) {
    Preconditions.checkArgument(!path.isEmpty(), "Path must not be empty");
    this.projectId = projectId;
    this.namespace = namespace;
    this.path = path;
}

From source file:org.waveprotocol.wave.model.raw.RawOperation.java

public RawOperation(Serializer serializer, ImmutableList<? extends WaveletOperation> operations,
        WaveletOperationContext context) {
    Preconditions.checkArgument(!operations.isEmpty(), "No operations");
    this.serializer = serializer;
    this.segmentId = null;
    this.context = context;
    this.operations = operations;
    this.worthy = isWorthy(operations);
}

From source file:com.facebook.buck.android.AndroidLibraryGraphEnhancer.java

public Result createBuildableForAndroidResources(BuildRuleResolver ruleResolver,
        boolean createBuildableIfEmptyDeps) {
    ImmutableSortedSet<BuildRule> originalDeps = originalBuildRuleParams.getDeps();
    ImmutableList<HasAndroidResourceDeps> androidResourceDeps = UberRDotJavaUtil
            .getAndroidResourceDeps(originalDeps);

    if (androidResourceDeps.isEmpty() && !createBuildableIfEmptyDeps) {
        return new Result(originalBuildRuleParams, Optional.<DummyRDotJava>absent());
    }//from   w w  w.  j a v  a  2 s  .c om

    // The androidResourceDeps may contain Buildables, but we need the actual BuildRules. Since this
    // is going to be used to modify the build graph, we can't just wrap the buildables. Fortunately
    // we know that the buildables come from the originalDeps.
    ImmutableSortedSet.Builder<BuildRule> actualDeps = ImmutableSortedSet.naturalOrder();
    for (HasAndroidResourceDeps dep : androidResourceDeps) {
        // If this ever returns null, something has gone horrifically awry.
        actualDeps.add(ruleResolver.get(dep.getBuildTarget()));
    }

    DummyRDotJava dummyRDotJava = new DummyRDotJava(androidResourceDeps, dummyRDotJavaBuildTarget,
            javacOptions);
    BuildRule dummyRDotJavaBuildRule = Buildables.createRuleFromBuildable(dummyRDotJava,
            BuildRuleType.DUMMY_R_DOT_JAVA, dummyRDotJavaBuildTarget, actualDeps.build(),
            originalBuildRuleParams);
    ruleResolver.addToIndex(dummyRDotJavaBuildTarget, dummyRDotJavaBuildRule);

    ImmutableSortedSet<BuildRule> totalDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(originalDeps)
            .add(dummyRDotJavaBuildRule).build();

    BuildRuleParams newBuildRuleParams = originalBuildRuleParams.copyWithChangedDeps(totalDeps);

    return new Result(newBuildRuleParams, Optional.of(dummyRDotJava));
}

From source file:org.apache.samoa.flink.topology.impl.FlinkTopology.java

private void initComponents(ImmutableList<FlinkProcessingItem> flinkComponents) {
    if (flinkComponents.isEmpty())
        return;//from ww w . j av  a  2  s .co m

    for (FlinkProcessingItem comp : flinkComponents) {
        if (comp.canBeInitialised() && !comp.isInitialised() && !comp.isPartOfCycle()) {
            comp.initialise();
            comp.initialiseStreams();

        } //if component is part of one or more cycle
        else if (comp.isPartOfCycle() && !comp.isInitialised()) {
            for (Integer cycle : comp.getCycleIds()) {
                //check if cycle can be initialized
                if (completenessCheck(cycle)) {
                    logger.debug("Cycle: " + cycle + " can be initialised");
                    initializeCycle(cycle);
                } else {
                    logger.debug("Cycle cannot be initialised");
                }
            }
        }
    }
    initComponents(ImmutableList.copyOf(Iterables.filter(flinkComponents, new Predicate<FlinkProcessingItem>() {
        @Override
        public boolean apply(FlinkProcessingItem flinkComponent) {
            return !flinkComponent.isInitialised();
        }
    })));
}

From source file:com.google.errorprone.bugpatterns.inject.dagger.MultibindsInsteadOfMultibindings.java

@Override
public Description matchClass(ClassTree tree, VisitorState state) {
    ImmutableList<ClassTree> multibindingsInterfaces = multibindingsInterfaces(tree, state);
    if (multibindingsInterfaces.isEmpty()) {
        return Description.NO_MATCH;
    }/*from  w  ww .  j a va 2 s .  c om*/
    Description.Builder description = buildDescription(tree);
    Optional<Fix> moveMethodsUp = moveMethodsUp(tree, multibindingsInterfaces, state);
    if (moveMethodsUp.isPresent()) {
        description.addFix(moveMethodsUp.get());
    }
    description.addFix(includeNestedModules(tree, multibindingsInterfaces, state));

    return description.build();
}

From source file:com.freiheit.fuava.simplebatch.processor.RetryingProcessor.java

private Iterable<Result<OriginalItem, Output>> doPersist(final Iterable<Result<OriginalItem, Input>> iterable) {
    final ImmutableList<Result<OriginalItem, Input>> successes = FluentIterable.from(iterable)
            .filter(Result::isSuccess).toList();
    final ImmutableList<Result<OriginalItem, Input>> fails = FluentIterable.from(iterable)
            .filter(Result::isFailed).toList();

    final ImmutableList<Input> outputs = getSuccessOutputs(successes);

    final List<Output> persistenceResults = outputs.isEmpty() ? ImmutableList.of() : apply(outputs);

    if (persistenceResults.size() != outputs.size() || persistenceResults.size() != successes.size()) {
        throw new IllegalStateException("persistence results of unexpected size produced by " + this);
    }//from  ww  w. j  av a2s.c  o  m
    final ImmutableList.Builder<Result<OriginalItem, Output>> b = ImmutableList.builder();

    for (int i = 0; i < outputs.size(); i++) {
        final Result<OriginalItem, Input> processingResult = successes.get(i);
        final Output persistenceResult = persistenceResults.get(i);
        b.add(Result.<OriginalItem, Output>builder(processingResult).withOutput(persistenceResult).success());
    }

    for (final Result<OriginalItem, Input> failed : fails) {
        b.add(Result.<OriginalItem, Output>builder(failed).failed());
    }

    return b.build();
}

From source file:google.registry.request.auth.RequestAuthenticator.java

/** Validates an Auth object, checking for invalid setting combinations. */
void checkAuthConfig(Auth auth) {
    ImmutableList<Auth.AuthMethod> authMethods = ImmutableList.copyOf(auth.methods());
    checkArgument(!authMethods.isEmpty(), "Must specify at least one auth method");
    checkArgument(/*w  w  w.  j  a v  a2 s.c o m*/
            Ordering.explicit(Auth.AuthMethod.INTERNAL, Auth.AuthMethod.API, Auth.AuthMethod.LEGACY)
                    .isStrictlyOrdered(authMethods),
            "Auth methods must be unique and strictly in order - INTERNAL, API, LEGACY");
    checkArgument(authMethods.contains(Auth.AuthMethod.INTERNAL),
            "Auth method INTERNAL must always be specified, and as the first auth method");
    if (authMethods.equals(ImmutableList.of(Auth.AuthMethod.INTERNAL))) {
        checkArgument(!auth.minimumLevel().equals(AuthLevel.USER),
                "Actions with only INTERNAL auth may not require USER auth level");
    } else {
        checkArgument(!auth.userPolicy().equals(Auth.UserPolicy.IGNORED),
                "Actions with auth methods beyond INTERNAL must not specify the IGNORED user policy");
    }
}

From source file:com.google.devtools.build.lib.skyframe.SkylarkModuleCycleReporter.java

@Override
public boolean maybeReportCycle(SkyKey topLevelKey, CycleInfo cycleInfo, boolean alreadyReported,
        EventHandler eventHandler) {
    ImmutableList<SkyKey> pathToCycle = cycleInfo.getPathToCycle();
    ImmutableList<SkyKey> cycle = cycleInfo.getCycle();
    if (pathToCycle.isEmpty()) {
        return false;
    }/*from  ww  w. j  av  a  2s.c o  m*/
    SkyKey lastPathElement = pathToCycle.get(pathToCycle.size() - 1);
    if (alreadyReported) {
        return true;
    } else if (Iterables.all(cycle, IS_SKYLARK_MODULE_SKY_KEY)
            // The last element before the cycle has to be a PackageFunction or SkylarkModule.
            && (IS_PACKAGE_SKY_KEY.apply(lastPathElement)
                    || IS_SKYLARK_MODULE_SKY_KEY.apply(lastPathElement))) {

        Function printer = new Function<SkyKey, String>() {
            @Override
            public String apply(SkyKey input) {
                if (input.argument() instanceof SkylarkImportLookupValue.SkylarkImportLookupKey) {
                    return ((SkylarkImportLookupValue.SkylarkImportLookupKey) input.argument()).importLabel
                            .toString();
                } else if (input.argument() instanceof PackageIdentifier) {
                    return ((PackageIdentifier) input.argument()) + "/BUILD";
                } else {
                    throw new UnsupportedOperationException();
                }
            }
        };

        StringBuilder cycleMessage = new StringBuilder().append("cycle detected in extension files: ")
                .append("\n    ").append(printer.apply(lastPathElement));

        AbstractLabelCycleReporter.printCycle(cycleInfo.getCycle(), cycleMessage, printer);
        // TODO(bazel-team): it would be nice to pass the Location of the load Statement in the
        // BUILD file.
        eventHandler.handle(Event.error(null, cycleMessage.toString()));
        return true;
    } else if (Iterables.any(cycle, IS_PACKAGE_LOOKUP) && Iterables.any(cycle, IS_WORKSPACE_FILE)
            && (IS_REPOSITORY_DIRECTORY.apply(lastPathElement) || IS_PACKAGE_SKY_KEY.apply(lastPathElement)
                    || IS_EXTERNAL_PACKAGE.apply(lastPathElement))) {
        // We have a cycle in the workspace file, report as such.
        Label fileLabel = (Label) Iterables.getLast(Iterables.filter(cycle, IS_AST_FILE_LOOKUP)).argument();
        String repositoryName = fileLabel.getPackageIdentifier().getRepository().strippedName();
        eventHandler.handle(Event.error(null, "Failed to load Skylark extension '" + fileLabel.toString()
                + "'.\n" + "It usually happens when the repository is not defined prior to being used.\n"
                + "Maybe repository '" + repositoryName + "' was defined later in your WORKSPACE file?"));
        return true;
    }
    return false;
}

From source file:org.zanata.client.commands.glossary.pull.GlossaryPullCommand.java

@Override
public void run() throws Exception {
    String fileType = StringUtils.isEmpty(getOpts().getFileType()) ? "csv" : getOpts().getFileType();
    if (!fileType.equalsIgnoreCase("po") && !fileType.equalsIgnoreCase("csv")) {
        throw new RuntimeException("Option '--file-type' is not valid. Please use 'csv' or 'po'");
    }/*from w  w w .ja va2 s  . c  o m*/

    log.info("Server: {}", getOpts().getUrl());
    log.info("Username: {}", getOpts().getUsername());
    log.info("File type: {}", fileType);
    if (StringUtils.isNotBlank(getOpts().getProject())) {
        log.info("Project: {}", getOpts().getProject());
    }
    ImmutableList<String> transLang = getOpts().getTransLang();
    if (transLang != null && !transLang.isEmpty()) {
        log.info("Translation language: {}", Joiner.on(",").join(transLang));
    }

    String project = getOpts().getProject();
    String qualifiedName;
    try {
        qualifiedName = StringUtils.isBlank(project) ? client.getGlobalQualifiedName()
                : client.getProjectQualifiedName(project);
    } catch (ResponseProcessingException rpe) {
        if (rpe.getResponse().getStatus() == 404) {
            log.error("Project {} not found", project);
            return;
        }
        throw rpe;
    }

    log.info("Pulling glossary from server");
    Response response;
    try {
        response = client.downloadFile(fileType, transLang, qualifiedName);
    } catch (ResponseProcessingException e) {
        if (e.getResponse().getStatus() == 404) {
            log.info("No glossary file in server");
            return;
        }
        throw e;
    }

    InputStream glossaryFile = response.readEntity(InputStream.class);
    if (glossaryFile == null) {
        log.info("No glossary file in server");
        return;
    }

    String fileName = ClientUtil.getFileNameFromHeader(response.getStringHeaders());
    if (fileName == null) {
        log.error("Null filename response from server: " + response.getStatusInfo());
        return;
    }

    File file = new File(fileName);
    PathUtil.makeDirs(file.getParentFile());
    try (OutputStream out = new FileOutputStream(file)) {
        int read;
        byte[] buffer = new byte[1024];
        while ((read = glossaryFile.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
        out.flush();
    } finally {
        glossaryFile.close();
    }
    log.info("Glossary pulled to {}", fileName);
}