public abstract class AbstractEntity extends java.lang.Object implements Entity, Describable
Base class to make it easier to implement entities.
Modifier and Type | Field and Description |
---|---|
protected long |
id |
protected EntityType |
type |
Modifier | Constructor and Description |
---|---|
protected |
AbstractEntity(EntityType t,
long eid) |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
asMap()
View this entity as a map.
|
void |
describeTo(DescriptionWriter writer)
Write this class’s description to a sink.
|
boolean |
equals(java.lang.Object obj) |
java.lang.Object |
get(java.lang.String attr)
Get the value of an attribute by name.
|
<T> T |
get(TypedName<T> name)
Get the value of an attribute.
|
java.util.Set<java.lang.String> |
getAttributeNames()
Get the names of the attributes in this entity.
|
java.util.Collection<Attribute<?>> |
getAttributes()
Get the attribute-value pairs.
|
boolean |
getBoolean(TypedName<java.lang.Boolean> name)
Get the value of a attr that contains a boolean.
|
double |
getDouble(TypedName<java.lang.Double> name)
Get the value of a attr that contains a double.
|
long |
getId()
Get the identifier of this entity.
|
int |
getInteger(TypedName<java.lang.Integer> name)
Get the value of a attr that contains a int.
|
long |
getLong(TypedName<java.lang.Long> name)
Get the value of a attribute that contains a long.
|
EntityType |
getType()
Get the type of this entity.
|
boolean |
hasAttribute(TypedName<?> name)
Check if the entity has a attribute.
|
int |
hashCode() |
<T> T |
maybeGet(TypedName<T> name)
Get the value of a possibly-missing attribute.
|
java.lang.String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getTypedAttributeNames, hasAttribute, maybeGet
protected final EntityType type
protected final long id
protected AbstractEntity(EntityType t, long eid)
@EntityAttribute(value="id") public long getId()
Entity
Get the identifier of this entity.
public EntityType getType()
Entity
Get the type of this entity.
public boolean hasAttribute(TypedName<?> name)
Check if the entity has a attribute.
This implementation delegates to Entity.hasAttribute(String)
hasAttribute
in interface Entity
name
- The attribute name to look for.true
if the entity contains attribute
and the value is of the associated type.public java.util.Set<java.lang.String> getAttributeNames()
Get the names of the attributes in this entity.
Delegates to Entity.getTypedAttributeNames()
and extracts the names.
getAttributeNames
in interface Entity
public java.util.Collection<Attribute<?>> getAttributes()
Get the attribute-value pairs.
Delegates to Entity.getTypedAttributeNames()
and extracts the names.
getAttributes
in interface Entity
public java.util.Map<java.lang.String,java.lang.Object> asMap()
Entity
View this entity as a map.
@Nonnull public <T> T get(TypedName<T> name)
Get the value of an attribute.
This implementation delegates to maybeGet(TypedName)
.
@Nonnull public java.lang.Object get(java.lang.String attr)
Get the value of an attribute by name.
This implementation delegates to Entity.maybeGet(String)
.
public long getLong(TypedName<java.lang.Long> name)
Get the value of a attribute that contains a long.
This implementation delegates to get(TypedName)
.
public double getDouble(TypedName<java.lang.Double> name)
Get the value of a attr that contains a double.
This implementation delegates to get(TypedName)
.
public int getInteger(TypedName<java.lang.Integer> name)
Get the value of a attr that contains a int.
This implementation delegates to get(TypedName)
.
getInteger
in interface Entity
name
- The attribute name.public boolean getBoolean(TypedName<java.lang.Boolean> name)
Get the value of a attr that contains a boolean.
This implementation delegates to get(TypedName)
.
getBoolean
in interface Entity
name
- The attribute name.@Nullable public <T> T maybeGet(TypedName<T> name)
Get the value of a possibly-missing attribute.
This implementation delegates to Entity.maybeGet(String)
and checks the type.
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public void describeTo(DescriptionWriter writer)
Describable
Write this class’s description to a sink. Anything relevant to this object’s identity should be digested; the idea is that, barring hash collisions, two objects with the same digest are equivalent. Used for things like deterministically generating cache file names.
describeTo
in interface Describable
writer
- The description writer to use.