Skip to content
Snippets Groups Projects
Commit c1a78434 authored by Sander August Heggland Schrader's avatar Sander August Heggland Schrader
Browse files

Added more lambda functions

parent 5ac0f150
Branches
No related tags found
No related merge requests found
......@@ -45,7 +45,7 @@ public class CardHand {
* @return Arraylist of PlayingCards
*/
public ArrayList<PlayingCard> getAllWithSuit(String type) {
return new ArrayList<PlayingCard>(cards.stream().filter(c -> Character.toString(c.getSuit()).equalsIgnoreCase(type)).collect(Collectors.toList()));
return cards.stream().filter(c -> Character.toString(c.getSuit()).equalsIgnoreCase(type)).collect(Collectors.toCollection(ArrayList::new));
}
/**
......@@ -60,7 +60,7 @@ public class CardHand {
* @return
*/
public int getCardSum() {
return cards.stream().map(c -> c.getFace()).reduce(0, Integer::sum);
return cards.stream().map(PlayingCard::getFace).reduce(0, Integer::sum);
}
/**
......
......@@ -49,7 +49,7 @@ public class DeckOfCards {
ArrayList<PlayingCard> cards = new ArrayList<>();
// Pick cards for n or until there are no cards in the deck.
IntStream.range(0, n < deck.size() ? n : deck.size()).forEach(i -> {
IntStream.range(0, Math.min(n, deck.size())).forEach(i -> {
PlayingCard card = deck.get(random.nextInt(deck.size()));
cards.add(card);
deck.remove(card);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment