package com.poker.analyst.analyser.combanalyzer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import com.poker.analyst.analyser.CardComparator;
import com.poker.analyst.combination.Pair;
import com.poker.analyst.element.Card;
import com.poker.analyst.element.CardFace;
import com.poker.analyst.element.PlayingCards;
public class PairAnalyzer {
public static List<Pair> analysePair(PlayingCards plCards){
Set<Card> allCards = new TreeSet<Card>(new CardComparator());
for (Card card: plCards.getPlayerCards())
if (card != null) allCards.add(card);
for (Card card: plCards.getTableCards())
if (card != null) allCards.add(card);
return analysePair(allCards, plCards);
}
public static List<Card> getListOfCardsByFace(Set<Card> allCards,CardFace cardFace){
List<Card> combinationList = new ArrayList<Card>();
for (Card card: allCards){
if (card.getFace().equals(cardFace))
combinationList.add(card);
}
return combinationList.size() == 0 ? null : combinationList;
}
public static List<Pair> analysePair(Set<Card> allCards, PlayingCards plCards){
Pair pair = null;
List<Pair> pairs = null;
int count = 0;
int i = 0;
CardFace cardFace = null;
for (Card card: allCards){
i++;
if (card.getFace().equals(cardFace))
count++;
else{
if (count == 2){
if (pairs == null) pairs = new ArrayList<Pair>();
pair = new Pair();
pair.setCombinationList(getListOfCardsByFace(allCards,cardFace));
pairs.add(pair);
}
cardFace = card.getFace();
count = 1;
}
}
if (count == 2){
if (pairs == null) pairs = new ArrayList<Pair>();
pair = new Pair();
pair.setCombinationList(getListOfCardsByFace(allCards,cardFace));
pairs.add(pair);
}
return pairs;
}
}