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.eclipse.xtext.ui.generator.trace.TraceBasedOpenerContributor.java

private void collectOpeners(IEclipseTrace trace, ITextRegion region, IAcceptor<FileOpener> acceptor) {
    Iterable<? extends ILocationInEclipseResource> locations = null;
    if (region != null)
        locations = trace.getAllAssociatedLocations(region);
    if (locations == null || Iterables.isEmpty(locations))
        locations = trace.getAllAssociatedLocations();
    Map<IStorage, ITextRegion> result = Maps.newHashMap();
    for (ILocationInEclipseResource location : locations) {
        IStorage storage = location.getPlatformResource();
        if (storage != null) {
            ITextRegion old = result.put(storage, location.getTextRegion());
            if (old != null) {
                ITextRegion merged = old.merge(location.getTextRegion());
                result.put(storage, merged);
            }/*from w ww .ja v a 2  s.  c  o  m*/
        }
    }
    for (Map.Entry<IStorage, ITextRegion> e : result.entrySet()) {
        IStorage storage = e.getKey();
        ITextRegion textRegion = e.getValue();
        acceptor.accept(createStorageBasedTextEditorOpener(storage, textRegion));
    }
}

From source file:com.b2international.index.revision.DefaultRevisionSearcher.java

@Override
public <T extends Revision> Iterable<T> get(Class<T> type, Iterable<Long> storageKeys) throws IOException {
    if (Iterables.isEmpty(storageKeys)) {
        return Collections.emptySet();
    } else {// ww  w  .  j av  a2 s  .c  o  m
        final Query<T> query = Query.select(type)
                .where(Expressions.matchAnyLong(Revision.STORAGE_KEY, storageKeys))
                .limit(Iterables.size(storageKeys)).build();
        return search(query);
    }
}

From source file:org.tensorics.core.tensor.lang.TensorStructurals.java

/**
 * Merges the given set of the Tensors based on information in their context and dimensions. This operation is only
 * possible, if the following preconditions are fulfilled:
 * <ul>//  w ww. ja v  a2  s . co  m
 * <li>The contexts of all the tensors have THE SAME dimensions AND</li>
 * <li>The dimensions of all the tensors are THE SAME (first found tensor dimension is taken as an reference)</li>
 * </ul>
 * 
 * @param tensors to be merged.
 * @return a merged tensor.
 * @throws IllegalArgumentException if zero or one tensor is put to be merged OR if tensors dimensionality and their
 *             context positions dimensionality is not equal OR tensor context is empty.
 */
public static <E> Tensor<E> merge(Iterable<Tensor<E>> tensors) {
    if (Iterables.isEmpty(tensors) || Iterables.size(tensors) == 1) {
        throw new IllegalArgumentException("Cannot merge empty or one element list of tensors!");
    }
    Tensor<E> firstTensor = tensors.iterator().next();
    Set<Class<?>> refDimensionSet = firstTensor.shape().dimensionSet();
    Position refContextPosition = firstTensor.context();
    Set<Class<?>> outcomeDimensionSet = new HashSet<>(refDimensionSet);
    Set<Class<?>> dimensionSet = refContextPosition.dimensionSet();
    if (dimensionSet.isEmpty()) {
        throw new IllegalArgumentException("Cannot merge tensors with empty context!");
    }
    outcomeDimensionSet.addAll(dimensionSet);
    Builder<E> tensorBuilder = ImmutableTensor.builder(outcomeDimensionSet);

    for (Tensor<E> oneTensor : tensors) {
        if (TensorStructurals.isValidInTermsOfDimensions(oneTensor, refDimensionSet,
                refContextPosition.dimensionSet())) {
            tensorBuilder.putAll(oneTensor.context(), oneTensor);
        } else {
            throw new IllegalArgumentException(
                    "One of the tensors in the provided list does not fit the others on dimensions."
                            + " Cannot continiue merging" + oneTensor);
        }
    }
    return tensorBuilder.build();
}

From source file:io.crate.sql.tree.QualifiedName.java

public QualifiedName(Iterable<String> parts) {
    Preconditions.checkNotNull(parts, "parts");
    Preconditions.checkArgument(!Iterables.isEmpty(parts), "parts is empty");

    this.parts = ImmutableList.copyOf(parts);
}

From source file:com.palantir.atlasdb.jackson.TableRowSelectionDeserializer.java

@Override
public TableRowSelection deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonNode node = jp.readValueAsTree();
    String tableName = node.get("table").textValue();
    TableMetadata metadata = metadataCache.getMetadata(tableName);
    Iterable<byte[]> rows = AtlasDeserializers.deserializeRows(metadata.getRowMetadata(), node.get("rows"));
    Iterable<byte[]> columns = AtlasDeserializers.deserializeNamedCols(metadata.getColumns(), node.get("cols"));
    if (Iterables.isEmpty(columns)) {
        return new TableRowSelection(tableName, rows, ColumnSelection.all());
    } else {//from w  w  w . jav  a2  s  .com
        return new TableRowSelection(tableName, rows, ColumnSelection.create(columns));
    }
}

From source file:com.synflow.cx.resource.CxResourceDescriptionManager.java

@Override
public boolean isAffectedByAny(Collection<Delta> deltas, IResourceDescription candidate,
        IResourceDescriptions context) throws IllegalArgumentException {
    for (Delta delta : deltas) {
        IResourceDescription resDesc = delta.getNew();
        if (resDesc == null) {
            // ignore deleted/closed resources
            continue;
        }/*from   ww  w .  ja va 2  s  . c o m*/

        if (!Iterables.isEmpty(candidate.getExportedObjectsByType(Literals.BUNDLE))) {
            // a candidate is a bundle, is it loaded by the deltas?
            if (isAffected(getImportedNames(resDesc), candidate)) {
                return true;
            }
        }

        // check instantiator to see if necessary to revalidate specialized sub-entities
        for (IEObjectDescription objDesc : resDesc.getExportedObjectsByType(Literals.NETWORK)) {
            CxEntity entity = instantiator.getEntity(objDesc.getEObjectURI());
            if (entity != null) {
                Network network = (Network) entity;
                if (isAffected(network, candidate)) {
                    return true;
                }
            }
        }
    }

    return isAffected(deltas, candidate, context);
}

From source file:org.tensorics.core.iterable.lang.QuantityIterableSupport.java

public final QuantifiedValue<V> rmsOf(Iterable<QuantifiedValue<V>> values) {
    if (Iterables.isEmpty(values)) {
        throw new IllegalArgumentException("Rms of empty value set is not possible.");
    }/*  w ww  . ja v  a  2 s. com*/
    return squareRootOf(calculate(sumOfSquaresOf(values)).dividedBy(sizeOf(values)));
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.repair.DEdgeDiagramElementState.java

/**
 * {@inheritDoc}/*w w w .  j  a  va2  s. c o m*/
 */
@Override
public void storeElementState(EObject target, DiagramElementMapping mapping, DEdge element) {
    super.storeElementState(target, mapping, element);

    Iterable<ArrangeConstraint> existingArrangeConstraints = Iterables.filter(element.getArrangeConstraints(),
            ArrangeConstraint.class);
    if (!Iterables.isEmpty(existingArrangeConstraints)) {
        Iterables.addAll(arrangeConstraints, existingArrangeConstraints);
    }
}

From source file:org.apache.beam.runners.core.metrics.MetricUpdates.java

/** Returns true if there are no updates in this MetricUpdates object. */
public boolean isEmpty() {
    return Iterables.isEmpty(counterUpdates()) && Iterables.isEmpty(distributionUpdates());
}

From source file:com.google.api.server.spi.config.model.ApiFrontendLimitsConfig.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    } else if (o instanceof ApiFrontendLimitsConfig) {
        ApiFrontendLimitsConfig config = (ApiFrontendLimitsConfig) o;
        return Iterables.isEmpty(getConfigurationInconsistencies(config));
    } else {/*from  w w w  . j av  a2s.c o  m*/
        return false;
    }
}