Package io.github.astrapi69.model
Class LambdaModel<T>
- java.lang.Object
-
- io.github.astrapi69.model.LambdaModel<T>
-
- Type Parameters:
T
- The type of the IModel Object
- All Implemented Interfaces:
Attachable
,IDetachable
,IModel<T>
,java.io.Serializable
public abstract class LambdaModel<T> extends java.lang.Object implements IModel<T>
LambdaModel
is a basic implementation of anIModel
that uses a serializableSupplier
to get the object andConsumer
to set it.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <X,T>
IModel<T>of(IModel<X> target, SerializableFunction<X,T> getter)
Create aLambdaModel
for a given target.static <X,T>
IModel<T>of(IModel<X> target, SerializableFunction<X,T> getter, SerializableBiConsumer<X,T> setter)
Create aLambdaModel
for a given target.static <T> IModel<T>
of(SerializableSupplier<T> getter, SerializableConsumer<T> setter)
Create aLambdaModel
.void
setObject(T t)
Sets the model object.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.github.astrapi69.model.api.Attachable
attach
-
Methods inherited from interface io.github.astrapi69.model.api.IDetachable
detach
-
-
-
-
Method Detail
-
of
public static <X,T> IModel<T> of(IModel<X> target, SerializableFunction<X,T> getter)
Create aLambdaModel
for a given target. Usage:LambdaModel.of(personModel, Person::getName)
- Type Parameters:
X
- target model object typeT
- model object type- Parameters:
target
- target for getter and settergetter
- used to get a value- Returns:
- model
-
of
public static <X,T> IModel<T> of(IModel<X> target, SerializableFunction<X,T> getter, SerializableBiConsumer<X,T> setter)
Create aLambdaModel
for a given target. Usage:LambdaModel.of(personModel, Person::getName, Person::setName)
- Type Parameters:
X
- target model object typeT
- model object type- Parameters:
target
- target for getter and settergetter
- used to get a valuesetter
- used to set a value- Returns:
- model
-
of
public static <T> IModel<T> of(SerializableSupplier<T> getter, SerializableConsumer<T> setter)
Create aLambdaModel
. Usage:LambdaModel.of(person::getName, person::setName)
- Type Parameters:
T
- model object type- Parameters:
getter
- used to get valuesetter
- used to set value- Returns:
- model
-
-