package speiger.src.collections.shorts.maps.interfaces;

import speiger.src.collections.shorts.utils.maps.Short2IntMaps;
import speiger.src.collections.shorts.maps.abstracts.AbstractShort2IntMap;
import speiger.src.collections.ints.collections.IntOrderedCollection;
import speiger.src.collections.shorts.sets.ShortOrderedSet;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.sets.ObjectOrderedSet;
/**
 * A Special Map Interface giving Access to some really usefull functions
 * The Idea behind this interface is to allow access to functions that give control to the Order of elements.
 * Since Linked implementations as examples can be reordered outside of the Insertion Order.
 * This interface provides basic access to such functions while also providing some Sorted/NaivgableMap implementations that still fit into here.
 * 
 */
public interface Short2IntOrderedMap extends Short2IntMap
{
	/**
	 * A customized put method that allows you to insert into the first index.
	 * @param key the key that should be inserted
	 * @param value the value that should be inserted
	 * @return the previous present or default return value
	 * @see java.util.Map#put(Object, Object)
	 */
	public int putAndMoveToFirst(short key, int value);
	
	/**
	 * A customized put method that allows you to insert into the last index. (This may be nessesary depending on the implementation)
	 * @param key the key that should be inserted
	 * @param value the value that should be inserted
	 * @return the previous present or default return value
	 * @see java.util.Map#put(Object, Object)
	 */
	public int putAndMoveToLast(short key, int value);
	
	/**
	 * A alternative to putAndMoveToFirst.
	 * This method simply puts an entry at the first spot of the Map but only if the entry is missing.
	 * @param key the key that should be inserted
	 * @param value the value that should be inserted
	 * @return the previous present or default return value
	 * @see java.util.Map#put(Object, Object)
	 */
	public int putFirst(short key, int value);
	
	/**
	 * A alternative to putAndMoveToLast.
	 * This method simply puts an entry at the last spot of the Map but only if the entry is missing.
	 * @param key the key that should be inserted
	 * @param value the value that should be inserted
	 * @return the previous present or default return value
	 * @see java.util.Map#put(Object, Object)
	 */
	public int putLast(short key, int value);
	
	/**
	 * A specific move method to move a given key/value to the first index.
	 * @param key that should be moved to the first index
	 * @return true if the value was moved.
	 * @note returns false if the value was not present in the first place
	 */
	public boolean moveToFirst(short key);
	/**
	 * A specific move method to move a given key/value to the last index.
	 * @param key that should be moved to the first last
	 * @return true if the value was moved.
	 * @note returns false if the value was not present in the first place
	 */
	public boolean moveToLast(short key);
	
	/**
	 * A Specific get method that allows to move teh given key/value int the first index.
	 * @param key that is searched for
	 * @return the given value for the requested key or default return value
	 */
	public int getAndMoveToFirst(short key);
	/**
	 * A Specific get method that allows to move teh given key/value int the last index.
	 * @param key that is searched for
	 * @return the given value for the requested key or default return value
	 */
	public int getAndMoveToLast(short key);
	
	/**
	 * A method to get the first Key of a Map.
	 * @return the first key in the map
	 */
	public short firstShortKey();
	/**
	 * A method to get and remove the first Key of a Map.
	 * @return the first key in the map
	 */
	public short pollFirstShortKey();
	/**
	 * A method to get the last Key of a Map.
	 * @return the last key in the map
	 */
	public short lastShortKey();
	/**
	 * A method to get and remove the last Key of a Map.
	 * @return the last key in the map
	 */
	public short pollLastShortKey();
	
	/**
	 * A method to get the first Value of a Map.
	 * @return the first key in the map
	 */
	public int firstIntValue();
	/**
	 * A method to get the last Value of a Map.
	 * @return the last key in the map
	 */
	public int lastIntValue();
	
	
	public Short2IntMap.Entry firstEntry();
	
	public Short2IntMap.Entry lastEntry();
	
	public Short2IntMap.Entry pollFirstEntry();
	
	public Short2IntMap.Entry pollLastEntry();
	@Override
	public Short2IntOrderedMap copy();
	@Override
	public ShortOrderedSet keySet();
	@Override
	public IntOrderedCollection values();
	@Override
	public ObjectOrderedSet<Short2IntMap.Entry> short2IntEntrySet();
	
	public default Short2IntOrderedMap reversed() { return new AbstractShort2IntMap.ReversedShort2IntOrderedMap(this); }
	
	/**
	 * Creates a Wrapped SortedMap that is Synchronized
	 * @return a new SortedMap that is synchronized
	 * @see Short2IntMaps#synchronize
	 */
	@Override
	public default Short2IntOrderedMap synchronize() { return Short2IntMaps.synchronize(this); }
	
	/**
	 * Creates a Wrapped SortedMap that is Synchronized
	 * @param mutex is the controller of the synchronization block
	 * @return a new SortedMap Wrapper that is synchronized
	 * @see Short2IntMaps#synchronize
	 */
	@Override
	public default Short2IntOrderedMap synchronize(Object mutex) { return Short2IntMaps.synchronize(this, mutex); }
	
	/**
	 * Creates a Wrapped SortedMap that is unmodifiable
	 * @return a new SortedMap Wrapper that is unmodifiable
	 * @see Short2IntMaps#unmodifiable
	 */
	@Override
	public default Short2IntOrderedMap unmodifiable() { return Short2IntMaps.unmodifiable(this); }
	
	/**
	 * Fast Ordered Entry Set that allows for a faster Entry Iterator by recycling the Entry Object and just exchanging 1 internal value
	 */
	interface FastOrderedSet extends Short2IntMap.FastEntrySet, ObjectOrderedSet<Short2IntMap.Entry> {
		@Override
		public ObjectBidirectionalIterator<Short2IntMap.Entry> fastIterator();
		/**
		 * Fast iterator that recycles the given Entry object to improve speed and reduce object allocation
		 * @param fromElement that is going to be started from.
		 * @return a improved iterator that starts from the desired element
		 */
		public ObjectBidirectionalIterator<Short2IntMap.Entry> fastIterator(short fromElement);
	}
}