Package javatro.core

Record Class Card


public record Card(Card.Rank rank, Card.Suit suit) extends Record
Represents a playing card with a rank and a suit in a card game. Each card has a specific rank (e.g., ACE, KING) and suit (e.g., HEARTS, SPADES). The card's rank determines both its display symbol and its chip value in gameplay.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enumeration of card ranks with associated symbols and chip values.
    static enum 
    Enumeration of card suits with full display names.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Card(Card other)
    Constructs a new card by copying an existing card instance.
    Card(Card.Rank rank, Card.Suit suit)
    Compact constructor to validate card components.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    int
    Returns the chip value of this card based on its rank.
    final int
    Returns a hash code value for this object.
    Returns the value of the rank record component.
    Returns the value of the suit record component.
    Returns a human-readable string representation of the card.

    Methods inherited from class java.lang.Object

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

    • Card

      public Card(Card.Rank rank, Card.Suit suit)
      Compact constructor to validate card components.
    • Card

      public Card(Card other)
      Constructs a new card by copying an existing card instance.
      Parameters:
      other - The card to copy. Must not be null.
  • Method Details

    • getChips

      public int getChips()
      Returns the chip value of this card based on its rank.
      Returns:
      Chip value for game calculations
    • toString

      public String toString()
      Returns a human-readable string representation of the card. Format: "[Symbol] of [Suit]" (e.g., "A of Hearts").
      Specified by:
      toString in class Record
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • rank

      public Card.Rank rank()
      Returns the value of the rank record component.
      Returns:
      the value of the rank record component
    • suit

      public Card.Suit suit()
      Returns the value of the suit record component.
      Returns:
      the value of the suit record component