package com.backfire.arithmetic;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
/**   
 * @Title: CardAssist.java
 * @Package com.backfire.card
 * @Description: TODO(用一句话描述该文件做什么)
 * @author Potter
 * @date 2013-10-7 下午5:30:21
 * @version V2.0   
 */
public class CardAssist {
	
	/**升序**/
	public static class Asc implements Comparator<Card>{
		@Override
		public int compare(Card object1, Card other) {
			if (object1.getPoint() == other.getPoint())
				return 0;
			else if (object1.getPoint() > other.getPoint())
				return 1;
			else
				return -1;
		}
	}

	/**降序**/
	public static class Desc implements Comparator<Card>{
		@Override
		public int compare(Card object1, Card other) {
			if (object1.getPoint() == other.getPoint())
				return 0;
			else if (object1.getPoint() > other.getPoint())
				return -1;
			else
				return 1;
		}
	}
	
	public static int indexOf(Card card,ArrayList<Card> cards){
		if(null==card||null==cards)return -1;
		int idx=-1;
		synchronized (cards) {
			for(Card cd:cards){
				if(0==cd.comparePoint(card)){
					idx=cards.indexOf(cd);
					break;
				}
			}
		}
		return idx;
	}
	
	/*public static Card cardFromCardInfo(CardInfo cardInfo, boolean orgLaizi){
		boolean isLaizi = cardInfo.getLaiziFace() > 0;
	    int cardFace = isLaizi ? (orgLaizi ? cardInfo.getLaiziFace() : cardInfo.getLaiziFace()) : cardInfo.getCardFace();
	    Card card=new Card(cardInfo.getCardSuit(), cardFace);
	    card.setIsLaiZi(isLaizi);
	    return card;
	}*/
	
	public static Card[] copyArray(Card[] resCards){
		if(null==resCards)return null;
		Card[] tmpCards=null;
		synchronized (resCards) {
			tmpCards=new Card[resCards.length];
			for(int i=0;i<resCards.length;i++){
				if(resCards[i]!=null)tmpCards[i]=new Card(resCards[i]);
			}
		}
		return tmpCards;
	}
	
	public static ArrayList<Card> copyList(ArrayList<Card> reCards){
		if(null==reCards)return null;
		ArrayList<Card> copyCards=null;
		synchronized (reCards) {
			copyCards= new ArrayList<Card>(Arrays.asList(new Card[reCards.size()]));
	        Collections.copy(copyCards, reCards);
		}
		return copyCards;
	}
	
}
