Class DelegatingEntity<T>

java.lang.Object
io.fluxcapacitor.javaclient.modeling.DelegatingEntity<T>
Type Parameters:
T - the type of the entity's value
All Implemented Interfaces:
Entity<T>
Direct Known Subclasses:
ModifiableAggregateRoot, ModifiableEntity

public abstract class DelegatingEntity<T> extends Object implements Entity<T>
A base implementation of Entity that forwards all method calls to a delegated Entity instance.

DelegatingEntity is designed to serve as a foundation for wrapper implementations that enrich or modify entity behavior without altering the core entity logic. It simplifies the creation of decorator-style entities such as ModifiableEntity, SideEffectFreeEntity, and ModifiableAggregateRoot, allowing selective method overriding while relying on delegation for the rest.

Subclasses typically override behavior like Entity.update(UnaryOperator), Entity.apply(Message), or Entity.assertLegal(Object) to add custom lifecycle behavior (e.g., interception, queuing, validation) while maintaining compatibility with the Entity interface.

By default, all methods delegate directly to the wrapped Entity instance, which is exposed via the #getDelegate() accessor.

See Also:
  • Field Details

    • delegate

      protected Entity<T> delegate
  • Constructor Details

    • DelegatingEntity

      public DelegatingEntity(@NonNull @NonNull Entity<T> delegate)
  • Method Details

    • id

      public Object id()
      Description copied from interface: Entity
      Retrieves the unique identifier of the entity.
      Specified by:
      id in interface Entity<T>
      Returns:
      the unique identifier of the entity, or null if this entity has not been initialized yet
    • aliases

      public Collection<?> aliases()
      Description copied from interface: Entity
      Retrieves a collection of aliases associated with this entity.
      Specified by:
      aliases in interface Entity<T>
      Returns:
      a collection containing aliases of this entity, or an empty collection if no aliases are present
    • type

      public Class<T> type()
      Description copied from interface: Entity
      Retrieves the type of the entity.
      Specified by:
      type in interface Entity<T>
      Returns:
      the class type of the entity, or null if the type has not been defined
    • get

      public T get()
      Description copied from interface: Entity
      Retrieves the current instance of the entity.
      Specified by:
      get in interface Entity<T>
      Returns:
      the current instance of the entity or null if not initialized
    • idProperty

      public String idProperty()
      Description copied from interface: Entity
      Retrieves the name of the property that serves as the unique identifier for the entity.
      Specified by:
      idProperty in interface Entity<T>
      Returns:
      the name of the identification property as a string
    • lastEventId

      public String lastEventId()
      Description copied from interface: Entity
      Retrieves the identifier of the last event applied to the entity hierarchy.
      Specified by:
      lastEventId in interface Entity<T>
      Returns:
      the identifier of the last event as a string, or null if no events have been recorded in the entity's aggregate
    • lastEventIndex

      public Long lastEventIndex()
      Description copied from interface: Entity
      Retrieves the index of the last event applied to this entity hierarchy.
      Specified by:
      lastEventIndex in interface Entity<T>
      Returns:
      the index of the last event as a Long, or null if no events have been recorded for the entity's aggregate
    • timestamp

      public Instant timestamp()
      Description copied from interface: Entity
      Retrieves the timestamp of the entity.
      Specified by:
      timestamp in interface Entity<T>
      Returns:
      the timestamp as an Instant obtained from the root entity
    • sequenceNumber

      public long sequenceNumber()
      Description copied from interface: Entity
      Retrieves the sequence number of the current entity.
      Specified by:
      sequenceNumber in interface Entity<T>
      Returns:
      the sequence number of the root entity
    • previous

      public Entity<T> previous()
      Description copied from interface: Entity
      Retrieves the previous version of this entity.
      Specified by:
      previous in interface Entity<T>
      Returns:
      the previous state of the entity, or null if this is the first known version
    • entities

      public Collection<? extends Entity<?>> entities()
      Description copied from interface: Entity
      Retrieves child entities of this entity.
      Specified by:
      entities in interface Entity<T>
      Returns:
      a collection containing child entities.
    • parent

      public Entity<?> parent()
      Description copied from interface: Entity
      Retrieves the parent entity of the current entity.
      Specified by:
      parent in interface Entity<T>
      Returns:
      the parent entity of the current entity, or null if this entity does not have a parent
    • withEventIndex

      public Entity<T> withEventIndex(Long index, String messageId)
      Description copied from interface: Entity
      Updates the event index and message ID of the entity and returns the updated version of the entity.
      Specified by:
      withEventIndex in interface Entity<T>
      Parameters:
      index - the event index to set for the root entity
      messageId - the message ID associated with the event
      Returns:
      the updated entity corresponding to the current entity's ID and type, or null if no such entity can be found
    • withType

      public Entity<T> withType(Class<T> type)
      Description copied from interface: Entity
      Sets the type of the entity to the specified class and returns the updated entity.
      Specified by:
      withType in interface Entity<T>
      Parameters:
      type - the class representing the type to be set for the entity
      Returns:
      the updated entity with the specified type
    • withSequenceNumber

      public Entity<T> withSequenceNumber(long sequenceNumber)
      Description copied from interface: Entity
      Returns an updated entity based on this with the specified sequence number.
      Specified by:
      withSequenceNumber in interface Entity<T>
      Parameters:
      sequenceNumber - the sequence number to assign to the entity
      Returns:
      the updated entity with the specified sequence number, or null if the entity could not be found in the entity hierarchy