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:com.eucalyptus.vm.VmInstance.java

/**
 *
 *//*from   www  .  ja  v  a 2 s  . co  m*/
public boolean eachVolumeAttachment(final Predicate<VmVolumeAttachment> predicate) {
    if (VmStateSet.DONE.contains(this.getState())
            && !VmStateSet.EXPECTING_TEARDOWN.contains(this.getLastState())) {
        return false;
    } else {
        final EntityTransaction db = Entities.get(VmInstance.class);
        try {
            final VmInstance entity = Entities.merge(this);
            Set<VmVolumeAttachment> persistentAttachments = Sets
                    .newHashSet(entity.getBootRecord().getPersistentVolumes());
            boolean ret = Iterables.all(persistentAttachments, new Predicate<VmVolumeAttachment>() {

                @Override
                public boolean apply(final VmVolumeAttachment arg0) {
                    return predicate.apply(arg0);
                }
            });

            ret |= entity.getTransientVolumeState().eachVolumeAttachment(new Predicate<VmVolumeAttachment>() {

                @Override
                public boolean apply(final VmVolumeAttachment arg0) {
                    return predicate.apply(arg0);
                }
            });
            db.commit();
            return ret;
        } catch (final Exception ex) {
            Logs.extreme().error(ex, ex);
            db.rollback();
            return false;
        }
    }
}