Class Property<T,C extends Context>

java.lang.Object
modelarium.entities.attributes.AttributeBase<C>
modelarium.entities.attributes.properties.Property<T,C>
Type Parameters:
T - the type of value this property carries
C - the type of context this property is given
All Implemented Interfaces:
Attribute
Direct Known Subclasses:
AgentProperty, EnvironmentProperty

public abstract sealed class Property<T,C extends Context> extends AttributeBase<C> permits AgentProperty<T>, EnvironmentProperty<T>
Abstract class for representing an attribute that carries a typed value.

Each tick, a property's behaviour is run and (if the property is logged) its value is recorded. Properties can also be read and written directly through their getter and setter. This class is extended by AgentProperty and EnvironmentProperty.

  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Returns this property's current value.
    protected abstract T
    get(C context)
    Returns this property's current value.
    Creates and returns an immutable version of this attribute.
    void
    run()
    Runs this property's behaviour for the current tick.
    protected void
    run(C context)
    Runs this property's behaviour (does nothing by default).
    protected abstract void
    set(C context, T value)
    Sets this property's value.
    void
    set(T value)
    Sets this property's value.
    Returns the string representation of the property value.
    Returns the class of the value this property carries.

    Methods inherited from class modelarium.entities.attributes.AttributeBase

    accessLevel, context, isLogged, name

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • toString

      public String toString()
      Returns the string representation of the property value.
      Overrides:
      toString in class Object
      Returns:
      the property's value as a string
    • type

      public Class<T> type()
      Returns the class of the value this property carries.
      Returns:
      the property's value type
    • set

      public void set(T value)
      Sets this property's value.
      Parameters:
      value - the value to set the property to
    • get

      public T get()
      Returns this property's current value.
      Returns:
      the property's value
    • run

      public void run()
      Runs this property's behaviour for the current tick.
    • run

      protected void run(C context)
      Runs this property's behaviour (does nothing by default). Can be overridden by subclasses.
      Parameters:
      context - the context the property can use in its behaviour
    • set

      protected abstract void set(C context, T value)
      Sets this property's value. Must be implemented by subclasses.
      Parameters:
      context - the context the property can use in its setter logic
      value - the value to set the property to
    • get

      protected abstract T get(C context)
      Returns this property's current value. Must be implemented by subclasses.
      Parameters:
      context - the context the property can use in its getter logic
      Returns:
      the property's value
    • getAsImmutable

      public ReadOnlyProperty<T> getAsImmutable()
      Creates and returns an immutable version of this attribute.
      Returns:
      the new ReadOnlyProperty instance