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

brooklyn.entity.basic.EntityPredicates Maven / Gradle / Ivy

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.entity.basic;

import javax.annotation.Nullable;

import brooklyn.entity.Entity;
import brooklyn.event.AttributeSensor;
import brooklyn.location.Location;

import com.google.common.base.Objects;
import com.google.common.base.Predicate;

public class EntityPredicates {

    public static  Predicate idEqualTo(final T val) {
        return new Predicate() {
            @Override
            public boolean apply(@Nullable Entity input) {
                return Objects.equal(input.getId(), val);
            }
        };
    }
    
    public static  Predicate attributeEqualTo(final AttributeSensor attribute, final T val) {
        return new Predicate() {
            @Override
            public boolean apply(@Nullable Entity input) {
                return Objects.equal(input.getAttribute(attribute), val);
            }
        };
    }
    
    /**
     * Create a predicate that matches any entity who has an exact match for the given location
     * (i.e. {@code entity.getLocations().contains(location)}).
     */
    public static  Predicate withLocation(final Location location) {
        return new Predicate() {
            @Override
            public boolean apply(@Nullable Entity input) {
                return (input != null) && input.getLocations().contains(location);
            }
        };
    }
    
    public static  Predicate managed() {
        return new Predicate() {
            @Override
            public boolean apply(@Nullable Entity input) {
                return input != null && Entities.isManaged(input);
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy