Interface MappedPojo

All Known Subinterfaces:
OrderedMappedPojo
All Known Implementing Classes:
AbstractMappedPojo, AbstractOrderedMappedPojo

public interface MappedPojo
Represents a Pojo that holds its values in a Map.
Since:
Alpha v.0.2
Version:
Beta v.0.5
Author:
Logan Ferree (Tadukoo)
  • Method Details

    • isEmpty

      default boolean isEmpty()
      Checks whether the pojo is empty (no keys/values)
      Returns:
      If the pojo is empty or not
    • hasKey

      default boolean hasKey(String key)
      Checks whether the pojo has the given key
      Parameters:
      key - The key to look for
      Returns:
      If the pojo contains the key or not
    • getKeys

      default Set<String> getKeys()
      Returns:
      The Set of keys in the pojo
    • hasItem

      default boolean hasItem(String key)
      Checks whether the pojo has an item for the given key
      Parameters:
      key - The key to look for
      Returns:
      Whether the pojo has an item for the given key
    • getItem

      default Object getItem(String key)
      Grabs the item contained in the pojo with the given key
      Parameters:
      key - The key of the item to grab
      Returns:
      The item the pojo has for the given key
    • setItem

      default void setItem(String key, Object item)
      Sets the item in the pojo for the given key
      Parameters:
      key - The key of the item to be set
      item - The item to set on the pojo
    • removeItem

      default void removeItem(String key)
      Removes the item in the pojo for the given key
      Parameters:
      key - The key of the item to be removed
    • getMap

      Map<String,Object> getMap()
      Returns:
      The full Map of items in the pojo
    • clear

      default void clear()
      Empties out the items in the pojo
    • getPojoItem

      Helper method to cast an item being stored in this Mapped Pojo as another MappedPojo object easily. The other Mapped Pojo object must have a constructor that takes in a MappedPojo.
      Type Parameters:
      T - The class the item should be cast to
      Parameters:
      key - The key of the item to grab
      clazz - The class to cast the item to
      Returns:
      The item as a proper instance of the class, or null
      Throws:
      NoSuchMethodException - See Constructor.newInstance(Object...)
      IllegalAccessException - See Constructor.newInstance(Object...)
      InvocationTargetException - See Constructor.newInstance(Object...)
      InstantiationException - See Constructor.newInstance(Object...)
    • getPojoItemNoThrow

      default <T extends MappedPojo> T getPojoItemNoThrow(String key, Class<T> clazz)
      Helper method to cast an item being stored in this Mapped Pojo as another MappedPojo object easily. The other Mapped Pojo object must have a constructor that takes in a MappedPojo.

      This version does not throw any exceptions and will not log any errors, just return null if something goes wrong
      Type Parameters:
      T - The class the item should be cast to
      Parameters:
      key - The key of the item to grab
      clazz - The class to cast the item to
      Returns:
      The item as a proper instance of the class, or null
    • getPojoItemNoThrow

      default <T extends MappedPojo> T getPojoItemNoThrow(EasyLogger logger, String key, Class<T> clazz)
      Helper method to cast an item being stored in this Mapped Pojo as another MappedPojo object easily. The other Mapped Pojo object must have a constructor that takes in a MappedPojo.

      This version does not throw any exceptions and will log any errors to the given EasyLogger, then return null if something goes wrong
      Type Parameters:
      T - The class the item should be cast to
      Parameters:
      logger - The EasyLogger to log any errors to
      key - The key of the item to grab
      clazz - The class to cast the item to
      Returns:
      The item as a proper instance of the class, or null
    • getListItem

      Helper method to cast an item being stored in this Mapped Pojo as a proper List easily. The Mapped Pojo class specified for the List must have a constructor that accepts a Mapped Pojo.
      Type Parameters:
      T - The class of the pojos in the List
      Parameters:
      key - The key of the item to grab
      clazz - The MappedPojo class to be used in the List
      Returns:
      The item as a proper List instance, or null
      Throws:
      NoSuchMethodException - See Constructor.newInstance(Object...)
      IllegalAccessException - See Constructor.newInstance(Object...)
      InvocationTargetException - See Constructor.newInstance(Object...)
      InstantiationException - See Constructor.newInstance(Object...)
    • getListItemNoThrow

      default <T extends MappedPojo> List<T> getListItemNoThrow(String key, Class<T> clazz)
      Helper method to cast an item being stored in this Mapped Pojo as a proper List easily. The Mapped Pojo class specified for the List must have a constructor that accepts a Mapped Pojo.

      This version does not throw any exceptions and will not log any errors, just return null if something goes wrong
      Type Parameters:
      T - The class of the pojos in the List
      Parameters:
      key - The key of the item to grab
      clazz - The MappedPojo class to be used in the List
      Returns:
      The item as a proper List instance, or null
    • getListItemNoThrow

      default <T extends MappedPojo> List<T> getListItemNoThrow(EasyLogger logger, String key, Class<T> clazz)
      Helper method to cast an item being stored in this Mapped Pojo as a proper List easily. The Mapped Pojo class specified for the List must have a constructor that accepts a Mapped Pojo.

      This version does not throw any exceptions and will log any errors to the given EasyLogger, then return null if something goes wrong
      Type Parameters:
      T - The class of the pojos in the List
      Parameters:
      logger - The EasyLogger to log any errors to
      key - The key of the item to grab
      clazz - The MappedPojo class to be used in the List
      Returns:
      The item as a proper List instance, or null