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

import speiger.src.collections.longs.utils.maps.Long2ShortMaps;
import speiger.src.collections.longs.maps.abstracts.AbstractLong2ShortMap;
import speiger.src.collections.shorts.collections.ShortOrderedCollection;
import speiger.src.collections.longs.sets.LongOrderedSet;
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 Long2ShortOrderedMap extends Long2ShortMap
{
	/**
	 * 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 short putAndMoveToFirst(long key, short 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 short putAndMoveToLast(long key, short 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 short putFirst(long key, short 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 short putLast(long key, short 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(long 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(long 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 short getAndMoveToFirst(long 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 short getAndMoveToLast(long key);
	
	/**
	 * A method to get the first Key of a Map.
	 * @return the first key in the map
	 */
	public long firstLongKey();
	/**
	 * A method to get and remove the first Key of a Map.
	 * @return the first key in the map
	 */
	public long pollFirstLongKey();
	/**
	 * A method to get the last Key of a Map.
	 * @return the last key in the map
	 */
	public long lastLongKey();
	/**
	 * A method to get and remove the last Key of a Map.
	 * @return the last key in the map
	 */
	public long pollLastLongKey();
	
	/**
	 * A method to get the first Value of a Map.
	 * @return the first key in the map
	 */
	public short firstShortValue();
	/**
	 * A method to get the last Value of a Map.
	 * @return the last key in the map
	 */
	public short lastShortValue();
	
	
	public Long2ShortMap.Entry firstEntry();
	
	public Long2ShortMap.Entry lastEntry();
	
	public Long2ShortMap.Entry pollFirstEntry();
	
	public Long2ShortMap.Entry pollLastEntry();
	@Override
	public Long2ShortOrderedMap copy();
	@Override
	public LongOrderedSet keySet();
	@Override
	public ShortOrderedCollection values();
	@Override
	public ObjectOrderedSet<Long2ShortMap.Entry> long2ShortEntrySet();
	
	public default Long2ShortOrderedMap reversed() { return new AbstractLong2ShortMap.ReversedLong2ShortOrderedMap(this); }
	
	/**
	 * Creates a Wrapped SortedMap that is Synchronized
	 * @return a new SortedMap that is synchronized
	 * @see Long2ShortMaps#synchronize
	 */
	@Override
	public default Long2ShortOrderedMap synchronize() { return Long2ShortMaps.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 Long2ShortMaps#synchronize
	 */
	@Override
	public default Long2ShortOrderedMap synchronize(Object mutex) { return Long2ShortMaps.synchronize(this, mutex); }
	
	/**
	 * Creates a Wrapped SortedMap that is unmodifiable
	 * @return a new SortedMap Wrapper that is unmodifiable
	 * @see Long2ShortMaps#unmodifiable
	 */
	@Override
	public default Long2ShortOrderedMap unmodifiable() { return Long2ShortMaps.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 Long2ShortMap.FastEntrySet, ObjectOrderedSet<Long2ShortMap.Entry> {
		@Override
		public ObjectBidirectionalIterator<Long2ShortMap.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<Long2ShortMap.Entry> fastIterator(long fromElement);
	}
}