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:eu.numberfour.n4js.external.RebuildWorkspaceProjectsScheduler.java

/**
 * Schedules a build with the given projects. Does nothing if the {@link Platform platform} is not running, or the
 * iterable of projects is empty.//  ww w  .  j  a  va 2  s .c o m
 *
 * @param toUpdate
 *            an iterable of projects to build.
 */
public void scheduleBuildIfNecessary(final Iterable<IProject> toUpdate) {
    if (Platform.isRunning() && !Iterables.isEmpty(toUpdate)) {
        final Workspace workspace = (Workspace) ResourcesPlugin.getWorkspace();
        final IBuildConfiguration[] projectsToReBuild = from(asList(workspace.getBuildOrder()))
                .filter(config -> Iterables.contains(toUpdate, config.getProject()))
                .toArray(IBuildConfiguration.class);

        if (!Arrays2.isEmpty(projectsToReBuild)) {
            new RebuildWorkspaceProjectsJob(projectsToReBuild).schedule();
        }
    }
}

From source file:org.apache.brooklyn.core.config.ConfigConstraints.java

/**
 * Checks all constraints of all config keys available to an entity.
 * <p>/*from  w w  w. j a  v  a2  s  .c om*/
 * If a constraint is a {@link BrooklynObjectPredicate} then
 * {@link BrooklynObjectPredicate#apply(Object, BrooklynObject)} will be used.
 */
public static void assertValid(Entity entity) {
    Iterable<ConfigKey<?>> violations = new EntityConfigConstraints(entity).getViolations();
    if (!Iterables.isEmpty(violations)) {
        throw new ConstraintViolationException(errorMessage(entity, violations));
    }
}

From source file:com.google.code.jgntp.internal.message.read.GntpMessageResponseParser.java

public GntpMessageResponse parse(String s) {
    Iterable<String> splitted = separatorSplitter.split(s);
    Preconditions.checkState(!Iterables.isEmpty(splitted), "Empty message received from Growl");

    Iterator<String> iter = splitted.iterator();
    String statusLine = iter.next();
    Preconditions.checkState(// w ww. j ava 2  s  .  co  m
            statusLine.startsWith(GntpMessage.PROTOCOL_ID + "/" + GntpVersion.ONE_DOT_ZERO.toString()),
            "Unknown protocol version");

    Iterable<String> statusLineIterable = statusLineSplitter.split(statusLine);
    String messageTypeText = Iterables.get(statusLineIterable, 1).substring(1);
    GntpMessageType messageType = GntpMessageType.valueOf(messageTypeText);

    Map<String, String> headers = Maps.newHashMap();
    while (iter.hasNext()) {
        String[] splittedHeader = iter.next().split(":", 2);
        headers.put(splittedHeader[0], splittedHeader[1].trim());
    }

    switch (messageType) {
    case OK:
        return createOkMessage(headers);
    case CALLBACK:
        return createCallbackMessage(headers);
    case ERROR:
        return createErrorMessage(headers);
    default:
        throw new IllegalStateException("Unknown response message type: " + messageType);
    }
}

From source file:google.registry.util.DateTimeUtils.java

/** Returns the latest element in a {@link DateTime} iterable. */
public static DateTime latestOf(Iterable<DateTime> dates) {
    checkArgument(!Iterables.isEmpty(dates));
    return Ordering.<DateTime>natural().max(dates);
}

From source file:org.eclipse.xtext.ui.editor.outline.impl.OutlineFilterAndSorter.java

public IOutlineNode[] filterAndSort(Iterable<IOutlineNode> nodes) {
    final Iterable<IFilter> enabledFilters = getEnabledFilters();
    Iterable<IOutlineNode> filteredNodes = null;
    if (Iterables.isEmpty(enabledFilters)) {
        filteredNodes = nodes;//from   w  w  w  .  ja  v  a 2  s  .com
    } else {
        filteredNodes = Iterables.filter(nodes, new Predicate<IOutlineNode>() {
            @Override
            public boolean apply(final IOutlineNode node) {
                return Iterables.all(enabledFilters, new Predicate<IFilter>() {
                    @Override
                    public boolean apply(IFilter filter) {
                        return filter.apply(node);
                    }
                });
            }
        });
    }
    IOutlineNode[] nodesAsArray = Iterables.toArray(filteredNodes, IOutlineNode.class);
    if (comparator != null && isSortingEnabled())
        Arrays.sort(nodesAsArray, comparator);
    return nodesAsArray;
}

From source file:org.janusgraph.testutil.JanusGraphAssert.java

public static boolean isEmpty(Object obj) {
    Preconditions.checkArgument(obj != null);
    if (obj instanceof Traversal)
        return !((Traversal) obj).hasNext();
    else if (obj instanceof Collection)
        return ((Collection) obj).isEmpty();
    else if (obj instanceof Iterable)
        return Iterables.isEmpty((Iterable) obj);
    else if (obj instanceof Iterator)
        return !((Iterator) obj).hasNext();
    else if (obj.getClass().isArray())
        return Array.getLength(obj) == 0;
    throw new IllegalArgumentException("Cannot determine size of: " + obj);
}

From source file:org.jpmml.evaluator.TargetUtil.java

/**
 * Evaluates the {@link Targets} element for {@link MiningFunctionType#REGRESSION regression} models.
 *//*ww w  . j a va  2 s .co  m*/
static public Map<FieldName, ? extends Number> evaluateRegression(Map<FieldName, ? extends Number> predictions,
        ModelEvaluationContext context) {
    ModelEvaluator<?> modelEvaluator = context.getModelEvaluator();

    Targets targets = modelEvaluator.getTargets();
    if (targets == null || Iterables.isEmpty(targets)) {
        return predictions;
    }

    Map<FieldName, Number> result = Maps.newLinkedHashMap();

    Collection<? extends Map.Entry<FieldName, ? extends Number>> entries = predictions.entrySet();
    for (Map.Entry<FieldName, ? extends Number> entry : entries) {
        FieldName key = entry.getKey();
        Number value = entry.getValue();

        Target target = modelEvaluator.getTarget(key);
        if (target != null) {

            if (value == null) {
                value = getDefaultValue(target);
            } // End if

            if (value != null) {
                value = processValue(target, value);
            }
        }

        result.put(key, value);
    }

    return result;
}

From source file:uk.gov.gchq.koryphe.impl.function.IsEmpty.java

@Override
@SuppressFBWarnings(value = "DE_MIGHT_IGNORE", justification = "Any exceptions are to be ignored")
public Boolean apply(final Iterable input) {
    if (null == input) {
        throw new IllegalArgumentException("Input cannot be null");
    }//  w  w  w.  j  a v a2s .c  o  m
    try {
        return Iterables.isEmpty(input);
    } finally {
        CloseableUtil.close(input);
    }
}

From source file:org.apache.abdera2.ext.license.LicenseHelper.java

private static boolean contains(Iterable<Link> list) {
    if (list == null)
        return false;
    return !Iterables.isEmpty(list);
}

From source file:google.registry.tools.CheckSnapshotCommand.java

@Override
public void run() throws Exception {
    Iterable<DatastoreBackupInfo> backups = DatastoreBackupService.get().findAllByNamePrefix(snapshotName);
    if (Iterables.isEmpty(backups)) {
        System.err.println("No snapshot found with name: " + snapshotName);
        return;/*from   w  ww . j a va 2s  .  c o m*/
    }
    for (DatastoreBackupInfo backup : backups) {
        System.out.println(backup.getInformation());
    }
}