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.apache.gobblin.util.executors.IteratorExecutor.java

/**
 * Utility method that checks whether all tasks succeeded from the output of {@link #executeAndGetResults()}.
 * @return true if all tasks succeeded.//w ww.j  av a  2s .  c  om
 */
public static <T> boolean verifyAllSuccessful(List<Either<T, ExecutionException>> results) {
    return Iterables.all(results, new Predicate<Either<T, ExecutionException>>() {
        @Override
        public boolean apply(@Nullable Either<T, ExecutionException> input) {
            return input instanceof Either.Left;
        }
    });
}

From source file:com.bennavetta.appsite.webapi.ContentController.java

/**
 * Given a list of files and their MD5 hashes, calculate which ones are the same on the server, which ones should be uploaded,
 * and which ones should be deleted on the server (via a delete request).
 * @param files//from   w w  w . j  a v a2  s  . co m
 * @return
 */
@RequestMapping(value = "/diff", method = RequestMethod.POST)
@ResponseBody
public DiffResponse calculateDiff(@RequestBody List<DiffFile> files) {
    List<String> same = new ArrayList<>();
    List<String> different = new ArrayList<>();
    List<String> extra = new ArrayList<>();

    for (DiffFile file : files) {
        Resource onServer = Resource.get(file.getPath());
        if (onServer == null) {
            different.add(file.getPath());
            continue;
        }
        if (MessageDigest.isEqual(file.getMd5(), onServer.getMD5())) {
            same.add(file.getPath());
        } else {
            different.add(file.getPath());
        }
    }

    //TODO: find a better way of doing this?
    for (String path : Resource.allResources()) {
        if (!Iterables.all(files, new PathMatches(path))) //add the path to extras if none of the files match it
        {
            extra.add(path);
        }
    }

    DiffResponse response = new DiffResponse();
    response.setDifferent(different);
    response.setExtra(extra);
    response.setSame(same);
    return response;
}

From source file:com.palantir.common.collect.IterableView.java

public boolean all(Predicate<? super T> predicate) {
    return Iterables.all(delegate(), predicate);
}

From source file:org.trnltk.morphology.phonetics.PhoneticsEngine.java

public boolean expectationsSatisfied(final Collection<PhoneticExpectation> phoneticExpectations,
        final SuffixFormSequence _form) {
    if (CollectionUtils.isEmpty(phoneticExpectations))
        return true;

    if (_form == null)
        return false;

    final String suffixFormStr = _form.getSuffixFormStr().trim();

    if (StringUtils.isBlank(suffixFormStr))
        return false;

    return Iterables.all(phoneticExpectations, new Predicate<PhoneticExpectation>() {
        @Override//w w  w  .j a  v  a 2  s  . c om
        public boolean apply(PhoneticExpectation input) {
            return expectationSatisfied(input, suffixFormStr);
        }
    });
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticmi.read.BusinessMappingCardinalityValidator.java

/**{@inheritDoc}**/
@Override//from  w  w  w  .j a  v a 2 s  .c om
protected boolean canValidate(RMetamodel rMetamodel) {
    RStructuredTypeExpression bmType = rMetamodel.findStructuredTypeByPersistentName("BusinessMapping");
    if (bmType == null) {
        return false;
    }

    RRelationshipEndExpression toBp = bmType.findRelationshipEndByPersistentName("businessProcess");
    RRelationshipEndExpression toBu = bmType.findRelationshipEndByPersistentName("businessUnit");
    RRelationshipEndExpression toProd = bmType.findRelationshipEndByPersistentName("product");
    RRelationshipEndExpression toIs = bmType.findRelationshipEndByPersistentName("informationSystemRelease");
    return Iterables.all(Lists.newArrayList(toBp, toBu, toIs, toProd), Predicates.notNull());
}

From source file:com.qcadoo.mes.productionPerShift.util.ProgressPerShiftViewSaver.java

@Transactional
private boolean saveProgressesAndForm(final ViewDefinitionState view,
        final Entity technologyOperationComponent) {
    AwesomeDynamicListComponent progressForDaysADL = (AwesomeDynamicListComponent) view
            .getComponentByReference(PROGRESS_ADL_REF);
    List<Entity> progressForDays = progressForDaysADL.getEntities();
    ProgressType progressType = extractProgressType(view);
    boolean hasCorrections = progressType == ProgressType.CORRECTED;
    List<Entity> savedProgresses = validateAndSaveProgresses(progressForDays,
            technologyOperationComponent.getId(), hasCorrections);
    if (Iterables.all(savedProgresses, IS_VALID)) {
        return tryUpdateTechnologyOperation(view, technologyOperationComponent, hasCorrections,
                savedProgresses);//from  w  ww  .  j  a v a  2s.co m
    } else {
        progressForDaysADL.setFieldValue(savedProgresses);
        showValidationErrors(view, FluentIterable.from(savedProgresses)
                .transformAndConcat(new Function<Entity, Iterable<ErrorMessage>>() {

                    @Override
                    public Iterable<ErrorMessage> apply(final Entity input) {
                        return input.getGlobalErrors();
                    }
                }));
        rollbackCurrentTransaction();
        return false;
    }
}

From source file:eu.interedition.web.metadata.DublinCoreMetadata.java

public boolean isEmpty() {
    return Iterables.all(Lists.newArrayList(title, creator, subject, description, publisher, contributor, date,
            type, format, identifier, source, language), Predicates.isNull());
}

From source file:com.splicemachine.orc.checkpoint.Checkpoints.java

public static Map<StreamId, StreamCheckpoint> getStreamCheckpoints(Set<Integer> columns,
        List<OrcType> columnTypes, CompressionKind compressionKind, int rowGroupId,
        List<ColumnEncoding> columnEncodings, Map<StreamId, Stream> streams,
        Map<Integer, List<RowGroupIndex>> columnIndexes) throws InvalidCheckpointException {
    ImmutableSetMultimap.Builder<Integer, StreamKind> streamKindsBuilder = ImmutableSetMultimap.builder();
    for (Stream stream : streams.values()) {
        streamKindsBuilder.put(stream.getColumn(), stream.getStreamKind());
    }/*from   ww  w . j  a  va  2s  .  co m*/
    SetMultimap<Integer, StreamKind> streamKinds = streamKindsBuilder.build();

    ImmutableMap.Builder<StreamId, StreamCheckpoint> checkpoints = ImmutableMap.builder();
    for (int column : columns) {
        List<Integer> positionsList = columnIndexes.get(column).get(rowGroupId).getPositions();

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

        ColumnPositionsList columnPositionsList = new ColumnPositionsList(column, columnType, positionsList);
        switch (columnType) {
        case BOOLEAN:
            checkpoints.putAll(getBooleanColumnCheckpoints(column, compressionKind, availableStreams,
                    columnPositionsList));
            break;
        case BYTE:
            checkpoints.putAll(
                    getByteColumnCheckpoints(column, compressionKind, availableStreams, columnPositionsList));
            break;
        case SHORT:
        case INT:
        case LONG:
        case DATE:
            checkpoints.putAll(getLongColumnCheckpoints(column, columnEncoding, compressionKind,
                    availableStreams, columnPositionsList));
            break;
        case FLOAT:
            checkpoints.putAll(
                    getFloatColumnCheckpoints(column, compressionKind, availableStreams, columnPositionsList));
            break;
        case DOUBLE:
            checkpoints.putAll(
                    getDoubleColumnCheckpoints(column, compressionKind, availableStreams, columnPositionsList));
            break;
        case TIMESTAMP:
            checkpoints.putAll(getTimestampColumnCheckpoints(column, columnEncoding, compressionKind,
                    availableStreams, columnPositionsList));
            break;
        case BINARY:
        case STRING:
        case VARCHAR:
        case CHAR:
            checkpoints.putAll(getSliceColumnCheckpoints(column, columnEncoding, compressionKind,
                    availableStreams, columnPositionsList));
            break;
        case LIST:
        case MAP:
            checkpoints.putAll(getListOrMapColumnCheckpoints(column, columnEncoding, compressionKind,
                    availableStreams, columnPositionsList));
            break;
        case STRUCT:
            checkpoints.putAll(
                    getStructColumnCheckpoints(column, compressionKind, availableStreams, columnPositionsList));
            break;
        case DECIMAL:
            checkpoints.putAll(getDecimalColumnCheckpoints(column, columnEncoding, compressionKind,
                    availableStreams, columnPositionsList));
            break;
        case UNION:
            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();
}

From source file:org.jclouds.rest.InputParamValidator.java

@SuppressWarnings("unchecked")
private void runPredicatesAgainstArgs(List<Validator<?>> predicates, List<Object> args) {
    for (@SuppressWarnings("rawtypes")
    Validator validator : predicates) {
        Iterables.all(args, validator);
    }//from  ww w . j a v a 2s.c  o  m
}

From source file:org.calrissian.mango.collect.FluentCloseableIterable.java

/**
 * Returns {@code true} if every element in this fluent iterable satisfies the predicate.
 * If this fluent iterable is empty, {@code true} is returned.
 *//*from   w w w . j ava 2  s  .  c  o  m*/
public final boolean allMatch(Predicate<? super T> predicate) {
    return Iterables.all(this, predicate);
}