Example usage for com.google.common.base Predicates compose

List of usage examples for com.google.common.base Predicates compose

Introduction

In this page you can find the example usage for com.google.common.base Predicates compose.

Prototype

public static <A, B> Predicate<A> compose(Predicate<B> predicate, Function<A, ? extends B> function) 

Source Link

Document

Returns the composition of a function and a predicate.

Usage

From source file:org.apache.brooklyn.util.collections.CollectionFunctionals.java

public static <K> Predicate<Map<K, ?>> mapSizeEquals(int targetSize) {
    return Predicates.compose(Predicates.equalTo(targetSize), CollectionFunctionals.<K>mapSize());
}

From source file:org.sosy_lab.cpachecker.util.AbstractStates.java

public static Iterable<AbstractState> filterLocation(Iterable<AbstractState> pStates, CFANode pLoc) {
    if (pStates instanceof LocationMappedReachedSet) {
        // only do this for LocationMappedReachedSet, not for all ReachedSet,
        // because this method is imprecise for the rest
        return ((LocationMappedReachedSet) pStates).getReached(pLoc);
    }/*from   w w  w  . j  a va  2  s .  c  om*/

    Predicate<AbstractState> statesWithRightLocation = Predicates.compose(equalTo(pLoc), EXTRACT_LOCATION);
    return FluentIterable.from(pStates).filter(statesWithRightLocation);
}

From source file:uk.co.unclealex.executable.generator.scan.ExecutableAnnotationInformationFinderImpl.java

/**
 * Find all {@link Executable} annotations in a list of classes.
 * /*from  w ww  .j a  v a 2 s.co  m*/
 * @param clazz
 *          The class to search.
 * @return A list of all found methods that have an {@link Executable}
 *         annotation.
 * @throws ExecutableScanException
 *           Thrown if there is an error with {@link Executable} annotations
 *           for the given class.
 */
protected List<ExecutableAnnotationInformation> findExecutableAnnotationInformation(Class<?> clazz)
        throws ExecutableScanException {
    Predicate<Method> isAnnotatedPredicate = Predicates.compose(Predicates.not(Predicates.isNull()),
            new ExecutableAnnotationFunction());
    List<Method> annotatedMethods = Lists
            .newArrayList(Iterables.filter(Arrays.asList(clazz.getDeclaredMethods()), isAnnotatedPredicate));
    List<ExecutableAnnotationInformation> executableAnnotationInformations = Lists.newArrayList();
    if (!annotatedMethods.isEmpty()) {
        if (clazz.getEnclosingClass() != null || clazz.isInterface()) {
            throw new NotTopLevelClassExecutableScanException(clazz);
        }
        for (Method annotatedMethod : annotatedMethods) {
            ExecutableAnnotationInformation executableAnnotationInformation = generateExecutableAnnotationInformation(
                    clazz, annotatedMethod);
            executableAnnotationInformations.add(executableAnnotationInformation);
        }
    }
    return executableAnnotationInformations;
}

From source file:com.bigfatgun.fixjures.dao.MyBusinessObjectDAOImpl.java

@Override
public List<MyBusinessObject> findChildren(final MyBusinessObject parent) {
    return Lists.newArrayList(
            getHelper().findAllWhere(Predicates.compose(Predicates.equalTo(parent), EXTRACT_PARENT)));
}

From source file:com.eucalyptus.util.Exceptions.java

public static <T> Predicate<StackTraceElement> stackTraceElementFilter(final List<String> patterns) {
    Function<StackTraceElement, String> toString = toStringFunction();
    return Predicates.compose(makeSteFilter(patterns), toString);
}

From source file:com.google.caliper.memory.ObjectGraphMeasurer.java

/**
 * Measures the footprint of the specified object graph.
 * The object graph is defined by a root object and whatever object can be
 * reached through that, excluding static fields, {@code Class} objects,
 * and fields defined in {@code enum}s (all these are considered shared
 * values, which should not contribute to the cost of any single object
 * graph), and any object for which the user-provided predicate returns
 * {@code false}.//from   ww  w  .j  a  v  a 2  s.  c o  m
 *
 * @param rootObject the root object of the object graph
 * @param objectAcceptor a predicate that returns {@code true} for objects
 * to be explored (and treated as part of the footprint), or {@code false}
 * to forbid the traversal to traverse the given object
 * @return the footprint of the object graph
 */
public static Footprint measure(Object rootObject, Predicate<Object> objectAcceptor) {
    Preconditions.checkNotNull(objectAcceptor, "predicate");

    Predicate<Chain> completePredicate = Predicates.and(
            ImmutableList.of(ObjectExplorer.notEnumFieldsOrClasses, new ObjectExplorer.AtMostOncePredicate(),
                    Predicates.compose(objectAcceptor, ObjectExplorer.chainToObject)));

    return ObjectExplorer.exploreObject(rootObject, new ObjectGraphVisitor(completePredicate),
            EnumSet.of(Feature.VISIT_PRIMITIVES, Feature.VISIT_NULL));
}

From source file:org.sosy_lab.cpachecker.util.AbstractStates.java

public static FluentIterable<AbstractState> filterLocations(Iterable<AbstractState> pStates,
        Set<CFANode> pLocs) {
    if (pStates instanceof LocationMappedReachedSet) {
        // only do this for LocationMappedReachedSet, not for all ReachedSet,
        // because this method is imprecise for the rest
        final LocationMappedReachedSet states = (LocationMappedReachedSet) pStates;
        return from(pLocs).transformAndConcat(new Function<CFANode, Iterable<AbstractState>>() {
            @Override/*from   ww  w .j  av a  2s.c o  m*/
            public Iterable<AbstractState> apply(CFANode location) {
                return states.getReached(location);
            }
        });
    }

    Predicate<AbstractState> statesWithRightLocation = Predicates.compose(in(pLocs), EXTRACT_LOCATION);
    return from(pStates).filter(statesWithRightLocation);
}

From source file:brooklyn.entity.group.DynamicMultiGroupImpl.java

@Override
public void distributeEntities() {
    synchronized (memberChangeMutex) {
        Function<Entity, String> bucketFunction = getConfig(BUCKET_FUNCTION);
        EntitySpec<? extends BasicGroup> bucketSpec = getConfig(BUCKET_SPEC);
        if (bucketFunction == null || bucketSpec == null)
            return;
        Map<String, BasicGroup> buckets = MutableMap.copyOf(getAttribute(BUCKETS));

        // Bucketize the members where the function gives a non-null bucket
        Multimap<String, Entity> entityMapping = Multimaps.index(
                Iterables.filter(getMembers(), Predicates.compose(Predicates.notNull(), bucketFunction)),
                bucketFunction);/*from w  w w  .  j  av a2s. c  o m*/

        // Now fill the buckets
        for (String name : entityMapping.keySet()) {
            BasicGroup bucket = buckets.get(name);
            if (bucket == null) {
                bucket = addChild(EntitySpec.create(bucketSpec).displayName(name));
                Entities.manage(bucket);
                buckets.put(name, bucket);
            }
            bucket.setMembers(entityMapping.get(name));
        }

        // Remove any now-empty buckets
        Set<String> empty = ImmutableSet.copyOf(Sets.difference(buckets.keySet(), entityMapping.keySet()));
        for (String name : empty) {
            Group removed = buckets.remove(name);
            removeChild(removed);
            Entities.unmanage(removed);
        }

        // Save the bucket mappings
        setAttribute(BUCKETS, ImmutableMap.copyOf(buckets));
    }
}

From source file:org.apache.brooklyn.entity.group.DynamicMultiGroupImpl.java

@Override
public void distributeEntities() {
    synchronized (memberChangeMutex) {
        Function<Entity, String> bucketFunction = getConfig(BUCKET_FUNCTION);
        EntitySpec<? extends BasicGroup> bucketSpec = getConfig(BUCKET_SPEC);
        if (bucketFunction == null || bucketSpec == null)
            return;
        Map<String, BasicGroup> buckets = MutableMap.copyOf(getAttribute(BUCKETS));

        // Bucketize the members where the function gives a non-null bucket
        Multimap<String, Entity> entityMapping = Multimaps.index(
                Iterables.filter(getMembers(), Predicates.compose(Predicates.notNull(), bucketFunction)),
                bucketFunction);/*from   w w  w.j  a  va  2  s. c o  m*/

        // Now fill the buckets
        for (String name : entityMapping.keySet()) {
            BasicGroup bucket = buckets.get(name);
            if (bucket == null) {
                bucket = addChild(EntitySpec.create(bucketSpec).displayName(name));
                buckets.put(name, bucket);
            }
            bucket.setMembers(entityMapping.get(name));
        }

        // Remove any now-empty buckets
        Set<String> empty = ImmutableSet.copyOf(Sets.difference(buckets.keySet(), entityMapping.keySet()));
        for (String name : empty) {
            Group removed = buckets.remove(name);
            removeChild(removed);
            Entities.unmanage(removed);
        }

        // Save the bucket mappings
        sensors().set(BUCKETS, ImmutableMap.copyOf(buckets));
    }
}

From source file:com.eucalyptus.autoscaling.common.internal.groups.TerminationPolicyType.java

private static <T> List<AutoScalingInstanceCoreView> filterByPropertyEquality(
        final List<AutoScalingInstanceCoreView> instances, final T target,
        final Function<? super AutoScalingInstanceCoreView, T> propertyFunction) {
    return Lists.newArrayList(
            Iterables.filter(instances, Predicates.compose(Predicates.equalTo(target), propertyFunction)));
}