Record Class SwarmState

java.lang.Object
java.lang.Record
com.tnsai.coordination.groups.swarm.SwarmState
Record Components:
swarmId - swarm identifier
memberCount - number of active members
behavior - current behavior
tickCount - number of ticks executed
running - whether swarm is running
pheromoneLocations - number of locations with pheromones
activePheromones - total active pheromone count
environmentSize - size of shared environment
neighborConnections - average neighbor connections per agent
startedAt - when swarm started running
elapsed - time since start

public record SwarmState(String swarmId, int memberCount, SwarmBehavior behavior, long tickCount, boolean running, int pheromoneLocations, int activePheromones, int environmentSize, double neighborConnections, Instant startedAt, Duration elapsed) extends Record
Snapshot of swarm state at a point in time.
  • Constructor Details

    • SwarmState

      public SwarmState(String swarmId, int memberCount, SwarmBehavior behavior, long tickCount, boolean running, int pheromoneLocations, int activePheromones, int environmentSize, double neighborConnections, Instant startedAt, Duration elapsed)
      Creates an instance of a SwarmState record class.
      Parameters:
      swarmId - the value for the swarmId record component
      memberCount - the value for the memberCount record component
      behavior - the value for the behavior record component
      tickCount - the value for the tickCount record component
      running - the value for the running record component
      pheromoneLocations - the value for the pheromoneLocations record component
      activePheromones - the value for the activePheromones record component
      environmentSize - the value for the environmentSize record component
      neighborConnections - the value for the neighborConnections record component
      startedAt - the value for the startedAt record component
      elapsed - the value for the elapsed record component
  • Method Details

    • initial

      public static SwarmState initial(String swarmId, int memberCount, SwarmBehavior behavior)
      Creates an initial state for a swarm.
      Parameters:
      swarmId - swarm ID
      memberCount - member count
      behavior - initial behavior
      Returns:
      initial state
    • snapshot

      public static SwarmState snapshot(String swarmId, int memberCount, SwarmBehavior behavior, long tickCount, boolean running, SwarmEnvironment environment, double avgNeighbors, Instant startedAt)
      Creates an updated state snapshot.
      Parameters:
      swarmId - swarm ID
      memberCount - current member count
      behavior - current behavior
      tickCount - total ticks
      running - is running
      environment - shared environment
      avgNeighbors - average neighbor count
      startedAt - start time
      Returns:
      updated state
    • hasActivity

      public boolean hasActivity()
      Checks if swarm has activity.
      Returns:
      true if has pheromones or environment data
    • getTickRate

      public double getTickRate()
      Gets ticks per second rate.
      Returns:
      ticks/second or 0 if not running
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • swarmId

      public String swarmId()
      Returns the value of the swarmId record component.
      Returns:
      the value of the swarmId record component
    • memberCount

      public int memberCount()
      Returns the value of the memberCount record component.
      Returns:
      the value of the memberCount record component
    • behavior

      public SwarmBehavior behavior()
      Returns the value of the behavior record component.
      Returns:
      the value of the behavior record component
    • tickCount

      public long tickCount()
      Returns the value of the tickCount record component.
      Returns:
      the value of the tickCount record component
    • running

      public boolean running()
      Returns the value of the running record component.
      Returns:
      the value of the running record component
    • pheromoneLocations

      public int pheromoneLocations()
      Returns the value of the pheromoneLocations record component.
      Returns:
      the value of the pheromoneLocations record component
    • activePheromones

      public int activePheromones()
      Returns the value of the activePheromones record component.
      Returns:
      the value of the activePheromones record component
    • environmentSize

      public int environmentSize()
      Returns the value of the environmentSize record component.
      Returns:
      the value of the environmentSize record component
    • neighborConnections

      public double neighborConnections()
      Returns the value of the neighborConnections record component.
      Returns:
      the value of the neighborConnections record component
    • startedAt

      public Instant startedAt()
      Returns the value of the startedAt record component.
      Returns:
      the value of the startedAt record component
    • elapsed

      public Duration elapsed()
      Returns the value of the elapsed record component.
      Returns:
      the value of the elapsed record component