I'm trying to copy 'select' elements from hands[1] to hands[0]. I can successfully do this with this code:
for(Card card : hands[1].cards) {
if (card.suit().ordinal() == 0){
hands[0].addSingleCard(card);
//hands[1].removeSingleCard(card);
}
}
Unfortunately, my removeSingleCard method doesn't work how i expected. With it commented out, the for-each loop successfully copies all 'Club' cards from hands[1] to hands[0]. I was hoping the removeSingleCard method would delete each 'Club' card from hands[1] after it was copied.
public void addSingleCard(Card card){
if(card!= null){
cards.add(card);
}
}
public void removeSingleCard(Card c){
if(c!= null){
cards.remove(c);
}
}
Any ideas why this isn't working?
card.suit().ordinal() == 0test is unidiomatic. Just usecard.suit() == Suit.CLUBS. If you defined your suits in a different order, use the 0th element in the enum. Any use ofEnum.ordinal()should arouse suspicion.