/**
 *
 */
package com.github.apixandru.games.rummikub;

import java.util.Collection;
import java.util.HashSet;

/**
 * @author Alexandru-Constantin Bledea
 * @since Sep 16, 2015
 */
final class Cards {

	/**
	 *
	 */
	private Cards() {
	}

	/**
	 * @return
	 */
	static boolean isDifferentColors(final Collection<Card> cards) {
		final Collection<Color> colors = new HashSet<>();
		for (final Card card : cards) {
			final Color cardColor = card.getColor();
			if (null == cardColor) {
				continue;
			}
			if (colors.contains(cardColor)) {
				return false;
			}
			colors.add(cardColor);
		}
		return true;
	}

	/**
	 * @param cards
	 * @return
	 */
	static boolean isSameRanks(final Collection<Card> cards) {
		final Rank rank = getFirstRank(cards);
		for (final Card card : cards) {
			final Rank cardRank = card.getRank();
			if (null != cardRank && rank != cardRank) {
				return false;
			}
		}
		return true;
	}

	/**
	 * @param cards
	 * @return
	 */
	public static boolean isAscendingRanks(final Collection<Card> cards) {
		Rank expected = null;
		boolean first = true;
		for (final Card card : cards) {
			final Rank rank = card.getRank();
			if (first) {
				expected = rank;
				first = false;
			}
//			if rank is null then joker, matches
			if (rank != null && expected != rank) {
				return false;
			}
			expected = Rank.next(expected);
		}
		return true;
	}


	/**
	 * @param cards
	 * @return
	 */
	private static Rank getFirstRank(final Collection<Card> cards) {
		for (final Card card : cards) {
			final Rank rank = card.getRank();
			if (null != rank) {
				return rank;
			}
		}
		return null;
	}

}

@@ -908,32 +908,586 @@
 eturn true;%0A%09%7D%0A%0A
+%09/**%0A%09 * @return%0A%09 */%0A%09static boolean isAllSameColor(final Collection%3CCard%3E cards) %7B%0A%09%09final Color color = getFirstColor(cards);%0A%09%09for (final Card card : cards) %7B%0A%09%09%09final Color cardColor = card.getColor();%0A%09%09%09if (null != cardColor && color != cardColor) %7B%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return true;%0A%09%7D%0A%0A%09/**%0A%09 * @param cards%0A%09 * @return%0A%09 */%0A%09private static Color getFirstColor(final Collection%3CCard%3E cards) %7B%0A%09%09for (final Card card : cards) %7B%0A%09%09%09final Color color = card.getColor();%0A%09%09%09if (null != color) %7B%0A%09%09%09%09return color;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return null;%0A%09%7D%0A%0A
 %09/**%0A%09 * @param 

add more utility methods