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.template.soy.jssrc.dsl.Composite.java

static Composite create(ImmutableList<CodeChunk> initialStatements, CodeChunk.WithValue value) {
    Preconditions.checkState(!initialStatements.isEmpty());
    return new AutoValue_Composite(ImmutableSet.<CodeChunk>builder().addAll(initialStatements)
            .addAll(value.initialStatements()).build(), initialStatements, value);
}

From source file:org.locationtech.geogig.model.RevObjects.java

/**
 * Creates and returns an iterator of the joint lists of {@link RevTree#trees() trees} and
 * {@link RevTree#features() features} of the given {@code RevTree} whose iteration order is
 * given by the provided {@code comparator}.
 * //from  w  w  w  .j  av  a2s.c o  m
 * @return an iterator over the <b>direct</b> {@link RevTree#trees() trees} and
 *         {@link RevTree#features() feature} children collections, in the order mandated by the
 *         provided {@code comparator}
 */
public static Iterator<Node> children(RevTree tree, Comparator<Node> comparator) {
    checkNotNull(comparator);
    ImmutableList<Node> trees = tree.trees();
    ImmutableList<Node> features = tree.features();
    if (trees.isEmpty()) {
        return features.iterator();
    }
    if (features.isEmpty()) {
        return trees.iterator();
    }
    return Iterators.mergeSorted(ImmutableList.of(trees.iterator(), features.iterator()), comparator);
}

From source file:com.google.devtools.build.lib.actions.CommandLine.java

/**
 * Returns a {@link CommandLine} that is constructed by appending the {@code args} to {@code
 * commandLine}./*  ww  w . j  av a 2 s  .  co  m*/
 */
public static CommandLine concat(final CommandLine commandLine, final ImmutableList<String> args) {
    if (args.isEmpty()) {
        return commandLine;
    }
    return new SuffixedCommandLine(args, commandLine);
}

From source file:li.klass.fhem.behavior.dim.DiscreteDimmableBehavior.java

static Optional<DiscreteDimmableBehavior> behaviorFor(SetList setList) {

    List<String> keys = setList.getSortedKeys();
    ImmutableList<String> foundDimStates = from(keys).filter(DIMMABLE_STATE).toList();

    return foundDimStates.isEmpty() ? Optional.<DiscreteDimmableBehavior>absent()
            : Optional.of(new DiscreteDimmableBehavior(foundDimStates));
}

From source file:elaborate.jaxrs.JAXUtils.java

/**
 * Returns an API description for each HTTP method in the specified
 * class if it has a <code>Path</code> annotation, or an empty list
 * if the <code>Path</code> annotation is missing.
 *//*from   ww  w  . ja v  a2s.  c om*/
public static List<API> generateAPIs(Class<?> cls) {
    List<API> list = Lists.newArrayList();

    String basePath = pathValueOf(cls);
    if (!basePath.isEmpty()) {
        for (Method method : cls.getMethods()) {
            Builder<String> builder = ImmutableList.<String>builder();
            if (method.isAnnotationPresent(GET.class)) {
                builder.add(HttpMethod.GET);
            }
            if (method.isAnnotationPresent(POST.class)) {
                builder.add(HttpMethod.POST);
            }
            if (method.isAnnotationPresent(PUT.class)) {
                builder.add(HttpMethod.PUT);
            }
            if (method.isAnnotationPresent(DELETE.class)) {
                builder.add(HttpMethod.DELETE);
            }

            ImmutableList<String> reqs = builder.build();
            if (!reqs.isEmpty()) {
                String subPath = pathValueOf(method);
                String fullPath = subPath.isEmpty() ? basePath : basePath + "/" + subPath;
                fullPath = fullPath.replaceAll("\\{([^:]*):[^}]*\\}", "{$1}");
                list.add(new API(fullPath, reqs, requestContentTypesOf(method), responseContentTypesOf(method),
                        descriptionOf(method)));
            }
        }
    }

    return list;
}

From source file:com.sourceclear.headlines.util.HeaderBuilder.java

/**
 * @param values - list of String attribute values
 * @return formatted values//  ww  w .  j  av a2 s. c  om
 */
public static String formatListAttributeValues(ImmutableList<String> values) {

    // In the case of an empty map return the empty string:
    if (values.isEmpty()) {
        return "";
    }

    StringBuilder sb = new StringBuilder();

    // Outer loop - loop through each directive
    for (int i = 0; i < values.size(); i++) {

        // Don't add a directive if it has zero elements
        if (values.size() == 0) {
            continue;
        }

        //adding value of header attributes
        sb.append("'").append(values.get(i)).append("'");

        // adding comma if list value isn't last
        if (values.size() > 1 && i < values.size() - 1) {
            sb.append(",");
        }
    }

    return sb.toString().trim();
}

From source file:com.torodb.torod.db.postgresql.query.processors.InProcessor.java

@Nullable
private static ProcessedQueryCriteria getNumericQuery(InQueryCriteria criteria,
        Multimap<BasicType, Value<?>> byTypeValues) {
    ImmutableList.Builder<Value<?>> newInBuilder = ImmutableList.builder();

    for (Value<?> value : byTypeValues.values()) {
        newInBuilder.add(value);/*from w  ww. ja v  a2  s.  co m*/
    }

    ImmutableList<Value<?>> newIn = newInBuilder.build();

    if (newIn.isEmpty()) {
        return null;
    }

    DisjunctionBuilder structureBuilder = new DisjunctionBuilder();

    structureBuilder.add(new TypeIsQueryCriteria(criteria.getAttributeReference(), BasicType.DOUBLE));
    structureBuilder.add(new TypeIsQueryCriteria(criteria.getAttributeReference(), BasicType.INTEGER));
    structureBuilder.add(new TypeIsQueryCriteria(criteria.getAttributeReference(), BasicType.LONG));

    newInBuilder.addAll(byTypeValues.get(BasicType.DOUBLE));
    newInBuilder.addAll(byTypeValues.get(BasicType.INTEGER));
    newInBuilder.addAll(byTypeValues.get(BasicType.LONG));

    return new ProcessedQueryCriteria(structureBuilder.build(),
            new InQueryCriteria(criteria.getAttributeReference(), newIn));
}

From source file:org.apache.calcite.plan.RelOptPredicateList.java

/** Concatenates two immutable lists, avoiding a copy it possible. */
private static <E> ImmutableList<E> concat(ImmutableList<E> list1, ImmutableList<E> list2) {
    if (list1.isEmpty()) {
        return list2;
    } else if (list2.isEmpty()) {
        return list1;
    } else {/*from www .j  a v  a 2 s  . co m*/
        return ImmutableList.<E>builder().addAll(list1).addAll(list2).build();
    }
}

From source file:org.lanternpowered.server.text.gson.JsonTextLiteralSerializer.java

static JsonElement serializeLiteralText(Text text, String content, JsonSerializationContext context,
        boolean removeComplexity) {
    final boolean noActionsAndStyle = areActionsAndStyleEmpty(text);
    final ImmutableList<Text> children = text.getChildren();

    if (noActionsAndStyle) {
        if (children.isEmpty()) {
            return new JsonPrimitive(content);
            // Try to make the serialized text object less complex,
            // like text objects nested in a lot of other
            // text objects, this seems to happen a lot
        } else if (removeComplexity && content.isEmpty()) {
            if (children.size() == 1) {
                return context.serialize(children.get(0));
            } else {
                return context.serialize(children);
            }/*from  ww  w.  ja va  2  s  .c  om*/
        }
    }

    final JsonObject json = new JsonObject();
    json.addProperty(TEXT, content);
    serialize(json, text, context);
    return json;
}

From source file:com.facebook.buck.apple.toolchain.impl.CodeSignIdentityStoreFactory.java

/**
 * Construct a store by asking the system keychain for all stored code sign identities.
 *
 * <p>The loading process is deferred till first access.
 *///from   ww  w .ja  va  2s .  c  o m
public static CodeSignIdentityStore fromSystem(ProcessExecutor processExecutor, ImmutableList<String> command) {
    return CodeSignIdentityStore.of(MoreSuppliers.memoize(() -> {
        ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addAllCommand(command)
                .build();
        // Specify that stdout is expected, or else output may be wrapped in Ansi escape
        // chars.
        Set<Option> options = EnumSet.of(Option.EXPECTING_STD_OUT);
        Result result;
        try {
            result = processExecutor.launchAndExecute(processExecutorParams, options,
                    /* stdin */ Optional.empty(), /* timeOutMs */ Optional.empty(),
                    /* timeOutHandler */ Optional.empty());
        } catch (InterruptedException | IOException e) {
            LOG.warn("Could not execute security, continuing without codesign identity.");
            return ImmutableList.of();
        }

        if (result.getExitCode() != 0) {
            throw new RuntimeException(result.getMessageForUnexpectedResult(String.join(" ", command)));
        }

        Matcher matcher = CODE_SIGN_IDENTITY_PATTERN.matcher(result.getStdout().get());
        Builder<CodeSignIdentity> builder = ImmutableList.builder();
        while (matcher.find()) {
            Optional<HashCode> fingerprint = CodeSignIdentity.toFingerprint(matcher.group(1));
            if (!fingerprint.isPresent()) {
                // security should always output a valid fingerprint string.
                LOG.warn("Code sign identity fingerprint is invalid, ignored: " + matcher.group(1));
                break;
            }
            String subjectCommonName = matcher.group(2);
            CodeSignIdentity identity = CodeSignIdentity.builder().setFingerprint(fingerprint)
                    .setSubjectCommonName(subjectCommonName).build();
            builder.add(identity);
            LOG.debug("Found code signing identity: " + identity);
        }
        ImmutableList<CodeSignIdentity> allValidIdentities = builder.build();
        if (allValidIdentities.isEmpty()) {
            LOG.warn("No valid code signing identities found.  Device build/install won't work.");
        } else if (allValidIdentities.size() > 1) {
            LOG.info("Multiple valid identity found.  This could potentially cause the wrong one to"
                    + " be used unless explicitly specified via CODE_SIGN_IDENTITY.");
        }
        return allValidIdentities;
    }));
}