Package net.n1da.dev.euler.helper.poker
Class Card
- java.lang.Object
-
- net.n1da.dev.euler.helper.poker.Card
-
- All Implemented Interfaces:
java.lang.Comparable<Card>
public class Card extends java.lang.Object implements java.lang.Comparable<Card>
Objects of this class representing a card known from a standard card game.- Since:
- 16.08.2016 18:13:23
- Author:
- Nico Danneberg
-
-
Method Summary
Modifier and Type Method Description int
compareTo(Card c)
Compares two cards using their numeric value of thevalue
.boolean
equals(java.lang.Object o)
Checks of two cards are equal to each other.int
getNumericValue()
Just a getter of thevalue
's numeric value.Suit
getSuit()
Just a getter of thesuit
.Value
getValue()
Just a getter of thevalue
.boolean
hasSameSuit(Card c)
Tests if a given card has the samesuit
like this card.boolean
hasSameValue(Card c)
Tests if a given card has the samevalue
like this card.boolean
set(java.lang.String vs)
java.lang.String
toString()
-
-
-
Constructor Detail
-
Card
public Card(java.lang.String vs) throws java.lang.IllegalArgumentException
Creates a card withvalue
andsuit
read from the given string. This string is a two-character code for all possible card combinations, e.g. "TH" for a Ten of Hearts.- Parameters:
vs
- a two-character string storing the value and suit of the card- Throws:
java.lang.IllegalArgumentException
- if the given string can not be interpreted as cards suit and value
-
-
Method Detail
-
compareTo
public int compareTo(Card c)
Compares two cards using their numeric value of thevalue
. If these are equal thesuits
are compared.- Specified by:
compareTo
in interfacejava.lang.Comparable<Card>
- Parameters:
c
- the other card- Returns:
- 1 of this card is higher, -1 if it is lower, and 0 if both cards are equal
-
equals
public boolean equals(java.lang.Object o)
Checks of two cards are equal to each other.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- a second card- Returns:
- true if
compareTo(Card)
returns 0
-
getNumericValue
public int getNumericValue()
Just a getter of thevalue
's numeric value.- Returns:
- the
value
's numeric value - See Also:
Value.getValue()
-
hasSameSuit
public boolean hasSameSuit(Card c)
Tests if a given card has the samesuit
like this card.- Parameters:
c
- another card- Returns:
- true, if both cards have the same suit
-
hasSameValue
public boolean hasSameValue(Card c)
Tests if a given card has the samevalue
like this card.- Parameters:
c
- another card- Returns:
- true, if both cards have the same value
-
set
public boolean set(java.lang.String vs)
Sets thevalue
andsuit
of the current card by the given string of two characters. E.g. the string "TH" is interpreted as aten
ofhearts
.- Parameters:
vs
- a two character string combined of value and suit- Returns:
- true if both, value and suit, can be read from given string
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a two character string of this card
-
-