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

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

Introduction

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

Prototype

public static boolean isEmpty(Iterable<?> iterable) 

Source Link

Document

Determines if the given iterable contains no elements.

Usage

From source file:msi.gaml.descriptions.ActionDescription.java

@SuppressWarnings("rawtypes")
public boolean verifyArgs(final IDescription caller, final Arguments args) {
    final Arguments names = args == null ? NULL_ARGS : args;
    final Iterable<IDescription> formalArgs = getFormalArgs();
    final boolean noArgs = names.isEmpty();
    if (noArgs) {
        final Iterable<IDescription> formalArgsWithoutDefault = Iterables.filter(formalArgs,
                each -> !each.hasFacet(DEFAULT));
        if (Iterables.isEmpty(formalArgsWithoutDefault)) {
            return true;
        }/*from www .  java  2 s  .  c o m*/
    }

    final List<String> allArgs = getArgNames();
    if (caller.getKeyword().equals(DO) || caller.getKeyword().equals(INVOKE)) {
        // If the names were not known at the time of the creation of the
        // caller, only the order
        if (names.containsKey("0")) {
            int index = 0;
            for (final String the_name : allArgs) {
                final String key = String.valueOf(index++);
                final IExpressionDescription old = names.get(key);
                if (old != null) {
                    names.put(the_name, old);
                    names.remove(key);
                }
            }
        }
    }

    // We compute the list of mandatory args

    if (formalArgs != null) {
        for (final IDescription c : formalArgs) {
            final String n = c.getName();
            if (c.hasFacet(DEFAULT)) {
                // AD: we compile the default (which is, otherwise, not
                // computed before validation
                c.getFacet(DEFAULT).compile(this);
                continue;
            }
            if (c.hasFacet(OPTIONAL) && c.getFacet(OPTIONAL).equalsString(FALSE) || !c.hasFacet(OPTIONAL)) {
                if (!names.containsKey(n)) {
                    caller.error(
                            "Missing argument " + n + " in call to " + getName() + ". Arguments passed are : "
                                    + names,
                            IGamlIssue.MISSING_ARGUMENT, caller.getUnderlyingElement(null), new String[] { n });
                    return false;
                }

            }
        }
    }

    for (final Map.Entry<String, IExpressionDescription> arg : names.entrySet()) {
        // A null value indicates a previous compilation error in the
        // arguments
        if (arg != null) {
            final String the_name = arg.getKey();
            if (!allArgs.contains(the_name)) {
                caller.error("Unknown argument " + the_name + " in call to " + getName(),
                        IGamlIssue.UNKNOWN_ARGUMENT, arg.getValue().getTarget(), new String[] { arg.getKey() });
                return false;
            } else if (arg.getValue() != null && arg.getValue().getExpression() != null) {
                final IDescription formalArg = Iterables.find(formalArgs,
                        input -> input.getName().equals(the_name));
                final IType<?> formalType = formalArg.getGamlType();
                final IType<?> callerType = arg.getValue().getExpression().getGamlType();
                if (Types.intFloatCase(formalType, callerType)) {
                    caller.warning("The argument " + the_name + " (of type " + callerType
                            + ") will be casted to " + formalType, IGamlIssue.WRONG_TYPE,
                            arg.getValue().getTarget());
                } else {
                    boolean accepted = formalType == Types.NO_TYPE || callerType.isTranslatableInto(formalType);
                    accepted = accepted || callerType == Types.NO_TYPE && formalType.getDefault() == null;
                    if (!accepted) {
                        caller.error("The type of argument " + the_name + " should be " + formalType,
                                IGamlIssue.WRONG_TYPE, arg.getValue().getTarget());
                        return false;
                    }
                }
            }
        }
    }
    return true;
}

From source file:com.smoketurner.notification.application.core.UserNotifications.java

public boolean isEmpty() {
    return Iterables.isEmpty(unseen) && Iterables.isEmpty(seen);
}

From source file:com.facebook.presto.serde.BlocksFileWriter.java

public BlocksFileWriter append(Iterable<Tuple> tuples) {
    Preconditions.checkNotNull(tuples, "tuples is null");
    if (!Iterables.isEmpty(tuples)) {
        if (encoder == null) {
            open();//from   w w  w  .ja va 2  s.c  o m
        }
        statsBuilder.process(tuples);
        encoder.append(tuples);
    }
    return this;
}

From source file:de.viadee.rules.Conclusions.java

/**
 * <p>/* w ww . j av  a2s .c o  m*/
 * Creates a new {@link Conclusion} which encapsulates all given conclusions.
 * </p>
 * 
 * @param <T>           The topic of the inference process.
 * @param conclusions   The conclusions to group (<b>may not be <code>null</code> nor empty</b>).
 * @return              A new conclusion builder.
 */
public static <T> Conclusion<T> conclude(final Iterable<? extends Conclusion<T>> conclusions) {
    // Check inputs
    Preconditions.checkNotNull(conclusions);
    Preconditions.checkArgument(!Iterables.isEmpty(conclusions));

    // Create composition
    return new CompositeConclusion<T>(ImmutableList.copyOf(conclusions));
}

From source file:org.apache.beam.sdk.transforms.windowing.OutputTimeFns.java

/**
 * Applies the given {@link OutputTimeFn} to the given output times, obtaining
 * the output time for a value computed. See {@link OutputTimeFn#combine} for
 * a full specification.//from   ww  w  . j a v  a2 s  .co m
 *
 * @throws IllegalArgumentException if {@code outputTimes} is empty.
 */
public static Instant combineOutputTimes(OutputTimeFn<?> outputTimeFn,
        Iterable<? extends Instant> outputTimes) {
    checkArgument(!Iterables.isEmpty(outputTimes),
            "Collection of output times must not be empty in %s.combineOutputTimes",
            OutputTimeFns.class.getName());

    @Nullable
    Instant combinedOutputTime = null;
    for (Instant outputTime : outputTimes) {
        combinedOutputTime = combinedOutputTime == null ? outputTime
                : outputTimeFn.combine(combinedOutputTime, outputTime);
    }
    return combinedOutputTime;
}

From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.layout.SequenceGraphicalHelper.java

/**
 * Finds and returns the InstanceRole semantic element which corresponds to
 * the first element graphically above the specified X coordinate in a
 * diagram.//from   ww w. j  av  a  2 s.  c  om
 * 
 * @param diagram
 *            the diagram.
 * @param x
 *            the X coordinate (in logical space)
 * @return the element which corresponds to the first InstanceRole above X.
 */
public static EObject getInstanceRoleBefore(SequenceDDiagram diagram, int x) {
    Iterable<Diagram> diagramViews = Iterables.filter(
            ISequenceElementAccessor.getViewsForSemanticElement(diagram, diagram.getTarget()), Diagram.class);
    if (!Iterables.isEmpty(diagramViews)) {
        Option<SequenceDiagram> seqDiag = ISequenceElementAccessor
                .getSequenceDiagram(diagramViews.iterator().next());
        if (seqDiag.some()) {
            for (InstanceRole ir : Lists.reverse(seqDiag.get().getSortedInstanceRole())) {
                int pos = ir.getProperLogicalBounds().x;
                if (pos <= x) {
                    return ir.getSemanticTargetElement().get();
                }
            }
        }
    }
    return null;
}

From source file:com.facebook.buck.features.go.GoPackStep.java

private boolean shouldSkipPacking() {
    // We need to verify that we don't have any cgo compiled
    // sources coming in before skipping. Those need to be packed.
    boolean cgoSourcesExist = false;
    for (int i = 0; i < srcs.size(); i++) {
        Path path = srcs.get(i);/*from   www . j av a  2s .co m*/
        if (path.toString().contains("cgo-second-step")) {
            cgoSourcesExist = true;
            break;
        }
    }
    return Iterables.isEmpty(filteredAsmSrcs) && !cgoSourcesExist;
}

From source file:com.google.gerrit.server.util.RegexListSearcher.java

public boolean hasMatch(List<T> list) {
    return !Iterables.isEmpty(search(list));
}

From source file:com.google.cloud.dataflow.sdk.util.StateFetcher.java

public Map<CodedTupleTag<?>, Optional<?>> fetch(String computation, ByteString key, long workToken,
        String prefix, Iterable<? extends CodedTupleTag<?>> tags) throws CoderException, IOException {
    if (Iterables.isEmpty(tags)) {
        return Collections.emptyMap();
    }/*from   ww w. j  av a2  s  .co m*/

    Windmill.KeyedGetDataRequest.Builder requestBuilder = Windmill.KeyedGetDataRequest.newBuilder().setKey(key)
            .setWorkToken(workToken);

    Map<ByteString, CodedTupleTag<?>> tagMap = new HashMap<>();
    for (CodedTupleTag<?> tag : tags) {
        ByteString tagString = ByteString.copyFromUtf8(prefix + tag.getId());
        if (tagMap.put(tagString, tag) == null) {
            requestBuilder.addValuesToFetch(Windmill.TagValue.newBuilder().setTag(tagString).build());
        }
    }

    Map<CodedTupleTag<?>, Optional<?>> resultMap = new HashMap<>();
    Windmill.KeyedGetDataResponse keyResponse = getResponse(computation, key, requestBuilder);

    for (Windmill.TagValue tv : keyResponse.getValuesList()) {
        CodedTupleTag<?> tag = tagMap.get(tv.getTag());
        if (tag != null) {
            if (tv.getValue().hasData() && !tv.getValue().getData().isEmpty()) {
                Object v = tag.getCoder().decode(tv.getValue().getData().newInput(), Coder.Context.OUTER);
                resultMap.put(tag, Optional.of(v));
            } else {
                resultMap.put(tag, Optional.absent());
            }
        }
    }

    for (CodedTupleTag<?> tag : tags) {
        if (!resultMap.containsKey(tag)) {
            resultMap.put(tag, Optional.absent());
        }
    }

    return resultMap;
}

From source file:org.apache.beam.runners.dataflow.worker.DataflowProcessFnRunner.java

private static <T> BoundedWindow getUnderlyingWindow(KeyedWorkItem<byte[], T> kwi) {
    if (Iterables.isEmpty(kwi.elementsIterable())) {
        // ProcessFn sets only a single timer.
        TimerData timer = Iterables.getOnlyElement(kwi.timersIterable());
        return ((WindowNamespace) timer.getNamespace()).getWindow();
    } else {//from  w ww .j  av a  2 s  .co m
        // KWI must have a single element in elementsIterable, because it follows a GBK by a
        // uniquely generated key.
        // Additionally, windows must be exploded before GBKIntoKeyedWorkItems, so there's also
        // only a single window.
        WindowedValue<T> value = Iterables.getOnlyElement(kwi.elementsIterable());
        return Iterables.getOnlyElement(value.getWindows());
    }
}