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.sirius.diagram.ui.tools.internal.actions.visibility.HideDDiagramElementAction.java

/**
 * {@inheritDoc}//from   www.  j  a  v  a  2s . c o  m
 */
@Override
public final boolean isEnabled() {
    boolean result = false;

    ISelection currentSelection = selection;
    if (selection == null) {
        currentSelection = getCurrentSelection();
    }

    if (currentSelection instanceof IStructuredSelection && !currentSelection.isEmpty()) {
        Collection<DDiagramElement> ddes = Sets.newHashSet();
        for (Object selected : ((IStructuredSelection) currentSelection).toList()) {
            if (selected instanceof IDiagramElementEditPart) {
                IDiagramElementEditPart diagramElementEditPart = (IDiagramElementEditPart) selected;
                if (diagramElementEditPart.isActive()) {
                    DDiagramElement dDiagramElement = diagramElementEditPart.resolveDiagramElement();
                    if (dDiagramElement != null) {
                        ddes.add(dDiagramElement);
                    }
                }
            } else if (selected instanceof DDiagramElement) {
                ddes.add((DDiagramElement) selected);
            }
        }

        if (!ddes.isEmpty()) {
            Predicate<DDiagramElement> allowsHideReveal = allowsHideReveal(
                    ddes.iterator().next().getParentDiagram());
            return Iterables.all(ddes, allowsHideReveal);
        }

    }

    return result;
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.pinning.AbstractPinUnpinElementsEclipseAction.java

/**
 * {@inheritDoc}/*from w  ww. ja v  a2s . com*/
 */
@Override
public final boolean isEnabled() {
    Collection<DDiagramElement> selectedDiagramElements = getSelectedDiagramElements(getCurrentSelection());
    if (!selectedDiagramElements.isEmpty()) {
        Predicate<DDiagramElement> pred = new Predicate<DDiagramElement>() {
            @Override
            public boolean apply(DDiagramElement input) {
                return PinHelper.allowsPinUnpin(input);
            }
        };
        if (Iterables.all(selectedDiagramElements, pred)) {
            return doIsEnabled(selectedDiagramElements);
        }
    }
    return false;
}

From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.AbstractNodeEventResizeSelectionValidator.java

/**
 * Verifies whether the new position/size of the execution would still be
 * valid if we accept the request. In particular, ensures sibling events can
 * not overlap./*from w  w w . ja  va 2 s . c o m*/
 * 
 * @return true if the request is validated to true
 */
protected boolean validateNewBoundsForAllTargets() {
    return Iterables.all(Iterables.filter(request.getEditParts(), ExecutionEditPart.class),
            new Predicate<ExecutionEditPart>() {
                @Override
                public boolean apply(ExecutionEditPart input) {
                    return validateNewBounds(input);
                }
            });
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.layout.provider.AbstractCompositeLayoutProvider.java

/**
 * {@inheritDoc}// ww w.jav  a 2s  .  c o  m
 */
@Override
public Command layoutEditParts(final List selectedObjects, final IAdaptable layoutHint) {
    padder.initializePaddingWithEditParts(selectedObjects);
    extender.startLayouting();

    // Clear the list of elements to keep fixed.
    elementsToKeepFixed.clear();
    // Finds if there are unpinned diagram elements to keep fixed stored in
    // the LayoutHint as a Collection
    if (layoutHint.getAdapter(Collection.class) instanceof ArrayList<?>
            && Iterables.all((ArrayList<?>) layoutHint.getAdapter(Collection.class),
                    validateAllElementInArrayListAreIDiagramElementEditPart)) {
        elementsToKeepFixed = new ArrayList<IDiagramElementEditPart>(
                (ArrayList<IDiagramElementEditPart>) layoutHint.getAdapter(Collection.class));
    }
    // return super.layoutEditParts(selectedObjects, layoutHint);
    Command result = super.layoutEditParts(selectedObjects, layoutHint);

    // Clear the list of elements to keep fixed (to avoid memory leak)
    elementsToKeepFixed.clear();

    return result;

}

From source file:com.eviware.loadui.ui.fx.views.workspace.CreateNewAgentDialog.java

private boolean validateUnique(final String url) {
    return Iterables.all(workspace.getAgents(), new Predicate<AgentItem>() {
        @Override//from  w w  w. ja v a2  s .  c om
        public boolean apply(AgentItem agent) {
            return !Objects.equal(url, filterUrl(agent.getUrl()));
        }
    });
}

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

@Override
public void addBuiltins() {
    add(ComplexNegate.class, CustomMultivariateGaussianNegate.class);
    add(ComplexSubtract.class, CustomMultivariateGaussianSubtract.class);
    add(ComplexSum.class, CustomMultivariateGaussianSum.class);
    add(FiniteFieldAdd.class, CustomFiniteFieldAdd.class);
    add(FiniteFieldMult.class, CustomFiniteFieldConstantMult.class);
    add(FiniteFieldMult.class, CustomFiniteFieldMult.class);
    add(FiniteFieldProjection.class, CustomFiniteFieldProjection.class);
    add(LinearEquation.class, CustomGaussianLinearEquation.class);
    add(MatrixRealJointVectorProduct.class, CustomMultivariateGaussianProduct.class);
    add(Multiplexer.class, CustomMultiplexer.class);
    add(MultivariateNormal.class, CustomMultivariateNormalConstantParameters.class);
    add(Negate.class, CustomGaussianNegate.class);
    add(Normal.class, CustomNormalConstantParameters.class);
    add(Product.class, CustomGaussianProduct.class);
    add(RealJointNegate.class, CustomMultivariateGaussianNegate.class);
    add(RealJointSubtract.class, CustomMultivariateGaussianSubtract.class);
    add(RealJointSum.class, CustomMultivariateGaussianSum.class);
    add(Subtract.class, CustomGaussianSubtract.class);
    add(Sum.class, CustomGaussianSum.class);

    // Backwards compatibility
    add("add", new ISolverFactorCreator<ISolverFactor, SumProductSolverGraph>() {
        @Override/*w  w w  .  j  a  v  a2  s .  com*/
        public ISolverFactor create(Factor factor, SumProductSolverGraph sgraph) {
            // We don't need to implement this using a single creator, but this way we can produce
            // a better error message.
            if (Iterables.all(factor.getSiblings(), VariablePredicates.isUnboundedReal()))
                return new CustomGaussianSum(factor, sgraph);
            if (Iterables.all(factor.getSiblings(), VariablePredicates.isUnboundedRealJoint()))
                return new CustomMultivariateGaussianSum(factor, sgraph);

            throw new SolverFactorCreationException(
                    "Variables must be unbounded and all Real or all RealJoint");
        }
    });
    add("constmult", CustomGaussianProduct.class);
    add("constmult", CustomMultivariateGaussianProduct.class);
    add("finiteFieldAdd", CustomFiniteFieldAdd.class);
    add("finiteFieldMult", CustomFiniteFieldConstantMult.class);
    add("finiteFieldMult", CustomFiniteFieldMult.class);
    add("finiteFieldProjection", CustomFiniteFieldProjection.class);
    add("linear", CustomGaussianLinear.class);
    add("multiplexerCPD", CustomMultiplexer.class);
    add("polynomial", CustomComplexGaussianPolynomial.class);
}

From source file:com.eucalyptus.compute.common.internal.vm.VmVolumeState.java

public boolean eachVolumeAttachment(final Predicate<VmVolumeAttachment> pred) throws NoSuchElementException {
    return Iterables.all(this.attachments, pred);
}

From source file:google.registry.model.ofy.Ofy.java

/**
 * Save, augmented to enroll the saved entities in a commit log and to check that we're not saving
 * virtual entities./* w w  w.j a  va 2  s  .  c  o m*/
 *
 * <p>We only allow this in transactions so commit logs can be written in tandem with the save.
 */
public Saver save() {
    return new AugmentedSaver() {
        @Override
        protected void handleSave(Iterable<?> entities) {
            assertInTransaction();
            checkState(Iterables.all(entities, notNull()), "Can't save a null entity.");
            checkProhibitedAnnotations(entities, NotBackedUp.class, VirtualEntity.class);
            ImmutableMap<Key<?>, ?> keysToEntities = uniqueIndex(entities, OBJECTS_TO_KEYS);
            TRANSACTION_INFO.get().putSaves(keysToEntities);
        }
    };
}

From source file:com.facebook.buck.apple.AppleBinaryDescription.java

@Override
public boolean hasFlavors(ImmutableSet<Flavor> flavors) {
    if (FluentIterable.from(flavors).allMatch(SUPPORTED_FLAVORS::contains)) {
        return true;
    }//from   w w  w .  j  a  v a 2s  .  c  o  m
    ImmutableSet<Flavor> delegateFlavors = ImmutableSet.copyOf(Sets.difference(flavors, NON_DELEGATE_FLAVORS));
    if (swiftDelegate.hasFlavors(delegateFlavors)) {
        return true;
    }
    Collection<ImmutableSortedSet<Flavor>> thinFlavorSets = generateThinDelegateFlavors(delegateFlavors);
    if (thinFlavorSets.size() > 0) {
        return Iterables.all(thinFlavorSets, delegate::hasFlavors);
    } else {
        return delegate.hasFlavors(delegateFlavors);
    }
}

From source file:io.prestosql.orc.checkpoint.Checkpoints.java

public static Map<StreamId, StreamCheckpoint> getStreamCheckpoints(Set<Integer> columns,
        List<OrcType> columnTypes, boolean compressed, int rowGroupId, List<ColumnEncoding> columnEncodings,
        Map<StreamId, Stream> streams, Map<StreamId, List<RowGroupIndex>> columnIndexes)
        throws InvalidCheckpointException {
    // map from (column, sequence) to available StreamKind
    ImmutableSetMultimap.Builder<ColumnAndSequence, StreamKind> streamKindsBuilder = ImmutableSetMultimap
            .builder();//from  ww w. ja  v  a 2  s.com
    for (Stream stream : streams.values()) {
        streamKindsBuilder.put(new ColumnAndSequence(stream.getColumn(), stream.getSequence()),
                stream.getStreamKind());
    }
    SetMultimap<ColumnAndSequence, StreamKind> streamKinds = streamKindsBuilder.build();

    ImmutableMap.Builder<StreamId, StreamCheckpoint> checkpoints = ImmutableMap.builder();
    for (Map.Entry<StreamId, List<RowGroupIndex>> entry : columnIndexes.entrySet()) {
        int column = entry.getKey().getColumn();

        if (!columns.contains(column)) {
            continue;
        }

        int sequence = entry.getKey().getSequence();
        List<Integer> positionsList = entry.getValue().get(rowGroupId).getPositions();

        ColumnEncodingKind columnEncoding = columnEncodings.get(column).getColumnEncoding(sequence)
                .getColumnEncodingKind();
        OrcTypeKind columnType = columnTypes.get(column).getOrcTypeKind();
        Set<StreamKind> availableStreams = streamKinds.get(new ColumnAndSequence(column, sequence));

        ColumnPositionsList columnPositionsList = new ColumnPositionsList(column, sequence, columnType,
                positionsList);
        switch (columnType) {
        case BOOLEAN:
            checkpoints.putAll(getBooleanColumnCheckpoints(column, sequence, compressed, availableStreams,
                    columnPositionsList));
            break;
        case BYTE:
            checkpoints.putAll(getByteColumnCheckpoints(column, sequence, compressed, availableStreams,
                    columnPositionsList));
            break;
        case SHORT:
        case INT:
        case LONG:
        case DATE:
            checkpoints.putAll(getLongColumnCheckpoints(column, sequence, columnEncoding, compressed,
                    availableStreams, columnPositionsList));
            break;
        case FLOAT:
            checkpoints.putAll(getFloatColumnCheckpoints(column, sequence, compressed, availableStreams,
                    columnPositionsList));
            break;
        case DOUBLE:
            checkpoints.putAll(getDoubleColumnCheckpoints(column, sequence, compressed, availableStreams,
                    columnPositionsList));
            break;
        case TIMESTAMP:
            checkpoints.putAll(getTimestampColumnCheckpoints(column, sequence, columnEncoding, compressed,
                    availableStreams, columnPositionsList));
            break;
        case BINARY:
        case STRING:
        case VARCHAR:
        case CHAR:
            checkpoints.putAll(getSliceColumnCheckpoints(column, sequence, columnEncoding, compressed,
                    availableStreams, columnPositionsList));
            break;
        case LIST:
        case MAP:
            checkpoints.putAll(getListOrMapColumnCheckpoints(column, sequence, columnEncoding, compressed,
                    availableStreams, columnPositionsList));
            break;
        case STRUCT:
            checkpoints.putAll(getStructColumnCheckpoints(column, sequence, compressed, availableStreams,
                    columnPositionsList));
            break;
        case DECIMAL:
            checkpoints.putAll(getDecimalColumnCheckpoints(column, sequence, columnEncoding, compressed,
                    availableStreams, columnPositionsList));
            break;
        default:
            throw new IllegalArgumentException("Unsupported column type " + columnType);
        }

        // The DWRF code is not meticulous in the handling of checkpoints.  It appears that for the first row group
        // it will write checkpoints for all streams, but in other cases it will write only the streams that exist.
        // We detect this case by checking that all offsets in the initial position list are zero, and if so, we
        // clear the extra offsets
        if (columnPositionsList.hasNextPosition() && !Iterables.all(positionsList, equalTo(0))) {
            throw new InvalidCheckpointException(format(
                    "Column %s, of type %s, contains %s offset positions, but only %s positions were consumed",
                    column, columnType, positionsList.size(), columnPositionsList.getIndex()));
        }
    }
    return checkpoints.build();
}