Package com.github.tadukoo.util.pojo
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 Summary
Modifier and TypeMethodDescriptiondefault void
clear()
Empties out the items in the pojodefault Object
Grabs the item contained in the pojo with the given keygetKeys()
default <T extends MappedPojo>
List<T>getListItem
(String key, Class<T> clazz) Helper method to cast an item being stored in this Mapped Pojo as a proper List easily.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.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.getMap()
default <T extends MappedPojo>
TgetPojoItem
(String key, Class<T> clazz) Helper method to cast an item being stored in this Mapped Pojo as another MappedPojo object easily.default <T extends MappedPojo>
TgetPojoItemNoThrow
(EasyLogger logger, String key, Class<T> clazz) Helper method to cast an item being stored in this Mapped Pojo as another MappedPojo object easily.default <T extends MappedPojo>
TgetPojoItemNoThrow
(String key, Class<T> clazz) Helper method to cast an item being stored in this Mapped Pojo as another MappedPojo object easily.default boolean
Checks whether the pojo has an item for the given keydefault boolean
Checks whether the pojo has the given keydefault boolean
isEmpty()
Checks whether the pojo is empty (no keys/values)default void
removeItem
(String key) Removes the item in the pojo for the given keydefault void
Sets the item in the pojo for the given key
-
Method Details
-
isEmpty
default boolean isEmpty()Checks whether the pojo is empty (no keys/values)- Returns:
- If the pojo is empty or not
-
hasKey
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
- Returns:
- The
Set
of keys in the pojo
-
hasItem
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
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
Sets the item in the pojo for the given key- Parameters:
key
- The key of the item to be setitem
- The item to set on the pojo
-
removeItem
Removes the item in the pojo for the given key- Parameters:
key
- The key of the item to be removed
-
getMap
- Returns:
- The full Map of items in the pojo
-
clear
default void clear()Empties out the items in the pojo -
getPojoItem
default <T extends MappedPojo> T getPojoItem(String key, Class<T> clazz) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException 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 grabclazz
- The class to cast the item to- Returns:
- The item as a proper instance of the class, or null
- Throws:
NoSuchMethodException
- SeeConstructor.newInstance(Object...)
IllegalAccessException
- SeeConstructor.newInstance(Object...)
InvocationTargetException
- SeeConstructor.newInstance(Object...)
InstantiationException
- SeeConstructor.newInstance(Object...)
-
getPojoItemNoThrow
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 grabclazz
- The class to cast the item to- Returns:
- The item as a proper instance of the class, or null
-
getPojoItemNoThrow
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 givenEasyLogger
, then return null if something goes wrong- Type Parameters:
T
- The class the item should be cast to- Parameters:
logger
- TheEasyLogger
to log any errors tokey
- The key of the item to grabclazz
- The class to cast the item to- Returns:
- The item as a proper instance of the class, or null
-
getListItem
default <T extends MappedPojo> List<T> getListItem(String key, Class<T> clazz) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException 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 grabclazz
- The MappedPojo class to be used in the List- Returns:
- The item as a proper List instance, or null
- Throws:
NoSuchMethodException
- SeeConstructor.newInstance(Object...)
IllegalAccessException
- SeeConstructor.newInstance(Object...)
InvocationTargetException
- SeeConstructor.newInstance(Object...)
InstantiationException
- SeeConstructor.newInstance(Object...)
-
getListItemNoThrow
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 grabclazz
- 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 givenEasyLogger
, then return null if something goes wrong- Type Parameters:
T
- The class of the pojos in the List- Parameters:
logger
- TheEasyLogger
to log any errors tokey
- The key of the item to grabclazz
- The MappedPojo class to be used in the List- Returns:
- The item as a proper List instance, or null
-