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:eu.numberfour.n4js.generator.headless.N4HeadlessCompiler.java

/**
 * Recursive algorithm//from www .j a  v  a 2 s  .  com
 *
 * @param p
 *            current project
 * @param visited
 *            set of projects already processed.
 * @param validProjects
 *            set of valid projects (the ones given to be ordered)
 * @param preconditionTo
 *            inverse of dependency
 * @param dependency
 *            inverse of preconditionTo
 * @param dependencyfree
 *            - projects which don't depend on others.
 */
private static void recCollect(IN4JSProject p, HashSet<IN4JSProject> visited,
        HashSet<IN4JSProject> validProjects, HashSet<IN4JSProject> unresolvedDependencies,
        HashMultimap<IN4JSProject, IN4JSProject> preconditionTo,
        HashMultimap<IN4JSProject, IN4JSProject> dependency, LinkedList<IN4JSProject> dependencyfree) {

    // already done?
    if (visited.contains(p)) {
        // Cycle detection later ?
        return;
    }
    visited.add(p);

    // build dependencies && inverse dependencies.
    ImmutableList<? extends IN4JSProject> dependencies = p.getDependenciesAndImplementedApis();
    if (dependencies.isEmpty()) {
        dependencyfree.add(p);
    } else {
        for (IN4JSProject dep : dependencies) {
            dependency.put(p, dep);
            preconditionTo.put(dep, p);
            if (!validProjects.contains(dep)) {
                // found a dependency on a project which is not part of the build.
                unresolvedDependencies.add(dep);
            }
            // recursive call:
            recCollect(dep, visited, validProjects, unresolvedDependencies, preconditionTo, dependency,
                    dependencyfree);
        }
    }
}

From source file:com.arpnetworking.tsdcore.sinks.MetricNameFilteringSink.java

/**
 * {@inheritDoc}//from  w  w  w  . j a  v a2s .c  om
 */
@Override
public void recordAggregateData(final PeriodicData periodicData) {
    final ImmutableList.Builder<AggregatedData> filteredDataBuilder = ImmutableList.builder();
    for (final AggregatedData datum : periodicData.getData()) {
        final String metric = datum.getFQDSN().getMetric();
        final Boolean cachedResult = _cachedFilterResult.getUnchecked(metric);
        if (cachedResult) {
            filteredDataBuilder.add(datum);
        }
    }

    final ImmutableList.Builder<Condition> filteredConditionsBuilder = ImmutableList.builder();
    for (final Condition condition : periodicData.getConditions()) {
        final String metric = condition.getFQDSN().getMetric();
        final Boolean cachedResult = _cachedFilterResult.getUnchecked(metric);
        if (cachedResult) {
            filteredConditionsBuilder.add(condition);
        }
    }
    final ImmutableList<AggregatedData> filteredData = filteredDataBuilder.build();
    final ImmutableList<Condition> filteredConditions = filteredConditionsBuilder.build();
    if (!filteredData.isEmpty() || !filteredConditions.isEmpty()) {
        _sink.recordAggregateData(PeriodicData.Builder.clone(periodicData, new PeriodicData.Builder())
                .setData(filteredData).setConditions(filteredConditions).build());
    }
}

From source file:org.locationtech.geogig.api.RevTreeImpl.java

@Override
public Iterator<Node> children() {
    Preconditions.checkState(!buckets().isPresent());
    ImmutableList<Node> trees = trees().or(ImmutableList.<Node>of());
    ImmutableList<Node> features = features().or(ImmutableList.<Node>of());
    if (trees.isEmpty()) {
        return features.iterator();
    }/* ww w.j  ava  2  s .  c om*/
    if (features.isEmpty()) {
        return trees.iterator();
    }
    return Iterators.mergeSorted(ImmutableList.of(trees.iterator(), features.iterator()), ordering);
}

From source file:com.arpnetworking.tsdcore.sinks.ServiceNameFilteringSink.java

/**
 * {@inheritDoc}//from   w  w w .j a  va2  s.c  om
 */
@Override
public void recordAggregateData(final PeriodicData periodicData) {
    final ImmutableList.Builder<AggregatedData> filteredDataBuilder = ImmutableList.builder();
    for (final AggregatedData datum : periodicData.getData()) {
        final String service = datum.getFQDSN().getService();
        final Boolean cachedResult = _cachedFilterResult.getUnchecked(service);
        if (cachedResult) {
            filteredDataBuilder.add(datum);
        }
    }

    final ImmutableList.Builder<Condition> filteredConditionsBuilder = ImmutableList.builder();
    for (final Condition condition : periodicData.getConditions()) {
        final String service = condition.getFQDSN().getService();
        final Boolean cachedResult = _cachedFilterResult.getUnchecked(service);
        if (cachedResult) {
            filteredConditionsBuilder.add(condition);
        }
    }

    final ImmutableList<AggregatedData> filteredData = filteredDataBuilder.build();
    final ImmutableList<Condition> filteredConditions = filteredConditionsBuilder.build();
    if (!filteredData.isEmpty() || !filteredConditions.isEmpty()) {
        _sink.recordAggregateData(PeriodicData.Builder.clone(periodicData, new PeriodicData.Builder())
                .setData(filteredData).setConditions(filteredConditions).build());
    }
}

From source file:org.jclouds.route53.domain.ChangeBatch.java

private ChangeBatch(Optional<String> comment, ImmutableList<ActionOnResourceRecordSet> changes) {
    this.comment = checkNotNull(comment, "comment");
    this.changes = checkNotNull(changes, "changes%s", comment.isPresent() ? " for %s " + comment.get() : "");
    checkArgument(!changes.isEmpty(), "no changes%s", comment.isPresent() ? " for %s " + comment.get() : "");
}

From source file:com.google.javascript.rhino.jstype.TemplateTypeMap.java

/**
 * Concatenates two ImmutableList instances. If either input is empty, the
 * other is returned; otherwise, a new ImmutableList instance is created that
 * contains the contents of both arguments.
 *///  w w w .  j  a v  a  2s .c o m
private <T> ImmutableList<T> concatImmutableLists(ImmutableList<T> first, ImmutableList<T> second) {
    if (first.isEmpty()) {
        return second;
    }
    if (second.isEmpty()) {
        return first;
    }
    ImmutableList.Builder<T> builder = ImmutableList.builder();
    builder.addAll(first);
    builder.addAll(second);
    return builder.build();
}

From source file:org.onosproject.net.intent.impl.ConnectivityIntentCompiler.java

/**
 * Computes a path between two ConnectPoints.
 *
 * @param intent intent on which behalf path is being computed
 * @param one    start of the path//  www  .  j  a v a 2s  .  co m
 * @param two    end of the path
 * @return Path between the two
 * @throws PathNotFoundException if a path cannot be found
 */
protected Path getPath(ConnectivityIntent intent, ElementId one, ElementId two) {
    Set<Path> paths = pathService.getPaths(one, two, weight(intent.constraints()));
    final List<Constraint> constraints = intent.constraints();
    ImmutableList<Path> filtered = FluentIterable.from(paths).filter(new Predicate<Path>() {
        @Override
        public boolean apply(Path path) {
            return checkPath(path, constraints);
        }
    }).toList();
    if (filtered.isEmpty()) {
        throw new PathNotFoundException("No packet path from " + one + " to " + two);
    }
    // TODO: let's be more intelligent about this eventually
    return filtered.iterator().next();
}

From source file:com.squareup.wire.schema.Options.java

/** Returns an object of the same type as {@code o}, or null if it is not retained. */
private Object retainAll(Schema schema, MarkSet markSet, ProtoType type, Object o) {
    if (!markSet.contains(type)) {
        return null; // Prune this type.

    } else if (o instanceof Map) {
        ImmutableMap.Builder<ProtoMember, Object> builder = ImmutableMap.builder();
        for (Map.Entry<?, ?> entry : ((Map<?, ?>) o).entrySet()) {
            ProtoMember protoMember = (ProtoMember) entry.getKey();
            if (!markSet.contains(protoMember))
                continue; // Prune this field.
            Field field = schema.getField(protoMember);
            Object retainedValue = retainAll(schema, markSet, field.type(), entry.getValue());
            if (retainedValue != null) {
                builder.put(protoMember, retainedValue); // This retained field is non-empty.
            }/*www  . ja  v  a2s.  c  o m*/
        }
        ImmutableMap<ProtoMember, Object> map = builder.build();
        return !map.isEmpty() ? map : null;

    } else if (o instanceof List) {
        ImmutableList.Builder<Object> builder = ImmutableList.builder();
        for (Object value : ((List) o)) {
            Object retainedValue = retainAll(schema, markSet, type, value);
            if (retainedValue != null) {
                builder.add(retainedValue); // This retained value is non-empty.
            }
        }
        ImmutableList<Object> list = builder.build();
        return !list.isEmpty() ? list : null;

    } else {
        return o;
    }
}

From source file:com.google.errorprone.bugpatterns.AnnotationPosition.java

private Description handle(Tree tree, Name name, ModifiersTree modifiers, VisitorState state) {
    List<? extends AnnotationTree> annotations = modifiers.getAnnotations();
    if (annotations.isEmpty()) {
        return NO_MATCH;
    }//  w  ww.  j a  va 2 s  .c om

    int treePos = ((JCTree) tree).getStartPosition();
    List<ErrorProneToken> tokens = annotationTokens(tree, state, treePos);
    Comment danglingJavadoc = findOrphanedJavadoc(name, tokens);

    ImmutableList<ErrorProneToken> modifierTokens = tokens.stream().filter(t -> MODIFIERS.contains(t.kind()))
            .collect(toImmutableList());
    if (!modifierTokens.isEmpty()) {
        int firstModifierPos = treePos + modifierTokens.get(0).pos();
        int lastModifierPos = treePos + getLast(modifierTokens).endPos();

        Description description = checkAnnotations(tree, treePos, annotations, danglingJavadoc,
                firstModifierPos, lastModifierPos, state);
        if (!description.equals(NO_MATCH)) {
            return description;
        }
    }
    if (danglingJavadoc != null) {
        SuggestedFix.Builder builder = SuggestedFix.builder();
        String javadoc = removeJavadoc(state, treePos, danglingJavadoc, builder);

        String message = "Javadocs should appear before any modifiers or annotations.";
        return buildDescription(tree).setMessage(message).addFix(builder.prefixWith(tree, javadoc).build())
                .build();
    }
    return NO_MATCH;
}

From source file:org.apache.james.transport.mailets.RecipientRewriteTableProcessor.java

private ImmutableList<Mapping> getAddressWithNoDomain(Mappings mappings, DomainList domainList)
        throws MessagingException {
    ImmutableList<Mapping> addressWithoutDomains = FluentIterable.from(mappings).filter(noneDomain).toList();

    if (!addressWithoutDomains.isEmpty()) {
        final String defaultDomain = getDefaultDomain(domainList);

        return FluentIterable.from(addressWithoutDomains).transform(appendDefaultDomain(defaultDomain))
                .toList();/*from  w w  w. ja  v a  2 s  .  c  o m*/
    }
    return ImmutableList.of();
}