public abstract class AbstractEntity extends 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 |
---|---|
Map<String,Object> |
asMap()
View this entity as a map.
|
void |
describeTo(DescriptionWriter writer)
Write this class’s description to a sink.
|
boolean |
equals(Object obj) |
Object |
get(String attr)
Get the value of an attribute by name.
|
<T> T |
get(TypedName<T> name)
Get the value of an attribute.
|
Set<String> |
getAttributeNames()
Get the names of the attributes in this entity.
|
Collection<Attribute<?>> |
getAttributes()
Get the attribute-value pairs.
|
boolean |
getBoolean(TypedName<Boolean> name)
Get the value of a attr that contains a boolean.
|
double |
getDouble(TypedName<Double> name)
Get the value of a attr that contains a double.
|
long |
getId()
Get the identifier of this entity.
|
int |
getInteger(TypedName<Integer> name)
Get the value of a attr that contains a int.
|
long |
getLong(TypedName<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.
|
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)
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. that the data is of a compatible type.public Set<String> getAttributeNames()
Get the names of the attributes in this entity.
Delegates to Entity.getTypedAttributeNames()
and extracts the names.
getAttributeNames
in interface Entity
public Collection<Attribute<?>> getAttributes()
Get the attribute-value pairs.
Delegates to Entity.getTypedAttributeNames()
and extracts the names.
getAttributes
in interface Entity
public Map<String,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 Object get(String attr)
Get the value of an attribute by name.
This implementation delegates to Entity.maybeGet(String)
.
public long getLong(TypedName<Long> name)
Get the value of a attribute that contains a long.
This implementation delegates to get(TypedName)
.
public double getDouble(TypedName<Double> name)
Get the value of a attr that contains a double.
This implementation delegates to get(TypedName)
.
public int getInteger(TypedName<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<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 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.