Record Class SimpleRoll

java.lang.Object
java.lang.Record
net.royalur.model.dice.SimpleRoll
Record Components:
value - The value of the dice roll.
All Implemented Interfaces:
Roll

public record SimpleRoll(int value) extends Record implements Roll
A roll of dice that contains just a value.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final SimpleRoll
    A constant representing a roll of four.
    static final SimpleRoll
    A constant representing a roll of one.
    static final SimpleRoll
    A constant representing a roll of three.
    static final SimpleRoll
    A constant representing a roll of two.
    static final SimpleRoll
    A constant representing a roll of zero.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleRoll(int value)
    Instantiates a dice roll.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Indicates whether some other object is "equal to" this one.
    int
    Returns a hash code value for this object.
    static SimpleRoll
    of(int value)
    Generates a roll representing a roll of the value value.
    Returns a string representation of this record class.
    int
    Gets the value of this dice roll.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • ZERO

      public static final SimpleRoll ZERO
      A constant representing a roll of zero.
    • ONE

      public static final SimpleRoll ONE
      A constant representing a roll of one.
    • TWO

      public static final SimpleRoll TWO
      A constant representing a roll of two.
    • THREE

      public static final SimpleRoll THREE
      A constant representing a roll of three.
    • FOUR

      public static final SimpleRoll FOUR
      A constant representing a roll of four.
  • Constructor Details

    • SimpleRoll

      public SimpleRoll(int value)
      Instantiates a dice roll.
      Parameters:
      value - The value of the roll.
  • Method Details

    • value

      public int value()
      Gets the value of this dice roll.
      Specified by:
      value in interface Roll
      Returns:
      The value of this dice roll.
    • hashCode

      public 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 boolean equals(@Nullable Object obj)
      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. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • toString

      public 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
    • of

      public static SimpleRoll of(int value)
      Generates a roll representing a roll of the value value.
      Parameters:
      value - The value that was rolled on the dice.
      Returns:
      A roll representing a roll of the value value.