@Test public void canRecognizeHighestThreeOfAKind(){ CardSet cardSet = new CardSet( aCard(HEART, FOUR), aCard(SPADE, TWO), aCard(DIAMOND, FOUR), aCard(CLUB, THREE), aCard(SPADE, FOUR)); Hand hand = handResolver.hand(cardSet); assertThat(hand) .hasRanking(RANKING.THREE_OF_A_KIND); }
public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); List<Spec> specs = Arrays.asList( STRAIGHT_FLUSH_SPEC, FLUSH_SPEC, STRAIGHT_SPEC, FOUR_OF_A_KIND_SPEC, FULL_HOUSE_SPEC, THREE_OF_A_KIND_SPEC, TWO_PAIR_SPEC, ONE_PAIR_SPEC); return specs.stream() .filter(spec -> spec.isSatisfiedBy(cardSet)) .findFirst() .map(spec -> new Hand(spec.getRanking(), handCards)) .orElse(new Hand(HIGH_CARD, handCards)); }
HandResolver { public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); List<Spec> specs = Arrays.asList( STRAIGHT_FLUSH_SPEC, FLUSH_SPEC, STRAIGHT_SPEC, FOUR_OF_A_KIND_SPEC, FULL_HOUSE_SPEC, THREE_OF_A_KIND_SPEC, TWO_PAIR_SPEC, ONE_PAIR_SPEC); return specs.stream() .filter(spec -> spec.isSatisfiedBy(cardSet)) .findFirst() .map(spec -> new Hand(spec.getRanking(), handCards)) .orElse(new Hand(HIGH_CARD, handCards)); } }
HandResolver { public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); List<Spec> specs = Arrays.asList( STRAIGHT_FLUSH_SPEC, FLUSH_SPEC, STRAIGHT_SPEC, FOUR_OF_A_KIND_SPEC, FULL_HOUSE_SPEC, THREE_OF_A_KIND_SPEC, TWO_PAIR_SPEC, ONE_PAIR_SPEC); return specs.stream() .filter(spec -> spec.isSatisfiedBy(cardSet)) .findFirst() .map(spec -> new Hand(spec.getRanking(), handCards)) .orElse(new Hand(HIGH_CARD, handCards)); }  }
HandResolver { public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); List<Spec> specs = Arrays.asList( STRAIGHT_FLUSH_SPEC, FLUSH_SPEC, STRAIGHT_SPEC, FOUR_OF_A_KIND_SPEC, FULL_HOUSE_SPEC, THREE_OF_A_KIND_SPEC, TWO_PAIR_SPEC, ONE_PAIR_SPEC); return specs.stream() .filter(spec -> spec.isSatisfiedBy(cardSet)) .findFirst() .map(spec -> new Hand(spec.getRanking(), handCards)) .orElse(new Hand(HIGH_CARD, handCards)); }  Hand hand(CardSet cardSet); }
HandResolver { public Hand hand(CardSet cardSet) { List<Card> handCards = cardSet.getSortedCards(); List<Spec> specs = Arrays.asList( STRAIGHT_FLUSH_SPEC, FLUSH_SPEC, STRAIGHT_SPEC, FOUR_OF_A_KIND_SPEC, FULL_HOUSE_SPEC, THREE_OF_A_KIND_SPEC, TWO_PAIR_SPEC, ONE_PAIR_SPEC); return specs.stream() .filter(spec -> spec.isSatisfiedBy(cardSet)) .findFirst() .map(spec -> new Hand(spec.getRanking(), handCards)) .orElse(new Hand(HIGH_CARD, handCards)); }  Hand hand(CardSet cardSet);  }