package assign;
public class Map {
	private Queue list=new Queue();
	public boolean put(Object key, Object value){
		return list.put(key,value);
	}
	public void clearNodes(Object key){
		list.delNode(key);
	}
	public Object readvalue(Object key){
		return list.readvalue(key);
	}
	public boolean equal(Object key, Object value){
		return list.readvalue(key)==value;
	}
	public Object[] readAllKeys(){
		Node[] NodeArray=list.toArray();
		Object[] resultObject=new Object[NodeArray.length];
		for (int i=0;i<NodeArray.length;i++){
			resultObject[i]=NodeArray[i].key;
		}
		return resultObject;
	}
	public Object[] readAllvalue(){
		Node[] NodeArray=list.toArray();
		if (NodeArray==null) return null;
		Object[] resultObject=new Object[NodeArray.length];
		for (int i=0;i<NodeArray.length;i++){
			resultObject[i]=NodeArray[i].value;
		}
		return resultObject;
	}
	public String toString(){
		Object[] allKeys=readAllKeys();
		Object[] allvalueues=readAllvalue();
		StringBuffer resultString=new StringBuffer(allKeys.length*5);
		for (int i=0; i<allKeys.length;i++){
			resultString.append(allKeys[i]).append("|").append(allvalueues[i]);
			resultString.append("; ");
		}
		return resultString.toString();
	}
	public boolean equals(Map m){
		int n=list.count();
		if (n!=m.list.count()) return false;
		boolean equal=false;
		Object[] allKeys=this.readAllKeys();
		Object[] allKeys2=m.readAllKeys();
		Object[] allvalueues2=m.readAllvalue();
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if (allKeys[i].equals(allKeys2[j])){
					equal=this.equal(allKeys[i],allvalueues2[j]);
				}
			if (equal==false) return false;
			equal=false;
		}
		return true;
	}
	public Map concatenate(Map m){
		Map resultMap=new Map();
		Object[] allKeys=readAllKeys();
		Object newvalueue;
		for(int i=0;i<allKeys.length;i++){
			newvalueue=m.readvalue(list.readvalue( allKeys[i]));
			if (newvalueue!=null) resultMap.put(allKeys[i],newvalueue);
		}
		return resultMap;
	}
}
