Package io.github.astrapi69.model
Class GenericModel<T>
- java.lang.Object
-
- io.github.astrapi69.model.GenericModel<T>
-
- Type Parameters:
T
- the generic type of the model object
- All Implemented Interfaces:
Attachable
,IDetachable
,IModel<T>
,IObjectClassAwareModel<T>
,java.io.Serializable
- Direct Known Subclasses:
BaseModel
,GenericCollectionModel
,SerializableModel
public abstract class GenericModel<T> extends java.lang.Object implements IModel<T>, IObjectClassAwareModel<T>
The classGenericModel
is the basic implementation of anIModel
. Decorates a simple object. This class is only for small object, if you want to store large objects consider to use LoadableDetachableModel instead.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GenericModel()
GenericModel(T object)
Instantiates a newGenericModel
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attach()
Attach an object.protected boolean
canEqual(java.lang.Object other)
void
detach()
Detach an object.boolean
equals(java.lang.Object o)
T
getObject()
Backing object.java.lang.Class<T>
getObjectClass()
Gets the object class.int
hashCode()
static <C> IModel<java.util.Collection<C>>
ofCollection(java.util.Collection<C> collection)
Factory method for models that contain collections.static <C> IModel<java.util.List<C>>
ofList(java.util.List<C> list)
Factory method for models that contain lists.static <K,V>
IModel<java.util.Map<K,V>>ofMap(java.util.Map<K,V> map)
Factory method for models that contain maps.static <C> IModel<java.util.Set<C>>
ofSet(java.util.Set<C> set)
Factory method for models that contain sets.void
setObject(T object)
Backing object.java.lang.String
toString()
-
-
-
Constructor Detail
-
GenericModel
public GenericModel(T object)
Instantiates a newGenericModel
.- Parameters:
object
- the object
-
GenericModel
public GenericModel()
-
-
Method Detail
-
ofCollection
public static <C> IModel<java.util.Collection<C>> ofCollection(java.util.Collection<C> collection)
Factory method for models that contain collections. This factory method will automatically rebuild a nonserializablecollection
into a serializableArrayList
.- Type Parameters:
C
- model type- Parameters:
collection
- The Collection, which may or may not be Serializable- Returns:
- A IModel object wrapping the Set
-
ofList
public static <C> IModel<java.util.List<C>> ofList(java.util.List<C> list)
Factory method for models that contain lists. This factory method will automatically rebuild a nonserializablelist
into a serializable one.- Type Parameters:
C
- model type- Parameters:
list
- The List, which may or may not be Serializable- Returns:
- A IModel object wrapping the List
-
ofMap
public static <K,V> IModel<java.util.Map<K,V>> ofMap(java.util.Map<K,V> map)
Factory method for models that contain maps. This factory method will automatically rebuild a nonserializablemap
into a serializable one.- Type Parameters:
K
- key type in mapV
- value type in map- Parameters:
map
- The Map, which may or may not be Serializable- Returns:
- A IModel object wrapping the Map
-
ofSet
public static <C> IModel<java.util.Set<C>> ofSet(java.util.Set<C> set)
Factory method for models that contain sets. This factory method will automatically rebuild a nonserializableset
into a serializable one.- Type Parameters:
C
- model type- Parameters:
set
- The Set, which may or may not be Serializable- Returns:
- A IModel object wrapping the Set
-
attach
public void attach()
Attach an object.- Specified by:
attach
in interfaceAttachable
-
detach
public void detach()
Detach an object.- Specified by:
detach
in interfaceIDetachable
-
getObjectClass
public java.lang.Class<T> getObjectClass()
Gets the object class.- Specified by:
getObjectClass
in interfaceIObjectClassAwareModel<T>
- Returns:
- the object class
-
getObject
public T getObject()
Backing object.
-
setObject
public void setObject(T object)
Backing object.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
canEqual
protected boolean canEqual(java.lang.Object other)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-