lambda-8-b45: bug report: contents of offending program

v.a.ammodytes at googlemail.com v.a.ammodytes at googlemail.com
Sun Jul 1 16:33:13 PDT 2012


As the list does not seem to provide access to attachments, I repeat the contents of the 
offending program:


import java.util.*;

public class CardGameC {

    private CardGameC() {
        throw new RuntimeException("no instances !");
    }

    public static void main(String[] args) {
        Dealer dealer = n -> {
            Deal d = new Deal();
            Iterable<Integer> zeroToN =
                new Iterable<Integer>() {
                    public Iterator<Integer> iterator() {
                        return new Iterator<Integer>() {
                            private int i = 0;
                            public boolean hasNext() { return i < n; }
                            public Integer next() { return i++; }
                        };
                    }
                };
            zeroToN.forEach( c -> { d.addCard(() -> c); });
            d.shuffle();
            return d;
        };
        Deal deal = dealer.dealCards(52);
        System.out.println("Dealing the cards");
        deal.getCards().forEach( c -> { System.out.printf("%1s%-2s ", c.getSuitAsString(), 
c.getCardValueAsString()); } );
        System.out.println();
    }

}

interface Dealer {
    Deal dealCards(int numberOfCards);
}

class Deal {
    private List<Card> cards = new ArrayList<>();
    public Deal() {
    }
    public void addCard(Card card) {
        cards.add(card);
    }
    public Iterable<Card> getCards() {
        return cards;
    }
    public void shuffle() {
        Collections.shuffle(cards);
    }
}

interface Card {
    static final String[] SUITS = new String[] { "C", "D", "H", "S" };
    static final String[] CARD_VALUES = new String[] { "2", "3", "4", "5", "6", "7", "8", "9", "10", 
"J", "Q", "K", "A" };

    int getCardNum();

    int getSuit() default {
        return getCardNum() % 4;
    }

    int getCardValue() default {
        return getCardNum() / 4;
    }

    String getSuitAsString() default {
        return SUITS[getSuit()];
    }

    String getCardValueAsString() default {
        return CARD_VALUES[getCardValue()];
    }
}



More information about the lambda-dev mailing list