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.facebook.buck.skylark.parser.RuleFunctionFactory.java

/**
 * Validates attributes passed to the rule and in case any required attribute is not provided,
 * throws an {@link IllegalArgumentException}.
 *
 * @param kwargs The keyword arguments passed to the rule.
 * @param allParamInfo The mapping from build rule attributes to their information.
 * @param name The build rule name. (e.g. {@code java_library}).
 * @param ast The abstract syntax tree of the build rule function invocation.
 *///from  w w w  .  j  a v  a  2s  .  co  m
private void throwOnMissingRequiredAttribute(Map<String, Object> kwargs,
        ImmutableMap<String, ParamInfo> allParamInfo, String name, FuncallExpression ast) throws EvalException {
    ImmutableList<ParamInfo> missingAttributes = allParamInfo.values().stream()
            .filter(param -> !param.isOptional() && !kwargs.containsKey(param.getPythonName()))
            .collect(ImmutableList.toImmutableList());
    if (!missingAttributes.isEmpty()) {
        throw new EvalException(ast.getLocation(),
                name + " requires "
                        + missingAttributes.stream().map(ParamInfo::getPythonName)
                                .collect(Collectors.joining(" and "))
                        + " but they are not provided.",
                BUCK_RULE_DOC_URL_PREFIX + name);
    }
}

From source file:org.locationtech.geogig.storage.memory.HeapGraphDatabase.java

@Override
public boolean put(ObjectId commitId, ImmutableList<ObjectId> parentIds) {
    Node n = graph.getOrAdd(commitId);

    if (parentIds.isEmpty()) {
        // the root node, only update on first addition
        if (!n.isRoot()) {
            n.setRoot(true);/*from w w w  . j av  a2s . com*/
            return true;
        }
    }

    // has the node been attached to graph?
    if (Iterables.isEmpty(n.to())) {
        // nope, attach it
        for (ObjectId parent : parentIds) {
            Node p = graph.getOrAdd(parent);
            graph.newEdge(n, p);
        }

        // only mark as updated if it is actually attached
        boolean added = !Iterables.isEmpty(n.to());
        return added;
    }
    return false;
}

From source file:org.geogit.storage.memory.HeapGraphDatabase.java

@Override
public boolean put(ObjectId commitId, ImmutableList<ObjectId> parentIds) {
    Node n = graph.getOrAdd(commitId);

    if (parentIds.isEmpty()) {
        // the root node, only update on first addition
        if (!n.isRoot()) {
            n.setRoot(true);/*from   w  w  w  .jav a 2  s. c  o m*/
            return true;
        }
    }

    // has the node been attached to graph?
    if (Iterables.isEmpty(n.to())) {
        // nope, attach it
        for (ObjectId parent : parentIds) {
            Node p = graph.getOrAdd(parent);
            graph.newEdge(n, p);
        }

        // only mark as updated if it is actually attached
        return !Iterables.isEmpty(n.to());
    }
    return false;
}

From source file:com.google.template.soy.pysrc.internal.GenPyCallExprVisitor.java

/**
 * Escaping directives might apply to the output of the call node, so wrap the output with all
 * required directives./*from  w  w  w  .  ja  v  a 2  s  . c o m*/
 *
 * @param callExpr The expression text of the call itself.
 * @param directiveNames The list of the directive names to be applied to the call.
 * @return A PyExpr containing the call expression with all directives applied.
 */
private PyExpr escapeCall(String callExpr, ImmutableList<String> directiveNames) {
    PyExpr escapedExpr = new PyExpr(callExpr, Integer.MAX_VALUE);
    if (directiveNames.isEmpty()) {
        return escapedExpr;
    }

    // Successively wrap each escapedExpr in various directives.
    for (String directiveName : directiveNames) {
        SoyPySrcPrintDirective directive = soyPySrcDirectivesMap.get(directiveName);
        Preconditions.checkNotNull(directive, "Autoescaping produced a bogus directive: %s", directiveName);
        escapedExpr = directive.applyForPySrc(escapedExpr, ImmutableList.<PyExpr>of());
    }
    return escapedExpr;
}

From source file:com.facebook.buck.rules.Manifest.java

/**
 * Adds a new output file to the manifest.
 *///w w  w. j a  v a 2  s .c o  m
public void addEntry(FileHashCache fileHashCache, RuleKey key, SourcePathResolver resolver,
        ImmutableSet<SourcePath> universe, ImmutableSet<SourcePath> inputs) throws IOException {
    int index = 0;
    int[] hashIndices = new int[inputs.size()];
    ImmutableListMultimap<String, SourcePath> sortedUniverse = Multimaps.index(universe,
            sourcePathToManifestHeaderFunction(resolver));
    for (SourcePath input : inputs) {
        String relativePath = sourcePathToManifestHeader(input, resolver);
        ImmutableList<SourcePath> paths = sortedUniverse.get(relativePath);
        Preconditions.checkState(!paths.isEmpty());
        hashIndices[index++] = addHash(relativePath, hashSourcePathGroup(fileHashCache, resolver, paths));
    }
    entries.add(new Pair<>(key, hashIndices));
}

From source file:com.facebook.buck.cli.AbstractCommand.java

@Override
public final int run(CommandRunnerParams params) throws IOException, InterruptedException {
    if (showHelp()) {
        new AdditionalOptionsCmdLineParser(this).printUsage(params.getConsole().getStdErr());
        return 1;
    }/*  www .j  a v a  2s.  c o m*/
    if (params.getConsole().getAnsi().isAnsiTerminal()) {
        ImmutableList<String> motd = params.getBuckConfig().getMessageOfTheDay();
        if (!motd.isEmpty()) {
            for (String line : motd) {
                params.getBuckEventBus().post(ConsoleEvent.info(line));
            }
        }
    }
    return runWithoutHelp(params);
}

From source file:com.google.jimfs.PathService.java

/**
 * Returns a path with the given root (or no root, if null) and the given names.
 */// w  w w  . j  a va  2  s  .  c  o m
public JimfsPath createPath(@Nullable Name root, Iterable<Name> names) {
    ImmutableList<Name> nameList = ImmutableList.copyOf(Iterables.filter(names, NOT_EMPTY));
    if (root == null && nameList.isEmpty()) {
        // ensure the canonical empty path (one empty string name) is used rather than a path with
        // no root and no names
        return emptyPath();
    }
    return createPathInternal(root, nameList);
}

From source file:com.facebook.buck.core.build.engine.manifest.Manifest.java

private boolean hashesMatch(FileHashCache fileHashCache, SourcePathResolver resolver,
        ImmutableListMultimap<String, SourcePath> universe, int[] hashIndices) throws IOException {
    for (int hashIndex : hashIndices) {
        Pair<Integer, HashCode> hashEntry = hashes.get(hashIndex);
        String input = inputs.get(hashEntry.getFirst());
        ImmutableList<SourcePath> candidates = universe.get(input);
        if (candidates.isEmpty()) {
            return false;
        }//from w  ww .jav a2 s  .  c o m
        HashCode onDiskHeaderHash;
        try {
            onDiskHeaderHash = hashSourcePathGroup(fileHashCache, resolver, candidates);
        } catch (NoSuchFileException e) {
            return false;
        }
        HashCode inputHash = hashEntry.getSecond();
        if (!inputHash.equals(onDiskHeaderHash)) {
            return false;
        }
    }
    return true;
}

From source file:dagger.internal.codegen.DependencyCycleValidator.java

private Optional<Cycle<Node>> cycleContainingEndpointPair(EndpointPair<Node> endpoints,
        ImmutableNetwork<Node, DependencyEdge> dependencyGraph, Set<EndpointPair<Node>> visited) {
    if (!visited.add(endpoints)) {
        // don't recheck endpoints we already know are part of a cycle
        return Optional.empty();
    }/*from  www . jav  a 2s  . c o  m*/

    // If there's a path from the target back to the source, there's a cycle.
    ImmutableList<Node> cycleNodes = shortestPath(dependencyGraph, endpoints.target(), endpoints.source());
    if (cycleNodes.isEmpty()) {
        return Optional.empty();
    }

    Cycle<Node> cycle = Cycle.fromPath(cycleNodes);
    visited.addAll(cycle.endpointPairs()); // no need to check any edge in this cycle again
    return Optional.of(cycle);
}

From source file:net.minecrell.dandelion.tree.PackageElement.java

public PackageElement(Type type, ImmutableList<String> packageElements, String memberName) {
    this.type = checkNotNull(type, "type");
    checkNotNull(packageElements, "packageElements");
    this.packageElements = packageElements;
    this.packageName = packageElements.isEmpty() ? DEFAULT_PACKAGE : PACKAGE_JOINER.join(packageElements);

    if (memberName != null) {
        this.memberName = Optional.of(memberName);

        StringBuilder builder = new StringBuilder();
        for (String element : packageElements) {
            builder.append(element).append(PATH_SEPARATOR);
        }/*from   ww  w  . java  2  s  . c  om*/
        builder.append(memberName);

        this.path = builder.toString();
    } else {
        checkArgument(this.type == Type.PACKAGE, "Member name must be specified");
        this.memberName = Optional.empty();
        this.path = PATH_JOINER.join(packageElements);
    }
}