package edu.unl.consystlab.sudokuSolver;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.Hashtable;


public class problemDomain
{
	//private String domainName;
	private List domainValues;
	private String domainName;

	//default constructor
	//nothing should call this.
//	public problemDomain()
//	{
//		domainValues = new LinkedList();
//
//	}
	
	//only used when making a copy
	private problemDomain(List newList, String newName, constraintProblem newProblem)
	{
		domainValues = new LinkedList(newList);
		domainName = newName;
		newProblem.addDomain(this, domainName);
		
	}
	
	public problemDomain copy(constraintProblem newProblem)
	{
		List newDomainValues = new LinkedList();
		Iterator i = domainValues.iterator();
		while(i.hasNext())
		{
			newDomainValues.add(new String((String)i.next()));
		}
		return( new problemDomain(newDomainValues, domainName, newProblem));
	}

	public problemDomain(String newDomainName, constraintProblem currentProblem)
	{
		domainName = newDomainName;
		currentProblem.addDomain(this, domainName);

		domainValues = new LinkedList();

	}

	public String toString()
	{
		return ( domainValues.toString() );
	}

	public void addElementToDomain(String newElement)
	{
		domainValues.add(newElement);
		return;
	}


	//acepts ranges like "3..7"
	public void addRangeToDomain(String newRange)
	{
		//Integer begin = Integer.valueOf(newRange.charAt(0));
		//int pointer = begin.intValue();
		String[] limits = null;
		limits = newRange.split("[.][.]");

		Integer begin = Integer.valueOf(limits[0]);
		int pointer = begin.intValue();

		Integer end = Integer.valueOf(limits[1]);
		int lastElement = end.intValue();


		while(pointer <= lastElement)
		{
			domainValues.add(Integer.toString(pointer));
			pointer++;
		}

		return;
	}

	public List getDomainList()
	{
		return domainValues;
	}

	public String getName()
	{
		return domainName;
	}
}
