/**
 *  Content:   Cache.java
 *  Author:    Jakob Svensson (c) 2008
 */

package seed.minerva.cache;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;

/**
 * @deprecated Replaced by seed.minerva.cache.common.CacheService and its implmentors.
 * 
 */
public class Cache implements Serializable {	
	private static final long serialVersionUID = 1L;	
	
	HashMap<Key,Object> map = new HashMap<Key,Object>();
	HashMap<String,Object> properties = new HashMap<String,Object>();
	
	public void put(Key key, Object value) {
		map.put(key,value);
	}
	
	public Object get(Key key) {
		return map.get(key);
	}
	
	public Object[] getAllValues(){
		return map.values().toArray();
	}
	
	public void clear() {
		map.clear();
	}
	
	public void addProperty(String name, Object value) {
		properties.put(name, value);
	}
	
	public void removeProperty(String name) {
		properties.remove(name);
	}
	
	public Object getProperty(String name) {
		return properties.get(name);
	}
	
	/** Returns the internal HashMap object used to store the entries */
	public HashMap getMap(){ return map; }
	
	public static class Key implements Serializable {	
		private static final long serialVersionUID = 1L;	
		
		private Object[] objects;
		
		public Key(double[]...array) {
			objects = new Object[array.length];
			for(int i=0;i<array.length;++i) {
				objects[i] = array[i];
			}		
		}
		
		public Key(Object[] objects) {
			this.objects = objects;
		}		
		
		@Override
		public boolean equals(Object arg0) {			
			return Arrays.deepEquals(objects, ((Key) arg0).objects);
		}
		
		@Override
		public int hashCode() {						
			return Arrays.deepHashCode(objects);
		}
		
		public Object[] getObjects(){ return objects; }
	}	
	
	
}
