-
Notifications
You must be signed in to change notification settings - Fork 24
Creating an Entity type
This is a subclass of Entity (outlined below). An Entity type can be used to 'cast' an entity to a different type - allowing entities to be used in an OO fashion.
An Entity type is a subclass of the interface Entity (see EntityProxies API docs).
An entity subclass can have the following method definitions:
- Setting an Attribute of type (will remove if argument passed is null).
- Getting an Attribute of type.
- Getting an Entity as type.
- Creating a new Entity of type.
- Getting a Set of all of the child entities of or as type.
- Getting a Stream of all of the child entities of or as type.
For an Entity proxy to be created the type be validated:
- All attributes types must not be primitives (can be null).
- Can only have super types that are (or are subclasses of) Entity.
- Must only contain default or annotated methods: * SetAttribute * GetAttribute * GetEntity * NewEntity * GetEntities * StreamEntities
The most basic types can be used to mark or group entities for processing - so require no methods at all.
public interface Animal extends Entity{}
public interface FlyingAnimal extends Animal{}Entity types can be bean-like with getters and setters.
public interface Friend extends Entity {
@GetAttribute("name")
String getName();
@SetAttribute("name")
void setName(String name);
}Entities can manage other entities (which may be typed).
public interface Friend extends Entity {
@StreamEnitites
Stream<Friend> streamFriends();
@GetEntities
Set<Friend> getFriends();
@NewEntity
Friend newFriend();
}Default methods allow entity types to be used similarly to concrete classes.
public interface WingedBeast extends Entity {
default void takeFlight() {
/* Set flying */
}
}An entity can be marked as multiple types (for easy filtering).
Entity e; // Previously created entity
e.markAsType(FlyingAnimal.class);Entity type inheritance still applies:
assert e.isMarkedAsType(Animal.class);Marked entities can be used to filter entities of that type:
jalse.streamEntitiesOfType(Animal.class).forEach(/* feed */);Entities can be 'cast' to a particular type and used as such without error. This is because entity type methods are translated into AttributeContainer and EntityContainer methods.
Entity e; // Previously created entity
FlyingAnimal fa = Entities.asType(e, FlyingAnimal.class);or
FlyingAnimal fa = e.asType(FlyingAnimal.class(;Check out the Example projects and Code snippets!
Getting Started
- Getting the latest release
- Building from source
- Example projects
- Code snippets
- How to contribute
- Have bugs or questions?
How To Use
- JALSE
- Entities
- Attributes
- Actions
- Tags
Misc