Package com.tnsai.coordination.voting
Record Class Vote
java.lang.Object
java.lang.Record
com.tnsai.coordination.voting.Vote
- Record Components:
voterId- Unique identifier of the voterchoice- Selected option (null for ranked-choice votes)rankedChoices- Ordered preferences for ranked-choice votingweight- Vote weight (default 1.0)timestamp- When the vote was cast
public record Vote(String voterId, String choice, List<String> rankedChoices, double weight, Instant timestamp)
extends Record
Represents a single vote cast by a voter.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchoice()Returns the value of thechoicerecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static VoteCreates a simple vote with default weight.static VoteCreates a ranked-choice vote.static VoteofWeighted(String voterId, String choice, double weight) Creates a weighted vote.Returns the value of therankedChoicesrecord component.Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.voterId()Returns the value of thevoterIdrecord component.doubleweight()Returns the value of theweightrecord component.
-
Constructor Details
-
Vote
public Vote(String voterId, String choice, List<String> rankedChoices, double weight, Instant timestamp) Creates an instance of aVoterecord class.- Parameters:
voterId- the value for thevoterIdrecord componentchoice- the value for thechoicerecord componentrankedChoices- the value for therankedChoicesrecord componentweight- the value for theweightrecord componenttimestamp- the value for thetimestamprecord component
-
-
Method Details
-
of
Creates a simple vote with default weight. -
ofRanked
Creates a ranked-choice vote. -
ofWeighted
Creates a weighted vote. -
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 '=='. -
voterId
Returns the value of thevoterIdrecord component.- Returns:
- the value of the
voterIdrecord component
-
choice
Returns the value of thechoicerecord component.- Returns:
- the value of the
choicerecord component
-
rankedChoices
Returns the value of therankedChoicesrecord component.- Returns:
- the value of the
rankedChoicesrecord component
-
weight
public double weight()Returns the value of theweightrecord component.- Returns:
- the value of the
weightrecord component
-
timestamp
Returns the value of thetimestamprecord component.- Returns:
- the value of the
timestamprecord component
-