Record Class SwarmState
java.lang.Object
java.lang.Record
com.tnsai.coordination.groups.swarm.SwarmState
- Record Components:
swarmId- swarm identifiermemberCount- number of active membersbehavior- current behaviortickCount- number of ticks executedrunning- whether swarm is runningpheromoneLocations- number of locations with pheromonesactivePheromones- total active pheromone countenvironmentSize- size of shared environmentneighborConnections- average neighbor connections per agentstartedAt- when swarm started runningelapsed- 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 Summary
ConstructorsConstructorDescriptionSwarmState(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 aSwarmStaterecord class. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the value of theactivePheromonesrecord component.behavior()Returns the value of thebehaviorrecord component.elapsed()Returns the value of theelapsedrecord component.intReturns the value of theenvironmentSizerecord component.final booleanIndicates whether some other object is "equal to" this one.doubleGets ticks per second rate.booleanChecks if swarm has activity.final inthashCode()Returns a hash code value for this object.static SwarmStateinitial(String swarmId, int memberCount, SwarmBehavior behavior) Creates an initial state for a swarm.intReturns the value of thememberCountrecord component.doubleReturns the value of theneighborConnectionsrecord component.intReturns the value of thepheromoneLocationsrecord component.booleanrunning()Returns the value of therunningrecord component.static SwarmStatesnapshot(String swarmId, int memberCount, SwarmBehavior behavior, long tickCount, boolean running, SwarmEnvironment environment, double avgNeighbors, Instant startedAt) Creates an updated state snapshot.Returns the value of thestartedAtrecord component.swarmId()Returns the value of theswarmIdrecord component.longReturns the value of thetickCountrecord component.final StringtoString()Returns a string representation of this record class.
-
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 aSwarmStaterecord class.- Parameters:
swarmId- the value for theswarmIdrecord componentmemberCount- the value for thememberCountrecord componentbehavior- the value for thebehaviorrecord componenttickCount- the value for thetickCountrecord componentrunning- the value for therunningrecord componentpheromoneLocations- the value for thepheromoneLocationsrecord componentactivePheromones- the value for theactivePheromonesrecord componentenvironmentSize- the value for theenvironmentSizerecord componentneighborConnections- the value for theneighborConnectionsrecord componentstartedAt- the value for thestartedAtrecord componentelapsed- the value for theelapsedrecord component
-
-
Method Details
-
initial
Creates an initial state for a swarm.- Parameters:
swarmId- swarm IDmemberCount- member countbehavior- 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 IDmemberCount- current member countbehavior- current behaviortickCount- total ticksrunning- is runningenvironment- shared environmentavgNeighbors- average neighbor countstartedAt- 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
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
swarmId
Returns the value of theswarmIdrecord component.- Returns:
- the value of the
swarmIdrecord component
-
memberCount
public int memberCount()Returns the value of thememberCountrecord component.- Returns:
- the value of the
memberCountrecord component
-
behavior
Returns the value of thebehaviorrecord component.- Returns:
- the value of the
behaviorrecord component
-
tickCount
public long tickCount()Returns the value of thetickCountrecord component.- Returns:
- the value of the
tickCountrecord component
-
running
public boolean running()Returns the value of therunningrecord component.- Returns:
- the value of the
runningrecord component
-
pheromoneLocations
public int pheromoneLocations()Returns the value of thepheromoneLocationsrecord component.- Returns:
- the value of the
pheromoneLocationsrecord component
-
activePheromones
public int activePheromones()Returns the value of theactivePheromonesrecord component.- Returns:
- the value of the
activePheromonesrecord component
-
environmentSize
public int environmentSize()Returns the value of theenvironmentSizerecord component.- Returns:
- the value of the
environmentSizerecord component
-
neighborConnections
public double neighborConnections()Returns the value of theneighborConnectionsrecord component.- Returns:
- the value of the
neighborConnectionsrecord component
-
startedAt
Returns the value of thestartedAtrecord component.- Returns:
- the value of the
startedAtrecord component
-
elapsed
Returns the value of theelapsedrecord component.- Returns:
- the value of the
elapsedrecord component
-