All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brooklyn.util.collections.CollectionFunctionals Maven / Gradle / Ivy

Go to download

Utility classes and methods developed for Brooklyn but not dependendent on Brooklyn or much else

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.util.collections;

import java.util.Arrays;

import javax.annotation.Nullable;

import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

/** things which it seems should be in guava, but i can't find 
 * @author alex */
public class CollectionFunctionals {

    public static Supplier sizeSupplier(final Iterable collection) {
        return new Supplier() {
            @Override
            public Integer get() {
                return Iterables.size(collection);
            }
        };
    }
    
    /** default guava Equals predicate will reflect order of target, and will fail when matching against a list;
     * this treats them both as sets */
    public static Predicate> equalsSetOf(Object... target) {
        return equalsSet(Arrays.asList(target));
    }
    public static Predicate> equalsSet(final Iterable target) {
        return new Predicate>() {
            @Override
            public boolean apply(@Nullable Iterable input) {
                if (input==null) return false;
                return Sets.newHashSet(target).equals(Sets.newHashSet(input));
            }
        };
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy