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:org.roda.core.common.iterables.CloseableIterables.java

public static <T> boolean isEmpty(CloseableIterable<T> it) {
    boolean empty = Iterables.isEmpty(it);
    IOUtils.closeQuietly(it);/*from  w w  w .  j ava  2 s.c  o m*/
    return empty;
}

From source file:com.google.devtools.j2objc.gen.TypeImplementationGenerator.java

private void printStaticVars() {
    Iterable<VariableDeclarationFragment> fields = Iterables.filter(getStaticFields(), NEEDS_DEFINITION);
    if (Iterables.isEmpty(fields)) {
        return;/*from  w  ww  . j a va2 s . c  om*/
    }
    newline();
    for (VariableDeclarationFragment fragment : fields) {
        IVariableBinding varBinding = fragment.getVariableBinding();
        Expression initializer = fragment.getInitializer();
        String name = nameTable.getVariableQualifiedName(varBinding);
        String objcType = getDeclarationType(varBinding);
        objcType += objcType.endsWith("*") ? "" : " ";
        if (initializer != null) {
            String cast = !varBinding.getType().isPrimitive() && BindingUtil.isVolatile(varBinding) ? "(void *)"
                    : "";
            printf("%s%s = %s%s;\n", objcType, name, cast, generateExpression(initializer));
        } else {
            printf("%s%s;\n", objcType, name);
        }
    }
}

From source file:org.onos.yangtools.yang.data.api.YangInstanceIdentifier.java

public static YangInstanceIdentifier create(final Iterable<? extends PathArgument> path) {
    if (Iterables.isEmpty(path)) {
        return EMPTY;
    }//from  w w w.j av  a 2 s  .c  om

    final HashCodeBuilder<PathArgument> hash = new HashCodeBuilder<>();
    for (PathArgument a : path) {
        hash.addArgument(a);
    }

    return FixedYangInstanceIdentifier.create(path, hash.build());
}

From source file:org.eclipse.xtext.testing.formatter.FormatterTestHelper.java

protected void assertNoSyntaxErrors(XtextResource resource) {
    Iterable<INode> syntaxErrors = resource.getParseResult().getSyntaxErrors();
    if (!Iterables.isEmpty(syntaxErrors)) {
        StringBuilder builder = new StringBuilder();
        builder.append("This document can't be formatted because of syntax errors:\n");
        for (INode node : syntaxErrors) {
            SyntaxErrorMessage msg = node.getSyntaxErrorMessage();
            builder.append(String.format("Line %02d: %s\n", node.getTotalStartLine(), msg.getMessage()));
        }/*from  w  w w. j  ava 2s . c o m*/
        fail(builder, resource.getParseResult().getRootNode().getText());
    }
}

From source file:org.eclipse.sirius.diagram.ui.graphical.edit.policies.RegionResizableEditPolicy.java

/**
 * Add the collapse handle of the region.
 * /* w w w  .  ja v  a 2  s.  co m*/
 * @param selectionHandles
 *            selection handles
 */
protected void addCollapseHandle(List selectionHandles) {
    EditPart regionContainerPart = getRegionContainerPart();

    // DisableCollapse for Regions whose the RegionContainer is itself a
    // Region.
    if (concernRegion() && regionContainerPart instanceof AbstractDiagramElementContainerEditPart
            && !((AbstractDiagramElementContainerEditPart) regionContainerPart).isRegion()) {
        AbstractDiagramElementContainerEditPart hostPart = (AbstractDiagramElementContainerEditPart) getHost();
        LabelAlignment textAlignment = getTextAlignment(hostPart);
        Iterable<IResizableCompartmentEditPart> compartmentParts = Iterables.filter(hostPart.getChildren(),
                IResizableCompartmentEditPart.class);
        if (new EditPartQuery(hostPart).getDrawerStyle() != null && !Iterables.isEmpty(compartmentParts)) {
            selectionHandles
                    .add(new RegionCollapseHandle(compartmentParts.iterator().next(), textAlignment, hostPart));
        }
    }
}

From source file:com.google.devtools.build.lib.skyframe.GraphBackedRecursivePackageProvider.java

@Override
public Map<PackageIdentifier, Package> bulkGetPackages(EventHandler eventHandler,
        Iterable<PackageIdentifier> pkgIds) throws NoSuchPackageException, InterruptedException {
    Set<SkyKey> pkgKeys = ImmutableSet.copyOf(PackageValue.keys(pkgIds));

    ImmutableMap.Builder<PackageIdentifier, Package> pkgResults = ImmutableMap.builder();
    Map<SkyKey, SkyValue> packages = graph.getSuccessfulValues(pkgKeys);
    for (Map.Entry<SkyKey, SkyValue> pkgEntry : packages.entrySet()) {
        PackageIdentifier pkgId = (PackageIdentifier) pkgEntry.getKey().argument();
        PackageValue pkgValue = (PackageValue) pkgEntry.getValue();
        pkgResults.put(pkgId, Preconditions.checkNotNull(pkgValue.getPackage(), pkgId));
    }// www  . ja  v a2s  .co m

    SetView<SkyKey> unknownKeys = Sets.difference(pkgKeys, packages.keySet());
    if (!Iterables.isEmpty(unknownKeys)) {
        LOGGER.warning("Unable to find " + unknownKeys + " in the batch lookup of " + pkgKeys
                + ". Successfully looked up " + packages.keySet());
    }
    for (Map.Entry<SkyKey, Exception> missingOrExceptionEntry : graph.getMissingAndExceptions(unknownKeys)
            .entrySet()) {
        PackageIdentifier pkgIdentifier = (PackageIdentifier) missingOrExceptionEntry.getKey().argument();
        Exception exception = missingOrExceptionEntry.getValue();
        if (exception == null) {
            // If the package key does not exist in the graph, then it must not correspond to any
            // package, because the SkyQuery environment has already loaded the universe.
            throw new BuildFileNotFoundException(pkgIdentifier, "Package not found");
        }
        Throwables.propagateIfInstanceOf(exception, NoSuchPackageException.class);
        Throwables.propagate(exception);
    }
    return pkgResults.build();
}

From source file:org.apache.cassandra.db.compaction.LeveledCompactionStrategy.java

@SuppressWarnings("resource")
public synchronized Collection<AbstractCompactionTask> getMaximalTask(int gcBefore, boolean splitOutput) {
    Iterable<SSTableReader> sstables = manifest.getAllSSTables();

    Iterable<SSTableReader> filteredSSTables = filterSuspectSSTables(sstables);
    if (Iterables.isEmpty(sstables))
        return null;
    LifecycleTransaction txn = cfs.getTracker().tryModify(filteredSSTables, OperationType.COMPACTION);
    if (txn == null)
        return null;
    return Arrays.<AbstractCompactionTask>asList(
            new LeveledCompactionTask(cfs, txn, 0, gcBefore, getMaxSSTableBytes(), true));

}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.ReflectiveJavaTypeWidget.java

@Override
public boolean hasProperties() {
    if (Iterable.class.isAssignableFrom(clazz)) {
        return false;
    }//w  w  w  . ja va 2s .  c  om
    PropertyAdapter properties = resolveProperties();
    if (properties == null) {
        return false;
    }
    if (properties.isClosed() && Iterables.isEmpty(properties.getProperties())) {
        return false;
    }
    return true;
}

From source file:com.qcadoo.mes.productionPerShift.dataProvider.ProgressForDayDataProvider.java

public EntityOpResult delete(final Iterable<Long> ids) {
    if (Iterables.isEmpty(ids)) {
        return EntityOpResult.successfull();
    }//from   w w w  .j  a  va2 s .  co m
    return getPfdDataDefinition().delete(FluentIterable.from(ids).toArray(Long.class));
}

From source file:org.apache.giraph.job.CombinedWorkerProgress.java

/**
 * Constructor/*from  w w  w . j  a v  a2s. c o m*/
 *
 * @param workerProgresses Worker progresses to combine
 * @param conf Configuration
 */
public CombinedWorkerProgress(Iterable<WorkerProgress> workerProgresses, Configuration conf) {
    normalFreeMemoryFraction = NORMAL_FREE_MEMORY_FRACTION.get(conf);
    for (WorkerProgress workerProgress : workerProgresses) {
        if (workerProgress.getCurrentSuperstep() > currentSuperstep) {
            verticesToCompute = 0;
            verticesComputed = 0;
            partitionsToCompute = 0;
            partitionsComputed = 0;
            currentSuperstep = workerProgress.getCurrentSuperstep();
            workersInSuperstep = 0;
        }

        if (workerProgress.getCurrentSuperstep() == currentSuperstep) {
            workersInSuperstep++;
            if (isInputSuperstep()) {
                verticesLoaded += workerProgress.getVerticesLoaded();
                vertexInputSplitsLoaded += workerProgress.getVertexInputSplitsLoaded();
                edgesLoaded += workerProgress.getEdgesLoaded();
                edgeInputSplitsLoaded += workerProgress.getEdgeInputSplitsLoaded();
            } else if (isComputeSuperstep()) {
                verticesToCompute += workerProgress.getVerticesToCompute();
                verticesComputed += workerProgress.getVerticesComputed();
                partitionsToCompute += workerProgress.getPartitionsToCompute();
                partitionsComputed += workerProgress.getPartitionsComputed();
            } else if (isOutputSuperstep()) {
                verticesToStore += workerProgress.getVerticesToStore();
                verticesStored += workerProgress.getVerticesStored();
                partitionsToStore += workerProgress.getPartitionsToStore();
                partitionsStored += workerProgress.getPartitionsStored();
            }
        }

        if (workerProgress.isStoringDone()) {
            workersDone++;
        }

        if (workerProgress.getFreeMemoryMB() < minFreeMemoryMB) {
            minFreeMemoryMB = workerProgress.getFreeMemoryMB();
            workerWithMinFreeMemory = workerProgress.getTaskId();
        }
        minFreeMemoryFraction = Math.min(minFreeMemoryFraction, workerProgress.getFreeMemoryFraction());
        freeMemoryMB += workerProgress.getFreeMemoryMB();
        int percentage = workerProgress.getLowestGraphPercentageInMemory();
        if (percentage < minGraphPercentageInMemory) {
            minGraphPercentageInMemory = percentage;
            workerWithMinGraphPercentageInMemory = workerProgress.getTaskId();
        }
    }
    if (!Iterables.isEmpty(workerProgresses)) {
        freeMemoryMB /= Iterables.size(workerProgresses);
    }
}