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

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

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

import static com.google.common.base.Preconditions.checkNotNull;
import brooklyn.entity.Entity;
import brooklyn.event.AttributeSensor;

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

/**
 * A tuple containing an {@link Entity} and an {@link Attribute}, which is assumed to be present on the entity.
 * 

* Allows retrieval of the attribute {@link #getValue() value} or can be used instead where a {@link Supplier} for * the attribute value is required. */ public class EntityAndAttribute implements Supplier { private final Entity entity; private final AttributeSensor attribute; public EntityAndAttribute(Entity entity, AttributeSensor attribute) { this.entity = checkNotNull(entity, "entity"); this.attribute = checkNotNull(attribute, "attribute"); } public Entity getEntity() { return entity; } public AttributeSensor getAttribute() { return attribute; } public T getValue() { return entity.getAttribute(attribute); } public void setValue(T val) { ((EntityLocal)entity).setAttribute(attribute, val); } /** * {@inheritDoc} * * Returns the current value of the {@link #getAttribute() attribute} on the {@link #getEntity() entity}. * * @see #getValue() */ @Override public T get() { return getValue(); } @Override public String toString() { return Objects.toStringHelper(this) .add("entity", entity) .add("attribute", attribute) .toString(); } @Override public int hashCode() { return Objects.hashCode(entity, attribute); } @Override public boolean equals(Object o) { if (o == null) return false; if (!(o instanceof EntityAndAttribute)) return false; EntityAndAttribute that = (EntityAndAttribute) o; return Objects.equal(this.entity, that.entity) && Objects.equal(this.attribute, that.attribute); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy