Module aeonics.core

Class Factory<T extends Entity>

  • 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 all Template that can be used to create an Entity based on user input. The templates are organized by Template.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 factory Template.category().
      static <U extends Entity>
      Template<U>
      add​(Template<U> template)
      Adds the specified template to its matching factory Template.category().
      static java.lang.Iterable<Factory<?>> all()
      Returns an iterator over all factories
      java.lang.String category()
      Returns the factory category.
      void clear()
      Removes all templates from this factory.
      <V extends Item<? super T>>
      boolean
      contains​(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>
      U
      create​(Data data)
      Builds an instance of the exported or snapshotted entity.
      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.
      <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 factory
      static <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>
      U
      update​(U instance, Data data)
      Updates an existing entity given new parameters.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • of

        public static <U extends EntityFactory<U> of​(java.lang.Class<? extends Item<? super U>> category)
        Fetches the factory of the given entity category. This is the same as calling of(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 EntityFactory<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 EntityTemplate<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 EntityTemplate<U> add​(Template<U> template)
        Adds the specified template to its matching factory Template.category().
        Type Parameters:
        U - the entity category
        Parameters:
        template - the template
        Returns:
        the template
      • add

        public static <U extends EntityTemplate<? extends U> add​(Item<U> templated)
        Adds the specified template provider to its matching factory Template.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 found
        java.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 category
        V - The entity type
        Parameters:
        category - the entity category
        type - the entity type
        data - the user input data
        Returns:
        the entity
        Throws:
        java.lang.RuntimeException - if a matching template cannot be found
        java.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 modify
        data - 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 calling get(StringUtils.toLowerCase(type))
        Type Parameters:
        U - the entity type
        V - 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 TTemplate<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 calling contains(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 TTemplate<U> put​(Template<U> template)
        Adds the specified template into this factory. The Template.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 calling remove(StringUtils.toLowerCase(type))
        Type Parameters:
        U - the entity type
        V - 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 TTemplate<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
      • iterator

        public java.util.Iterator<Template<T>> iterator()
        Returns an iterator over all templates registered in this factory
        Specified by:
        iterator in interface java.lang.Iterable<T extends Entity>
        Returns:
        a template iterator