package jrummikub.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import jrummikub.util.Pair;

/**
 * Mock class for {@link Hand}
 */
public class MockHand implements IHand {
	/** */
	public List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>();
	/** */
	public Set<Stone> pickups = new HashSet<Stone>();
	/** */
	public Iterable<Pair<Stone, Position>> iterable;

	@Override
	public void drop(Stone object, Position position) {
		stones.add(new Pair<Stone, Position>(object, position));
	}

	@Override
	public Position getPosition(Stone object) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean pickUp(Stone object) {
		List<Pair<Stone, Position>> itList = new ArrayList<Pair<Stone, Position>>(
				stones);
		for (Pair<Stone, Position> entry : itList) {
			if (entry.getFirst() == object) {
				stones.remove(entry);
				pickups.add(object);
				return true;
			}
		}
		return false;
	}

	@Override
	public int getSize() {
		return stones.size();
	}

	@Override
	public Iterator<Pair<Stone, Position>> iterator() {
		if (iterable != null) {
			return iterable.iterator();
		} else {
			return stones.iterator();
		}
	}

	public MockHand clone() {
		try {
			return (MockHand) super.clone();
		} catch (CloneNotSupportedException e) {
			return null;
		}
	}

	@Override
	public int getRowCount() {
		return 0;
	}

	@Override
	public int getFreeRowSpace(int row) {
		// TODO Auto-generated method stub
		return 0;
	}
}
