Class FunctionalAgentProperty<T>
java.lang.Object
modelarium.entities.attributes.AttributeBase<AgentContext>
modelarium.entities.attributes.properties.Property<T,AgentContext>
modelarium.entities.attributes.properties.AgentProperty<T>
modelarium.entities.attributes.properties.functional.FunctionalAgentProperty<T>
- Type Parameters:
T- the type of value this property carries
- All Implemented Interfaces:
AgentAttribute,Attribute
Class for representing an agent property whose behaviour is defined via functional interfaces.
This class allows dynamic configuration of property behaviour, which is useful when working with external systems or when subclassing is not feasible (e.g. in Python via JPype). The property's value is stored internally and passed to each of the user-provided functions.
-
Constructor Summary
ConstructorsConstructorDescriptionFunctionalAgentProperty(String name, boolean isLogged, AttributeAccessLevel accessLevel, Class<T> type, AgentPropertyGetterFunction<T> getter, AgentPropertySetterFunction<T> setter, AgentPropertyRunFunction<T> runLogic) Constructs a new functional agent property with the specified logic functions. -
Method Summary
Modifier and TypeMethodDescriptionget(AgentContext context) Returns this property's value by applying the user-provided getter function.voidrun(AgentContext context) Runs this property's behaviour by applying the user-provided run function and storing its result.voidset(AgentContext context, T value) Sets this property's value by applying the user-provided setter function and storing its result.Methods inherited from class modelarium.entities.attributes.properties.Property
get, getAsImmutable, run, set, toString, typeMethods inherited from class modelarium.entities.attributes.AttributeBase
accessLevel, context, isLogged, nameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface modelarium.entities.attributes.Attribute
accessLevel, getAsImmutable, isLogged, name, run
-
Constructor Details
-
FunctionalAgentProperty
public FunctionalAgentProperty(String name, boolean isLogged, AttributeAccessLevel accessLevel, Class<T> type, AgentPropertyGetterFunction<T> getter, AgentPropertySetterFunction<T> setter, AgentPropertyRunFunction<T> runLogic) Constructs a new functional agent property with the specified logic functions.- Parameters:
name- the name of the property, used to identify it within its attribute setisLogged- whether the property's value is logged as the model progressesaccessLevel- the access level of the property, determining whether other entities may read ittype- the class of the value the property carriesgetter- the function defining the property's getter logicsetter- the function defining the property's setter logicrunLogic- the function defining the property's behaviour
-
-
Method Details
-
run
Runs this property's behaviour by applying the user-provided run function and storing its result.If no run function was provided, this method does nothing.
- Overrides:
runin classProperty<T,AgentContext> - Parameters:
context- the context the property can use in its behaviour
-
set
Sets this property's value by applying the user-provided setter function and storing its result.- Specified by:
setin classProperty<T,AgentContext> - Parameters:
context- the context the property can use in its setter logicvalue- the value the property is being set to
-
get
Returns this property's value by applying the user-provided getter function.- Specified by:
getin classProperty<T,AgentContext> - Parameters:
context- the context the property can use in its getter logic- Returns:
- the value reported by the getter function
-