- java.lang.Object
-
- aeonics.template.Factory<T>
-
- Type Parameters:
T
- the entity category
- All Implemented Interfaces:
java.lang.Iterable<Template<T>>
public class Factory<T extends Entity> extends java.lang.Object implements java.lang.Iterable<Template<T>>
The factory contains the list of allTemplate
that can be used to create anEntity
based on user input. The templates are organized byTemplate.category()
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <U extends Entity>
Template<? extends U>add(Item<U> templated)
Adds the specified template provider to its matching factoryTemplate.category()
.static <U extends Entity>
Template<U>add(Template<U> template)
Adds the specified template to its matching factoryTemplate.category()
.static java.lang.Iterable<Factory<?>>
all()
Returns an iterator over all factoriesjava.lang.String
category()
Returns the factory category.void
clear()
Removes all templates from this factory.<V extends Item<? super T>>
booleancontains(java.lang.Class<V> type)
Returns true if a template is registered for the specified entity type.boolean
contains(java.lang.String type)
Returns true if a template is registered for the specified entity type.static <U extends Entity>
Ucreate(Data data)
Builds an instance of the exported or snapshotted entity.static <U extends Entity,V extends Item<? super U>>
Ucreate(java.lang.Class<? extends Item<? super U>> category, java.lang.Class<V> type, Data data)
Builds an instance of the exported or snapshotted entity.<U extends T,V extends Item<? super T>>
Template<U>get(java.lang.Class<V> type)
Fetches the template for the specified entity item type.<U extends T>
Template<U>get(java.lang.String type)
Fetches the template for the specified entity type.static boolean
has(java.lang.String category)
Checks if the factory of the given entity category exists.java.util.Iterator<Template<T>>
iterator()
Returns an iterator over all templates registered in this factorystatic <U extends Entity>
Template<U>of(Entity instance)
Fetches the template that can be used to create or modify the specified entity.static <U extends Entity>
Factory<U>of(java.lang.Class<? extends Item<? super U>> category)
Fetches the factory of the given entity category.static <U extends Entity>
Factory<U>of(java.lang.String category)
Fetches the factory of the given entity category.<U extends T>
Template<U>put(Template<U> template)
Adds the specified template into this factory.<U extends T,V extends Item<? super T>>
Template<U>remove(java.lang.Class<V> type)
Removes the template for the specified entity item type.<U extends T>
Template<U>remove(java.lang.String type)
Removes the template for the specified entity type.int
size()
Returns the number of templates in this factory.static <U extends Entity>
Uupdate(U instance, Data data)
Updates an existing entity given new parameters.
-
-
-
Method Detail
-
of
public static <U extends Entity> Factory<U> of(java.lang.Class<? extends Item<? super U>> category)
Fetches the factory of the given entity category. This is the same as callingof(StringUtils.toLowerCase(category))
- Type Parameters:
U
- The entity category- Parameters:
category
- The entity category- Returns:
- The factory containing all
Template
for the specified category
-
of
public static <U extends Entity> Factory<U> of(java.lang.String category)
Fetches the factory of the given entity category.- Type Parameters:
U
- The entity category- Parameters:
category
- The entity category (should be or will be converted to lower case)- Returns:
- The factory containing all
Template
for the specified category
-
of
public static <U extends Entity> Template<U> of(Entity instance)
Fetches the template that can be used to create or modify the specified entity.- Type Parameters:
U
- The entity category- Parameters:
instance
- The entity to fetch the category (should be or will be converted to lower case)- Returns:
- The factory containing all
Template
for the specified category
-
has
public static boolean has(java.lang.String category)
Checks if the factory of the given entity category exists.- Parameters:
category
- The entity category (should be or will be converted to lower case)- Returns:
- true if the factory of the given entity category exists
-
add
public static <U extends Entity> Template<U> add(Template<U> template)
Adds the specified template to its matching factoryTemplate.category()
.- Type Parameters:
U
- the entity category- Parameters:
template
- the template- Returns:
- the template
-
add
public static <U extends Entity> Template<? extends U> add(Item<U> templated)
Adds the specified template provider to its matching factoryTemplate.category()
.- Type Parameters:
U
- the entity category- Parameters:
templated
- the template provider- Returns:
- the template
- See Also:
Template
-
create
public static <U extends Entity> U create(Data data)
Builds an instance of the exported or snapshotted entity.- Type Parameters:
U
- The entity type- Parameters:
data
- the exported entity data- Returns:
- the entity
- Throws:
java.lang.RuntimeException
- if a matching template cannot be foundjava.lang.IllegalArgumentException
- if the provided data is invalid or corrupted- See Also:
Entity.export()
,Template.create(Data)
-
create
public static <U extends Entity,V extends Item<? super U>> U create(java.lang.Class<? extends Item<? super U>> category, java.lang.Class<V> type, Data data)
Builds an instance of the exported or snapshotted entity.- Type Parameters:
U
- The entity categoryV
- The entity type- Parameters:
category
- the entity categorytype
- the entity typedata
- the user input data- Returns:
- the entity
- Throws:
java.lang.RuntimeException
- if a matching template cannot be foundjava.lang.IllegalArgumentException
- if the provided data is invalid or corrupted- See Also:
Template.create(Data)
-
update
public static <U extends Entity> U update(U instance, Data data)
Updates an existing entity given new parameters.- Type Parameters:
U
- The entity type- Parameters:
instance
- the existing instance to modifydata
- the new user input data- Returns:
- the modified instance
- See Also:
Template.update(Data, Entity)
-
all
public static java.lang.Iterable<Factory<?>> all()
Returns an iterator over all factories- Returns:
- a factory iterator
-
category
public java.lang.String category()
Returns the factory category.- Returns:
- the factory category
-
get
public <U extends T,V extends Item<? super T>> Template<U> get(java.lang.Class<V> type)
Fetches the template for the specified entity item type. This is the same as callingget(StringUtils.toLowerCase(type))
- Type Parameters:
U
- the entity typeV
- the entity item type- Parameters:
type
- the entity item type- Returns:
- the matching template or null if no such template is found
-
get
public <U extends T> Template<U> get(java.lang.String type)
Fetches the template for the specified entity type.- Type Parameters:
U
- the entity type- Parameters:
type
- the entity type (should be or will be converted to lower case)- Returns:
- the matching template or null if no such template is found
-
contains
public <V extends Item<? super T>> boolean contains(java.lang.Class<V> type)
Returns true if a template is registered for the specified entity type. This is the same as callingcontains(StringUtils.toLowerCase(type))
- Type Parameters:
V
- the entity item type- Parameters:
type
- the entity item type- Returns:
- true if a template is registered for the specified entity type
-
contains
public boolean contains(java.lang.String type)
Returns true if a template is registered for the specified entity type.- Parameters:
type
- the entity type (should be or will be converted to lower case)- Returns:
- true if a template is registered for the specified entity type
-
put
public <U extends T> Template<U> put(Template<U> template)
Adds the specified template into this factory. TheTemplate.category()
should match this factory's category.- Type Parameters:
U
- the entity type- Parameters:
template
- the template- Returns:
- the template
- Throws:
java.lang.IllegalArgumentException
- if the template is null or if the category does not match
-
remove
public <U extends T,V extends Item<? super T>> Template<U> remove(java.lang.Class<V> type)
Removes the template for the specified entity item type. This is the same as callingremove(StringUtils.toLowerCase(type))
- Type Parameters:
U
- the entity typeV
- the entity item type- Parameters:
type
- the entity item type- Returns:
- the removed template, or null if there was no template for the specified entity type
-
remove
public <U extends T> Template<U> remove(java.lang.String type)
Removes the template for the specified entity type. The entity type should always be lower case.- Type Parameters:
U
- the entity type- Parameters:
type
- the entity type (should be or will be converted to lower case)- Returns:
- the removed template, or null if there was no template for the specified entity type
-
clear
public void clear()
Removes all templates from this factory.
-
size
public int size()
Returns the number of templates in this factory.- Returns:
- the number of templates in this factory
-
-