Record Class Vote

java.lang.Object
java.lang.Record
com.tnsai.coordination.voting.Vote
Record Components:
voterId - Unique identifier of the voter
choice - Selected option (null for ranked-choice votes)
rankedChoices - Ordered preferences for ranked-choice voting
weight - 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 Details

    • Vote

      public Vote(String voterId, String choice, List<String> rankedChoices, double weight, Instant timestamp)
      Creates an instance of a Vote record class.
      Parameters:
      voterId - the value for the voterId record component
      choice - the value for the choice record component
      rankedChoices - the value for the rankedChoices record component
      weight - the value for the weight record component
      timestamp - the value for the timestamp record component
  • Method Details

    • of

      public static Vote of(String voterId, String choice)
      Creates a simple vote with default weight.
    • ofRanked

      public static Vote ofRanked(String voterId, List<String> rankedChoices)
      Creates a ranked-choice vote.
    • ofWeighted

      public static Vote ofWeighted(String voterId, String choice, double weight)
      Creates a weighted vote.
    • 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.
    • voterId

      public String voterId()
      Returns the value of the voterId record component.
      Returns:
      the value of the voterId record component
    • choice

      public String choice()
      Returns the value of the choice record component.
      Returns:
      the value of the choice record component
    • rankedChoices

      public List<String> rankedChoices()
      Returns the value of the rankedChoices record component.
      Returns:
      the value of the rankedChoices record component
    • weight

      public double weight()
      Returns the value of the weight record component.
      Returns:
      the value of the weight record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component