Class Hand


  • public class Hand
    extends java.lang.Object
    Objects of this class representing a hand of Poker Cards.
    Since:
    17.08.2016 07:11:36
    Author:
    Nico Danneberg
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Card[] cards
      Stores the cards of this hand.
      private java.util.Hashtable<Value,​java.lang.Integer> values
      Stores for every value the number of cards with this values in the current hand.
    • Constructor Summary

      Constructors 
      Constructor Description
      Hand​(Card[] cards)
      Creates a hand with all given cards.
      Hand​(Card c1, Card c2, Card c3, Card c4, Card c5)
      Creates a hand with all five given cards.
    • Method Summary

      Modifier and Type Method Description
      boolean beats​(Hand h)
      Checks if the current hand beats the given one by comparing the value of both hands.
      long getValue()
      The complete value of a five card poker hand can be represented in a 5-digit big hexadecimal number.
      boolean isFlush()
      Tests if this hand is a Flush.
      boolean isFourOfAKind()
      Tests if this hand is a Four of a Kind.
      boolean isFullHouse()
      Tests if this hand is a Full House.
      boolean isHighCard()
      Tests if this hand is just a High Card.
      boolean isOnePair()
      Tests if this hand is a One Pair.
      boolean isRoyalFlush()
      Tests if this hand is a Royal Flush.
      boolean isStraight()
      Tests if this hand is a Straight.
      boolean isStraightFlush()
      Tests if this hand is a Straight Flush.
      boolean isThreeOfAKind()
      Tests if this hand is a Three of a Kind.
      boolean isTwoPairs()
      Tests if this hand is a Two Pairs.
      java.lang.String toString()
      Creates a string representation of this hand.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • cards

        private Card[] cards
        Stores the cards of this hand.
        See Also:
        Card
      • values

        private java.util.Hashtable<Value,​java.lang.Integer> values
        Stores for every value the number of cards with this values in the current hand.
        See Also:
        Value
    • Constructor Detail

      • Hand

        public Hand​(Card c1,
                    Card c2,
                    Card c3,
                    Card c4,
                    Card c5)
        Creates a hand with all five given cards.
        Parameters:
        c1 - 1st card
        c2 - 2nd card
        c3 - 3rd card
        c4 - 4th card
        c5 - 5th card
        See Also:
        Hand(Card[])
      • Hand

        public Hand​(Card[] cards)
        Creates a hand with all given cards. Therefore the given array is stored into cards which is sorted immediately. Afterwards the values is written to speed up later calculations.
        Parameters:
        cards - an array of cards
    • Method Detail

      • beats

        public boolean beats​(Hand h)
        Checks if the current hand beats the given one by comparing the value of both hands.
        Parameters:
        h - another hand
        Returns:
        true if the current hand's value is greater than the given hand's
        See Also:
        getValue()
      • getValue

        public long getValue()
        The complete value of a five card poker hand can be represented in a 5-digit big hexadecimal number. Here this number is calculated.
        Returns:
        the numeric value of the hand
      • isFlush

        public boolean isFlush()
        Tests if this hand is a Flush.
        Returns:
        true if all cards has the same suit
        See Also:
        Card.getSuit()
      • isFourOfAKind

        public boolean isFourOfAKind()
        Tests if this hand is a Four of a Kind.
        Returns:
        true if fours cards has the same value
        See Also:
        Card.getValue()
      • isFullHouse

        public boolean isFullHouse()
        Tests if this hand is a Full House.
        Returns:
        true if three cards has the same value and the other two has an equal value, too
        See Also:
        Card.getValue()
      • isHighCard

        public boolean isHighCard()
        Tests if this hand is just a High Card.
        Returns:
        true if all cards' values exist only once
        See Also:
        Card.getValue()
      • isOnePair

        public boolean isOnePair()
        Tests if this hand is a One Pair.
        Returns:
        true if only two cards has the same value
        See Also:
        Card.getValue()
      • isRoyalFlush

        public boolean isRoyalFlush()
        Tests if this hand is a Royal Flush.
        Returns:
        true if this hand is a Flush, and a Straight, and the lowest card is a ten
        See Also:
        isFlush(), isStraight()
      • isStraight

        public boolean isStraight()
        Tests if this hand is a Straight.
        Returns:
        true if all cards' value are in an consecutive order
        See Also:
        Card.getNumericValue()
      • isStraightFlush

        public boolean isStraightFlush()
        Tests if this hand is a Straight Flush.
        Returns:
        true if this hand is a Flush and a Straight
        See Also:
        isFlush(), isStraight()
      • isThreeOfAKind

        public boolean isThreeOfAKind()
        Tests if this hand is a Three of a Kind.
        Returns:
        true if three cards has the same value and the rest is no pair
      • isTwoPairs

        public boolean isTwoPairs()
        Tests if this hand is a Two Pairs.
        Returns:
        true if exactly two different cards' values exist twice
      • toString

        public java.lang.String toString()
        Creates a string representation of this hand.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string a combination of all cards in this hand
        See Also:
        Card.toString()