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

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

Introduction

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

Prototype

public static <T> boolean all(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns true if every element in iterable satisfies the predicate.

Usage

From source file:org.eclipse.buildship.ui.view.task.TaskViewActionStateRules.java

private static boolean canFindRootProjects(List<TaskSelectorNode> nodes) {
    return Iterables.all(nodes, new Predicate<TaskNode>() {

        @Override//  w  ww  .j av a2s .  c  o m
        public boolean apply(TaskNode node) {
            OmniEclipseProject project = node.getParentProjectNode().getEclipseProject();
            Path projectPath = new Path(project.getProjectDirectory().getPath());
            IPath masterPath = projectPath.removeLastSegments(1).append("master");
            Path rootPath = new Path(project.getRoot().getProjectDirectory().getPath());
            return rootPath.isPrefixOf(projectPath) || rootPath.equals(masterPath);
        }
    });
}

From source file:de.cosmocode.palava.media.expire.AssetExpirationService.java

private void checkExpiring() {
    final List<AssetBase> assets = service.list(AssetBase.EXPIRING);
    assert Iterables.all(assets, AssetBase.IS_EXPIRING) : "Expected all assets to be expiring";

    LOG.info("Found {} expiring assets", assets.size());

    for (AssetBase asset : assets) {
        expiredEvent.eventAssetExpired(asset);
    }/*ww  w .j  a  v a  2s.  c o m*/
}

From source file:com.analog.lyric.dimple.solvers.sumproduct.customFactors.CustomNormalConstantParameters.java

/**
 * Utility to indicate whether or not a factor is compatible with the requirements of this custom factor
 * @deprecated as of release 0.08//from  ww  w  . j ava  2s.  c om
 */
@Deprecated
public static boolean isFactorCompatible(Factor factor) {
    FactorFunction factorFunction = factor.getFactorFunction();
    if (!(factorFunction instanceof Normal))
        return false;

    Normal specificFactorFunction = (Normal) factorFunction;

    boolean constantParameters = false;
    if (specificFactorFunction.hasConstantParameters())
        constantParameters = true;
    else if (factor.hasConstantAtIndex(MEAN_PARAMETER_INDEX)
            && factor.hasConstantAtIndex(PRECISION_PARAMETER_INDEX))
        constantParameters = true;

    if (!constantParameters)
        return false;

    return Iterables.all(factor.getSiblings(), VariablePredicates.isUnboundedReal());
}

From source file:com.viadeo.kasper.core.id.DefaultIDTransformer.java

@Override
public Map<ID, ID> to(final Format format, final Collection<ID> ids) {
    checkNotNull(format);//w  ww . j a  v a 2 s  .  c  o m
    checkNotNull(ids);
    checkArgument(Iterables.all(ids, Predicates.notNull()), "Each specified ids must be not null");

    return doConvertAll(format, ids);
}

From source file:org.lenskit.data.history.BasicUserHistory.java

/**
 * {@inheritDoc}//w  w  w  .j av  a  2s.co m
 * <p>This implementation filters into a new {@link BasicUserHistory} backed
 * by an {@link ArrayList}.
 */
@SuppressWarnings("unchecked")
@Override
public <T extends Event> UserHistory<T> filter(Class<T> type) {
    // pre-scan the history to see if we need to copy
    if (Iterables.all(this, Predicates.instanceOf(type))) {
        return (UserHistory<T>) this;
    } else {
        List<T> evts = ImmutableList.copyOf(Iterables.filter(this, type));
        return new BasicUserHistory<>(getUserId(), evts);
    }
}

From source file:org.grouplens.lenskit.data.history.BasicUserHistory.java

/**
 * {@inheritDoc}/*  w w  w  .  j a v  a  2 s .  c o m*/
 * <p>This implementation filters into a new {@link BasicUserHistory} backed
 * by an {@link ArrayList}.
 */
@SuppressWarnings("unchecked")
@Override
public <T extends Event> UserHistory<T> filter(Class<T> type) {
    // pre-scan the history to see if we need to copy
    if (Iterables.all(this, Predicates.instanceOf(type))) {
        return (UserHistory<T>) this;
    } else {
        List<T> evts = ImmutableList.copyOf(Iterables.filter(this, type));
        return new BasicUserHistory<T>(getUserId(), evts);
    }
}

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

@Override
protected boolean canReportCycle(SkyKey topLevelKey, CycleInfo cycleInfo) {
    if (!IS_CONFIGURED_TARGET_SKY_KEY.apply(topLevelKey)) {
        return false;
    }/*from www  .ja v  a  2 s  . c om*/
    Iterable<SkyKey> cycleKeys = Iterables.concat(cycleInfo.getPathToCycle(), cycleInfo.getCycle());
    // Static configurations expect all keys to be ConfiguredTargetValue keys. Dynamic
    // configurations expect the top-level key to be a ConfiguredTargetValue key, but cycles and
    // paths to them can travel through TransitiveTargetValue keys because ConfiguredTargetFunction
    // visits TransitiveTargetFunction as a part of dynamic configuration computation.
    //
    // Unfortunately this class can't easily figure out if we're in static or dynamic configuration
    // mode, so we loosely permit both cases.
    //
    // TODO: remove the static-style checking once dynamic configurations fully replace them
    return Iterables.all(cycleKeys,
            Predicates.<SkyKey>or(IS_CONFIGURED_TARGET_SKY_KEY, IS_TRANSITIVE_TARGET_SKY_KEY));
}

From source file:org.onosproject.net.intent.PathIntent.java

/**
 * Validates that source element ID and destination element ID of a link are
 * different for the specified all links and that destination element ID of a link and source
 * element ID of the next adjacent source element ID are same for the specified all links.
 *
 * @param links links to be validated// w  ww .  ja va2s. c  o m
 */
public static void validate(List<Link> links) {
    checkArgument(Iterables.all(links, link -> !link.src().elementId().equals(link.dst().elementId())),
            "element of src and dst in a link must be different: {}", links);

    boolean adjacentSame = true;
    for (int i = 0; i < links.size() - 1; i++) {
        if (!links.get(i).dst().elementId().equals(links.get(i + 1).src().elementId())) {
            adjacentSame = false;
            break;
        }
    }
    checkArgument(adjacentSame, "adjacent links must share the same element: {}", links);
}

From source file:com.google.devtools.build.lib.query2.TransitiveTraversalValueDTCVisitor.java

@Override
protected Iterable<SkyKey> preprocessInitialVisit(Iterable<SkyKey> keys) {
    // ParallelVisitorCallback passes in TTV keys.
    Preconditions.checkState(Iterables.all(keys, SkyQueryEnvironment.IS_TTV), keys);
    return keys;/*w w  w  .  jav a2 s .c o  m*/
}

From source file:com.qcadoo.mes.materialFlow.hooks.TransformationsModelValidators.java

public boolean checkIfTransfersAreValid(final DataDefinition transformationsDD, final Entity transformations) {
    List<Entity> transfersConsumption = transformations.getHasManyField(TRANSFERS_CONSUMPTION);
    List<Entity> transfersProduction = transformations.getHasManyField(TRANSFERS_PRODUCTION);

    Iterable<Boolean> validationResults = Lists.newArrayList(areTransfersValid(transfersConsumption),
            areTransfersValid(transfersProduction),
            checkIfTransfersNumbersAreDistinct(transfersConsumption, transfersProduction),
            checkIfTransfersNumbersAreDistinct(transfersProduction, transfersConsumption));
    return Iterables.all(validationResults, Predicates.equalTo(true));
}