Refactoring and Deprecating SortedMap/Sets

- Added: OrderedMap/Set
- Added: All Relevant functions into Ordered interface
- Changed: Marked all Relevant SortedMap/Set functions Deprecated until
0.6.0
- Fixed: All code that was relevant to this
This commit is contained in:
Speiger 2021-12-25 03:46:51 +01:00
parent 3274e96355
commit e6c9600b40
32 changed files with 720 additions and 187 deletions

View File

@ -218,6 +218,7 @@ public class GlobalVariables
addClassMapper("LIST_ITER", "ListIter");
addClassMapper("LIST", "List");
addBiClassMapper("NAVIGABLE_MAP", "NavigableMap", "2");
addBiClassMapper("ORDERED_MAP", "OrderedMap", "2");
addBiClassMapper("SORTED_MAP", "SortedMap", "2");
addBiClassMapper("MAP", "Map", "2");
addClassMapper("NAVIGABLE_SET", "NavigableSet");
@ -226,6 +227,7 @@ public class GlobalVariables
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
addClassMapper("PREDICATE", "2BooleanFunction");
addClassMapper("SORTED_SET", "SortedSet");
addClassMapper("ORDERED_SET", "OrderedSet");
addClassMapper("SET", "Set");
addClassMapper("STRATEGY", "Strategy");
addClassMapper("STACK", "Stack");

View File

@ -73,7 +73,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
biRequired.put("Pair", "");
biRequired.put("MutablePair", "");
biRequired.put("ImmutablePair", "");
addBiClass("Function", "Maps", "Map", "SortedMap", "NavigableMap", "AbstractMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
addBiClass("Function", "Maps", "Map", "SortedMap", "OrderedMap", "NavigableMap", "AbstractMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
nameRemapper.put("BiConsumer", "%sConsumer");
nameRemapper.put("IArray", "I%sArray");
nameRemapper.put("AbstractMap", "Abstract%sMap");
@ -88,8 +88,8 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack");
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
addBlockage(ClassType.BOOLEAN, "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "NavigableMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "OrderedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
addBlockage(ClassType.BOOLEAN, "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
}
protected void create(ClassType mainType, ClassType subType)

View File

@ -21,6 +21,7 @@ import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
@ -71,7 +72,7 @@ import speiger.src.collections.utils.HashUtil;
* @Type(T)
* @ValueType(V)
*/
public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
{
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
protected transient long[] links;

View File

@ -22,6 +22,7 @@ import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
import speiger.src.collections.PACKAGE.sets.SET;
@ -70,7 +71,7 @@ import speiger.src.collections.utils.HashUtil;
* @Type(T)
* @ValueType(V)
*/
public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
{
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
protected transient long[] links;

View File

@ -26,6 +26,7 @@ import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
@ -83,7 +84,7 @@ import speiger.src.collections.utils.HashUtil;
* @Type(T)
* @ValueType(V)
*/
public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
{
/** The Backing keys array */
protected transient KEY_TYPE[] keys;

View File

@ -16,6 +16,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
@ -42,7 +43,7 @@ import speiger.src.collections.objects.sets.ObjectSet;
* @Type(T)
* @ValueType(V)
*/
public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
{
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
protected long[] links;

View File

@ -0,0 +1,117 @@
package speiger.src.collections.PACKAGE.maps.interfaces;
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
/**
* 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.
*
* @Type(T)
* @ValueType(V)
*/
public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERIC_TYPE
{
/**
* 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 VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE 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 VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE 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(KEY_TYPE 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(KEY_TYPE 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 VALUE_TYPE getAndMoveToFirst(KEY_TYPE 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 VALUE_TYPE getAndMoveToLast(KEY_TYPE key);
/**
* A method to get the first Key of a Map.
* @return the first key in the map
*/
public KEY_TYPE FIRST_ENTRY_KEY();
/**
* A method to get and remove the first Key of a Map.
* @return the first key in the map
*/
public KEY_TYPE POLL_FIRST_ENTRY_KEY();
/**
* A method to get the last Key of a Map.
* @return the last key in the map
*/
public KEY_TYPE LAST_ENTRY_KEY();
/**
* A method to get and remove the last Key of a Map.
* @return the last key in the map
*/
public KEY_TYPE POLL_LAST_ENTRY_KEY();
/**
* A method to get the first Value of a Map.
* @return the first key in the map
*/
public VALUE_TYPE FIRST_ENTRY_VALUE();
/**
* A method to get the last Value of a Map.
* @return the last key in the map
*/
public VALUE_TYPE LAST_ENTRY_VALUE();
@Override
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
/**
* Creates a Wrapped SortedMap that is Synchronized
* @return a new SortedMap that is synchronized
* @see MAPS#synchronize
*/
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.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 MAPS#synchronize
*/
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
/**
* Creates a Wrapped SortedMap that is unmodifiable
* @return a new SortedMap Wrapper that is unmodifiable
* @see MAPS#unmodifiable
*/
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
}

View File

@ -19,8 +19,10 @@ import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
*
* @Type(T)
* @ValueType(V)
* @note ORDERED_MAP is only extended until 0.6.0 for Compat reasons.
* The supported classes already implement ORDERED_MAP directly and will remove SORTED_MAP implementations in favor of ORDERED_MAP instead
*/
public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE, CLASS_VALUE_TYPE>, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
{
/**
* A customized put method that allows you to insert into the first index.
@ -29,6 +31,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @return the previous present or default return value
* @see java.util.Map#put(Object, Object)
* @note some implementations do not support this method
* @deprecated use ORDERED_MAP#putAndMoveToFirst instead (removed in 0.6.0)
*/
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value);
/**
@ -38,6 +41,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @return the previous present or default return value
* @see java.util.Map#put(Object, Object)
* @note some implementations do not support this method
* @deprecated use ORDERED_MAP#putAndMoveToLast instead (removed in 0.6.0)
*/
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
@ -47,6 +51,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @return true if the value was moved.
* @note returns false if the value was not present in the first place
* @note some implementations do not support this method
* @deprecated use ORDERED_MAP#moveToFirst instead (removed in 0.6.0)
*/
public boolean moveToFirst(KEY_TYPE key);
/**
@ -55,6 +60,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @return true if the value was moved.
* @note returns false if the value was not present in the first place
* @note some implementations do not support this method
* @deprecated use ORDERED_MAP#moveToLast instead (removed in 0.6.0)
*/
public boolean moveToLast(KEY_TYPE key);
@ -63,6 +69,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @param key that is searched for
* @return the given value for the requested key or default return value
* @note some implementations do not support this method
* @deprecated use ORDERED_MAP#getAndMoveToFirst instead (removed in 0.6.0)
*/
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key);
/**
@ -70,6 +77,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @param key that is searched for
* @return the given value for the requested key or default return value
* @note some implementations do not support this method
* @deprecated use ORDERED_MAP#getAndMoveToLast instead (removed in 0.6.0)
*/
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key);

View File

@ -36,7 +36,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
* This implementation does not shrink the backing array
* @Type(T)
*/
public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE, ORDERED_SET KEY_GENERIC_TYPE
{
/** The Backing Array */
protected transient KEY_TYPE[] data;

View File

@ -37,7 +37,7 @@ import speiger.src.collections.utils.SanityChecks;
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
* @Type(T)
*/
public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE, ORDERED_SET KEY_GENERIC_TYPE
{
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
protected transient long[] links;

View File

@ -38,7 +38,7 @@ import speiger.src.collections.utils.SanityChecks;
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
* @Type(T)
*/
public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE, ORDERED_SET KEY_GENERIC_TYPE
{
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
protected transient long[] links;

View File

@ -0,0 +1,114 @@
package speiger.src.collections.PACKAGE.sets;
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
import speiger.src.collections.PACKAGE.utils.SETS;
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
/**
* A Special Set 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/NaivgableSet implementations that still fit into here.
*
* @Type(T)
*/
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
{
/**
* A customized add method that allows you to insert into the first index.
* @param o the element that should be inserted
* @return true if it was added
* @see java.util.Set#add(Object)
*/
public boolean addAndMoveToFirst(KEY_TYPE o);
/**
* A customized add method that allows you to insert into the last index.
* @param o the element that should be inserted
* @return true if it was added
* @see java.util.Set#add(Object)
*/
public boolean addAndMoveToLast(KEY_TYPE o);
/**
* A specific move method to move a given key to the first index.
* @param o 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(KEY_TYPE o);
/**
* A specific move method to move a given key to the last index.
* @param o 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(KEY_TYPE o);
@Override
public ORDERED_SET KEY_GENERIC_TYPE copy();
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
/**
* A type Specific Iterator starting from a given key
* @param fromElement the element the iterator should start from
* @return a iterator starting from the given element
* @throws java.util.NoSuchElementException if fromElement isn't found
*/
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
/**
* A Type Specific Type Splititerator to reduce boxing/unboxing
* @return type specific splititerator
*/
@Override
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
/**
* A method to get the first element in the set
* @return first element in the set
*/
public KEY_TYPE FIRST_KEY();
/**
* A method to get and remove the first element in the set
* @return first element in the set
*/
public KEY_TYPE POLL_FIRST_KEY();
/**
* A method to get the last element in the set
* @return last element in the set
*/
public KEY_TYPE LAST_KEY();
/**
* A method to get and remove the last element in the set
* @return last element in the set
*/
public KEY_TYPE POLL_LAST_KEY();
#if !TYPE_BOOLEAN
/**
* Creates a Wrapped OrderedSet that is Synchronized
* @return a new OrderedSet that is synchronized
* @see SETS#synchronize
*/
public default ORDERED_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
/**
* Creates a Wrapped OrderedSet that is Synchronized
* @param mutex is the controller of the synchronization block
* @return a new OrderedSet Wrapper that is synchronized
* @see SETS#synchronize
*/
public default ORDERED_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
/**
* Creates a Wrapped OrderedSet that is unmodifiable
* @return a new OrderedSet Wrapper that is unmodifiable
* @see SETS#unmodifiable
*/
public default ORDERED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
#endif
}

View File

@ -16,8 +16,10 @@ import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
* A Type Specific SortedSet implementation to reduce boxing/unboxing
* with a couple extra methods that allow greater control over sets.
* @Type(T)
* @note ORDERED_SET is only extended until 0.6.0 for Compat reasons.
* The supported classes already implement ORDERED_SET directly and will remove SORTED_SET implementations in favor of ORDERED_SET instead
*/
public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
public interface SORTED_SET KEY_GENERIC_TYPE extends ORDERED_SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
{
/**
@ -26,6 +28,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
* @return true if it was added
* @see java.util.Set#add(Object)
* @note some implementations do not support this method
* @deprecated use ORDERED_SET#addAndMoveToFirst instead (removed in 0.6.0)
*/
public boolean addAndMoveToFirst(KEY_TYPE o);
/**
@ -34,6 +37,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
* @return true if it was added
* @see java.util.Set#add(Object)
* @note some implementations do not support this method
* @deprecated use ORDERED_SET#addAndMoveToLast instead (removed in 0.6.0)
*/
public boolean addAndMoveToLast(KEY_TYPE o);
@ -43,6 +47,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
* @return true if the value was moved.
* @note returns false if the value was not present in the first place
* @note some implementations do not support this method
* @deprecated use ORDERED_SET#moveToFirst instead (removed in 0.6.0)
*/
public boolean moveToFirst(KEY_TYPE o);
/**
@ -51,6 +56,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
* @return true if the value was moved.
* @note returns false if the value was not present in the first place
* @note some implementations do not support this method
* @deprecated use ORDERED_SET#moveToLast instead (removed in 0.6.0)
*/
public boolean moveToLast(KEY_TYPE o);

View File

@ -18,6 +18,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
import speiger.src.collections.PACKAGE.sets.SET;
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.EmptyCollection;
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.SynchronizedCollection;
@ -95,6 +96,29 @@ public class SETS
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s, mutex) : new SynchronizedSortedSetBRACES(s, mutex));
}
/**
* Creates a Synchronized OrderedSet while preserving the ITrimmable interface
* @param s the set that should be synchronized
* @Type(T)
* @return a OrderedSet that is synchronized
* @note if the set is already synchronized then it will just self return it
*/
public static GENERIC_KEY_BRACES ORDERED_SET KEY_GENERIC_TYPE synchronize(ORDERED_SET KEY_GENERIC_TYPE s) {
return s instanceof SynchronizedOrderedSet ? s : (s instanceof ITrimmable ? new SynchronizedOrderedTrimSetBRACES(s) : new SynchronizedOrderedSetBRACES(s));
}
/**
* Creates a Synchronized OrderedSet while preserving the ITrimmable interface
* @param s the set that should be synchronized
* @param mutex controller for access
* @Type(T)
* @return a OrderedSet that is synchronized
* @note if the set is already synchronized then it will just self return it
*/
public static GENERIC_KEY_BRACES ORDERED_SET KEY_GENERIC_TYPE synchronize(ORDERED_SET KEY_GENERIC_TYPE s, Object mutex) {
return s instanceof SynchronizedOrderedSet ? s : (s instanceof ITrimmable ? new SynchronizedOrderedTrimSetBRACES(s, mutex) : new SynchronizedOrderedSetBRACES(s, mutex));
}
/**
* Creates a Synchronized NavigableSet while preserving the ITrimmable interface
* @param s the set that should be synchronized
@ -138,6 +162,16 @@ public class SETS
return s instanceof UnmodifiableSortedSet ? s : new UnmodifiableSortedSetBRACES(s);
}
/**
* Creates Unmodifyable OrderedSet wrapper
* @param s OrderedSet that should be made unmodifiable
* @Type(T)
* @return a UnmodifyableOrderedSet, if the set is already unmodifiable then it returns itself
*/
public static GENERIC_KEY_BRACES ORDERED_SET KEY_GENERIC_TYPE unmodifiable(ORDERED_SET KEY_GENERIC_TYPE s) {
return s instanceof UnmodifiableOrderedSet ? s : new UnmodifiableOrderedSetBRACES(s);
}
/**
* Creates Unmodifyable NavigableSet wrapper
* @param s navigableSet that should be made unmodifiable
@ -278,6 +312,39 @@ public class SETS
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); }
}
private static class UnmodifiableOrderedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
{
ORDERED_SET KEY_GENERIC_TYPE s;
UnmodifiableOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c)
{
super(c);
s = c;
}
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
@Override
public ORDERED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
@Override
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
@Override
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
@Override
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
@Override
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
}
private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
{
SORTED_SET KEY_GENERIC_TYPE s;
@ -288,47 +355,37 @@ public class SETS
}
@Override
@Deprecated
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return s.comparator(); }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
@Override
public SORTED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
@Override
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(s.subSet(fromElement, toElement)); }
@Override
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(s.headSet(toElement)); }
@Override
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(s.tailSet(fromElement)); }
@Override
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
@Override
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
@Override
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
@Override
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
}
@ -490,47 +547,96 @@ public class SETS
}
@Override
@Deprecated
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
@Override
@Deprecated
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
@Override
@Deprecated
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
@Override
@Deprecated
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator(){ synchronized(mutex) { return s.comparator(); } }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
@Override
public SORTED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
@Override
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.subSet(fromElement, toElement), mutex); } }
@Override
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.headSet(toElement), mutex); } }
@Override
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(s.tailSet(fromElement), mutex); } }
@Override
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
@Override
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
@Override
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
@Override
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
}
private static class SynchronizedOrderedTrimSet KEY_GENERIC_TYPE extends SynchronizedOrderedSet KEY_GENERIC_TYPE implements ITrimmable
{
ITrimmable trim;
SynchronizedOrderedTrimSet(ORDERED_SET KEY_GENERIC_TYPE c) {
super(c);
trim = (ITrimmable)c;
}
SynchronizedOrderedTrimSet(ORDERED_SET KEY_GENERIC_TYPE c, Object mutex) {
super(c, mutex);
trim = (ITrimmable)c;
}
@Override
public boolean trim(int size) { synchronized(mutex) { return trim.trim(size); } }
@Override
public void clearAndTrim(int size) { synchronized(mutex) { trim.clearAndTrim(size); } }
}
private static class SynchronizedOrderedSet KEY_GENERIC_TYPE extends SynchronizedSet KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
{
ORDERED_SET KEY_GENERIC_TYPE s;
SynchronizedOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c) {
super(c);
s = c;
}
SynchronizedOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c, Object mutex) {
super(c, mutex);
s = c;
}
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
@Override
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
@Override
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
@Override
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
@Override
public ORDERED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
@Override
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
@Override
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
@Override
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
@Override
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
}

View File

@ -32,6 +32,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
#if !TYPE_BOOLEAN
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.sets.SET;
@ -161,6 +162,28 @@ public class MAPS
*/
public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedSortedMap ? map : new SynchronizedSortedMapKV_BRACES(map, mutex); }
/**
* Helper function that creates a Helper wrapper to synchronize access into the OrderedMap.
* @param map the OrderedMap that should be synchronized
* @Type(T)
* @ValueType(V)
* @return a synchronized OrderedMap
* @note if the inputted map is already synchronized then it will just return it instead
* @note iterators do not support synchronization
*/
public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof SynchronizedOrderedMap ? map : new SynchronizedOrderedMapKV_BRACES(map); }
/**
* Helper function that creates a Helper wrapper to synchronize access with custom access control into the OrderedMap.
* @param map the OrderedMap that should be synchronized
* @param mutex the object that controls access
* @Type(T)
* @ValueType(V)
* @return a synchronized OrderedMap
* @note if the inputted map is already synchronized then it will just return it instead
* @note iterators do not support synchronization
*/
public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedOrderedMap ? map : new SynchronizedOrderedMapKV_BRACES(map, mutex); }
/**
* Helper function that creates a Helper wrapper to synchronize access into the NavigableMap.
* @param map the NavigableMap that should be synchronized
@ -192,6 +215,17 @@ public class MAPS
* @note if the inputted map is already unmodifiable then it will just return it instead
*/
public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE unmodifiable(MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableMap ? map : new UnmodifyableMapKV_BRACES(map); }
/**
* A Helper function that creates a Helper wrapper to only allow Read Access into the OrderedMap
* @param map the OrderedMap that should be made Unmodifiable
* @Type(T)
* @ValueType(V)
* @return a unmodifiable OrderedMap
* @note if the inputted OrderedMap is already unmodifiable then it will just return it instead
*/
public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableOrderedMap ? map : new UnmodifyableOrderedMapKV_BRACES(map); }
/**
* A Helper function that creates a Helper wrapper to only allow Read Access into the SortedMap
* @param map the SortedMap that should be made Unmodifiable
@ -201,6 +235,7 @@ public class MAPS
* @note if the inputted SortedMap is already unmodifiable then it will just return it instead
*/
public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableSortedMap ? map : new UnmodifyableSortedMapKV_BRACES(map); }
/**
* A Helper function that creates a Helper wrapper to only allow Read Access into NavigableMap Map
* @param map the NavigableMap that should be made Unmodifiable
@ -210,6 +245,7 @@ public class MAPS
* @note if the inputted NavigableMap is already unmodifiable then it will just return it instead
*/
public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableNavigableMap ? map : new UnmodifyableNavigableMapKV_BRACES(map); }
/**
* A Helper function that creates a Unmodifyable Entry
* @param entry the Entry that should be made unmodifiable
@ -424,14 +460,14 @@ public class MAPS
}
/**
* The Unmodifyable Sorted Map implementation that is sued for the unmodifyableMap function
* The Unmodifyable Ordered Map implementation that is sued for the unmodifyableMap function
* @Type(T)
* @ValueType(V)
*/
public static class UnmodifyableSortedMap KEY_VALUE_GENERIC_TYPE extends UnmodifyableMap KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE {
SORTED_MAP KEY_VALUE_GENERIC_TYPE map;
public static class UnmodifyableOrderedMap KEY_VALUE_GENERIC_TYPE extends UnmodifyableMap KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE {
ORDERED_MAP KEY_VALUE_GENERIC_TYPE map;
UnmodifyableSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) {
UnmodifyableOrderedMap(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) {
super(map);
this.map = map;
}
@ -449,6 +485,53 @@ public class MAPS
@Override
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
@Override
public KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
@Override
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
@Override
public KEY_TYPE LAST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
@Override
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return map.POLL_LAST_ENTRY_KEY(); }
@Override
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
@Override
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
@Override
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
}
/**
* The Unmodifyable Sorted Map implementation that is sued for the unmodifyableMap function
* @Type(T)
* @ValueType(V)
*/
public static class UnmodifyableSortedMap KEY_VALUE_GENERIC_TYPE extends UnmodifyableMap KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE {
SORTED_MAP KEY_VALUE_GENERIC_TYPE map;
UnmodifyableSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) {
super(map);
this.map = map;
}
@Override
@Deprecated
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); }
@Override
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return MAPS.unmodifiable(map.subMap(fromKey, toKey)); }
@ -680,6 +763,52 @@ public class MAPS
#endif
}
/**
* The Synchronized Ordered Map implementation used by the synchronizedMap helper function
* @Type(T)
* @ValueType(V)
*/
public static class SynchronizedOrderedMap KEY_VALUE_GENERIC_TYPE extends SynchronizedMap KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE {
ORDERED_MAP KEY_VALUE_GENERIC_TYPE map;
SynchronizedOrderedMap(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) {
super(map);
this.map = map;
}
SynchronizedOrderedMap(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) {
super(map, mutex);
this.map = map;
}
@Override
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToFirst(key, value); } }
@Override
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } }
@Override
public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } }
@Override
public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } }
@Override
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToFirst(key); } }
@Override
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToLast(key); } }
@Override
public KEY_TYPE FIRST_ENTRY_KEY() { synchronized(mutex) { return map.FIRST_ENTRY_KEY(); } }
@Override
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { synchronized(mutex) { return map.POLL_FIRST_ENTRY_KEY(); } }
@Override
public KEY_TYPE LAST_ENTRY_KEY() { synchronized(mutex) { return map.LAST_ENTRY_KEY(); } }
@Override
public KEY_TYPE POLL_LAST_ENTRY_KEY() { synchronized(mutex) { return map.POLL_LAST_ENTRY_KEY(); } }
@Override
public VALUE_TYPE FIRST_ENTRY_VALUE() { synchronized(mutex) { return map.FIRST_ENTRY_VALUE(); } }
@Override
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
@Override
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
}
/**
* The Synchronized Sorted Map implementation used by the synchronizedMap helper function
* @Type(T)
@ -699,16 +828,22 @@ public class MAPS
}
@Override
@Deprecated
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToFirst(key, value); } }
@Override
@Deprecated
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } }
@Override
@Deprecated
public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } }
@Override
@Deprecated
public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } }
@Override
@Deprecated
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToFirst(key); } }
@Override
@Deprecated
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToLast(key); } }
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { synchronized(mutex) { return map.comparator(); } }

View File

@ -0,0 +1,75 @@
package speiger.src.collections.ints.base;
import java.util.EnumSet;
import org.junit.Assert;
import org.junit.Test;
import speiger.src.collections.ints.maps.interfaces.Int2IntOrderedMap;
import speiger.src.collections.tests.OrderedMapTests;
@SuppressWarnings("javadoc")
public abstract class BaseInt2IntOrderedMapTest extends BaseInt2IntMapTest
{
@Override
public abstract Int2IntOrderedMap createMap(int[] keys, int[] values);
@Override
public abstract Int2IntOrderedMap createEmptyMap();
public EnumSet<OrderedMapTests> getValidOrderedMapTests() { return EnumSet.allOf(OrderedMapTests.class); }
@Test
public void testPutMove()
{
if(!getValidOrderedMapTests().contains(OrderedMapTests.PUT_MOVE)) return;
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
Assert.assertEquals(0, map.putAndMoveToFirst(120, -1));
Assert.assertEquals(120, map.firstIntKey());
Assert.assertEquals(-1, map.firstIntValue());
Assert.assertEquals(0, map.putAndMoveToLast(121, -2));
Assert.assertEquals(121, map.lastIntKey());
Assert.assertEquals(-2, map.lastIntValue());
}
@Test
public void testMove()
{
if(!getValidOrderedMapTests().contains(OrderedMapTests.MOVE)) return;
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
Assert.assertTrue(map.moveToFirst(99));
Assert.assertFalse(map.moveToFirst(99));
Assert.assertEquals(99, map.firstIntKey());
Assert.assertTrue(map.moveToLast(0));
Assert.assertFalse(map.moveToLast(0));
Assert.assertEquals(0, map.lastIntKey());
}
@Test
public void testGetMove()
{
if(!getValidOrderedMapTests().contains(OrderedMapTests.GET_MOVE)) return;
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
Assert.assertNotEquals(99, map.firstIntValue());
Assert.assertEquals(99, map.getAndMoveToFirst(99));
Assert.assertEquals(99, map.firstIntValue());
Assert.assertNotEquals(0, map.lastIntValue());
Assert.assertEquals(0, map.getAndMoveToLast(0));
Assert.assertEquals(0, map.lastIntValue());
}
@Test
public void testFirst()
{
if(!getValidOrderedMapTests().contains(OrderedMapTests.FIRST)) return;
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
Assert.assertEquals(map.pollFirstIntKey(), 0);
}
@Test
public void testLast()
{
if(!getValidOrderedMapTests().contains(OrderedMapTests.LAST)) return;
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
Assert.assertEquals(map.pollLastIntKey(), 99);
}
}

View File

@ -18,45 +18,6 @@ public abstract class BaseInt2IntSortedMapTest extends BaseInt2IntMapTest
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.allOf(SortedMapTests.class); }
@Test
public void testPutMove()
{
if(!getValidSortedMapTests().contains(SortedMapTests.PUT_MOVE)) return;
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
Assert.assertEquals(0, map.putAndMoveToFirst(120, -1));
Assert.assertEquals(120, map.firstIntKey());
Assert.assertEquals(-1, map.firstIntValue());
Assert.assertEquals(0, map.putAndMoveToLast(121, -2));
Assert.assertEquals(121, map.lastIntKey());
Assert.assertEquals(-2, map.lastIntValue());
}
@Test
public void testMove()
{
if(!getValidSortedMapTests().contains(SortedMapTests.MOVE)) return;
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
Assert.assertTrue(map.moveToFirst(99));
Assert.assertFalse(map.moveToFirst(99));
Assert.assertEquals(99, map.firstIntKey());
Assert.assertTrue(map.moveToLast(0));
Assert.assertFalse(map.moveToLast(0));
Assert.assertEquals(0, map.lastIntKey());
}
@Test
public void testGetMove()
{
if(!getValidSortedMapTests().contains(SortedMapTests.GET_MOVE)) return;
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
Assert.assertNotEquals(99, map.firstIntValue());
Assert.assertEquals(99, map.getAndMoveToFirst(99));
Assert.assertEquals(99, map.firstIntValue());
Assert.assertNotEquals(0, map.lastIntValue());
Assert.assertEquals(0, map.getAndMoveToLast(0));
Assert.assertEquals(0, map.lastIntValue());
}
@Test
public void testFirst()
{

View File

@ -0,0 +1,63 @@
package speiger.src.collections.ints.base;
import java.util.EnumSet;
import org.junit.Assert;
import org.junit.Test;
import speiger.src.collections.ints.sets.IntOrderedSet;
import speiger.src.collections.tests.OrderedSetTest;
@SuppressWarnings("javadoc")
public abstract class BaseIntOrderedSetTest extends BaseIntCollectionTest
{
@Override
protected abstract IntOrderedSet create(int[] data);
protected EnumSet<OrderedSetTest> getValidOrderedSetTests() { return EnumSet.allOf(OrderedSetTest.class); }
@Test
public void addMoveTest() {
if(getValidOrderedSetTests().contains(OrderedSetTest.ADD_MOVE)) {
IntOrderedSet set = create(TEST_ARRAY);
Assert.assertTrue(set.addAndMoveToFirst(1050));
Assert.assertFalse(set.addAndMoveToLast(5));
}
}
@Test
public void moveTest() {
if(getValidOrderedSetTests().contains(OrderedSetTest.MOVE)) {
IntOrderedSet set = create(TEST_ARRAY);
Assert.assertTrue(set.moveToFirst(5));
Assert.assertFalse(set.moveToFirst(5));
Assert.assertTrue(set.moveToLast(5));
Assert.assertFalse(set.moveToLast(5));
}
}
@Test
public void peekTest() {
if(getValidOrderedSetTests().contains(OrderedSetTest.PEEK)) {
IntOrderedSet set = create(TEST_ARRAY);
Assert.assertEquals(set.firstInt(), 0);
Assert.assertEquals(set.lastInt(), 99);
}
}
@Test
public void pollTest() {
if(getValidOrderedSetTests().contains(OrderedSetTest.POLL)) {
IntOrderedSet set = create(TEST_ARRAY);
for(int i = 0;i<100;i++)
{
Assert.assertEquals(i, set.pollFirstInt());
}
set = create(TEST_ARRAY);
for(int i = 99;i>=0;i--)
{
Assert.assertEquals(i, set.pollLastInt());
}
}
}
}

View File

@ -16,26 +16,6 @@ public abstract class BaseIntSortedSetTest extends BaseIntCollectionTest
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.allOf(SortedSetTest.class); }
@Test
public void addMoveTest() {
if(getValidSortedSetTests().contains(SortedSetTest.ADD_MOVE)) {
IntSortedSet set = create(TEST_ARRAY);
Assert.assertTrue(set.addAndMoveToFirst(1050));
Assert.assertFalse(set.addAndMoveToLast(5));
}
}
@Test
public void moveTest() {
if(getValidSortedSetTests().contains(SortedSetTest.MOVE)) {
IntSortedSet set = create(TEST_ARRAY);
Assert.assertTrue(set.moveToFirst(5));
Assert.assertFalse(set.moveToFirst(5));
Assert.assertTrue(set.moveToLast(5));
Assert.assertFalse(set.moveToLast(5));
}
}
@Test
public void peekTest() {
if(getValidSortedSetTests().contains(SortedSetTest.PEEK)) {

View File

@ -1,18 +1,12 @@
package speiger.src.collections.ints.maps;
import java.util.EnumSet;
import speiger.src.collections.ints.base.BaseInt2IntNavigableMapTest;
import speiger.src.collections.ints.maps.impl.tree.Int2IntAVLTreeMap;
import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
import speiger.src.collections.tests.SortedMapTests;
@SuppressWarnings("javadoc")
public class Int2IntAVLTreeMapTest extends BaseInt2IntNavigableMapTest
{
@Override
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.GET_MOVE, SortedMapTests.MOVE, SortedMapTests.PUT_MOVE)); }
{
@Override
public Int2IntNavigableMap createMap(int[] keys, int[] values)
{

View File

@ -1,26 +1,20 @@
package speiger.src.collections.ints.maps;
import java.util.EnumSet;
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
import speiger.src.collections.ints.base.BaseInt2IntOrderedMapTest;
import speiger.src.collections.ints.maps.impl.misc.Int2IntArrayMap;
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
import speiger.src.collections.tests.SortedMapTests;
import speiger.src.collections.ints.maps.interfaces.Int2IntOrderedMap;
@SuppressWarnings("javadoc")
public class Int2IntArrayMapTest extends BaseInt2IntSortedMapTest
{
public class Int2IntArrayMapTest extends BaseInt2IntOrderedMapTest
{
@Override
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.SUB_MAP, SortedMapTests.HEAD_MAP, SortedMapTests.TAIL_MAP)); }
@Override
public Int2IntSortedMap createMap(int[] keys, int[] values)
public Int2IntOrderedMap createMap(int[] keys, int[] values)
{
return new Int2IntArrayMap(keys, values);
}
@Override
public Int2IntSortedMap createEmptyMap()
public Int2IntOrderedMap createEmptyMap()
{
return new Int2IntArrayMap();
}

View File

@ -1,26 +1,20 @@
package speiger.src.collections.ints.maps;
import java.util.EnumSet;
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
import speiger.src.collections.ints.base.BaseInt2IntOrderedMapTest;
import speiger.src.collections.ints.maps.impl.customHash.Int2IntLinkedOpenCustomHashMap;
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
import speiger.src.collections.tests.SortedMapTests;
import speiger.src.collections.ints.maps.interfaces.Int2IntOrderedMap;
@SuppressWarnings("javadoc")
public class Int2IntLinkedOpenCustomHashMapTest extends BaseInt2IntSortedMapTest
{
public class Int2IntLinkedOpenCustomHashMapTest extends BaseInt2IntOrderedMapTest
{
@Override
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.SUB_MAP, SortedMapTests.TAIL_MAP, SortedMapTests.HEAD_MAP)); }
@Override
public Int2IntSortedMap createMap(int[] keys, int[] values)
public Int2IntOrderedMap createMap(int[] keys, int[] values)
{
return new Int2IntLinkedOpenCustomHashMap(keys, values, STRATEGY);
}
@Override
public Int2IntSortedMap createEmptyMap()
public Int2IntOrderedMap createEmptyMap()
{
return new Int2IntLinkedOpenCustomHashMap(STRATEGY);
}

View File

@ -1,26 +1,20 @@
package speiger.src.collections.ints.maps;
import java.util.EnumSet;
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
import speiger.src.collections.ints.base.BaseInt2IntOrderedMapTest;
import speiger.src.collections.ints.maps.impl.hash.Int2IntLinkedOpenHashMap;
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
import speiger.src.collections.tests.SortedMapTests;
import speiger.src.collections.ints.maps.interfaces.Int2IntOrderedMap;
@SuppressWarnings("javadoc")
public class Int2IntLinkedOpenHashMapTest extends BaseInt2IntSortedMapTest
public class Int2IntLinkedOpenHashMapTest extends BaseInt2IntOrderedMapTest
{
@Override
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.SUB_MAP, SortedMapTests.TAIL_MAP, SortedMapTests.HEAD_MAP)); }
@Override
public Int2IntSortedMap createMap(int[] keys, int[] values)
public Int2IntOrderedMap createMap(int[] keys, int[] values)
{
return new Int2IntLinkedOpenHashMap(keys, values);
}
@Override
public Int2IntSortedMap createEmptyMap()
public Int2IntOrderedMap createEmptyMap()
{
return new Int2IntLinkedOpenHashMap();
}

View File

@ -1,18 +1,12 @@
package speiger.src.collections.ints.maps;
import java.util.EnumSet;
import speiger.src.collections.ints.base.BaseInt2IntNavigableMapTest;
import speiger.src.collections.ints.maps.impl.tree.Int2IntRBTreeMap;
import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
import speiger.src.collections.tests.SortedMapTests;
@SuppressWarnings("javadoc")
public class Int2IntRBTreeMapTest extends BaseInt2IntNavigableMapTest
{
@Override
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.GET_MOVE, SortedMapTests.MOVE, SortedMapTests.PUT_MOVE)); }
@Override
public Int2IntNavigableMap createMap(int[] keys, int[] values)
{

View File

@ -1,9 +1,6 @@
package speiger.src.collections.ints.sets;
import java.util.EnumSet;
import speiger.src.collections.ints.base.BaseIntNavigableSetTest;
import speiger.src.collections.tests.SortedSetTest;
@SuppressWarnings("javadoc")
public class IntAVLTreeSetTests extends BaseIntNavigableSetTest
@ -12,7 +9,4 @@ public class IntAVLTreeSetTests extends BaseIntNavigableSetTest
protected IntNavigableSet create(int[] data) {
return new IntAVLTreeSet(data);
}
@Override
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.of(SortedSetTest.PEEK, SortedSetTest.POLL, SortedSetTest.HEAD_SET, SortedSetTest.SUB_SET, SortedSetTest.TAIL_SET);}
}

View File

@ -1,15 +1,10 @@
package speiger.src.collections.ints.sets;
import java.util.EnumSet;
import speiger.src.collections.ints.base.BaseIntSortedSetTest;
import speiger.src.collections.tests.SortedSetTest;
import speiger.src.collections.ints.base.BaseIntOrderedSetTest;
@SuppressWarnings("javadoc")
public class IntArraySetTests extends BaseIntSortedSetTest
public class IntArraySetTests extends BaseIntOrderedSetTest
{
@Override
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.complementOf(EnumSet.of(SortedSetTest.SUB_SET, SortedSetTest.HEAD_SET, SortedSetTest.TAIL_SET)); }
@Override
protected IntSortedSet create(int[] data) { return new IntArraySet(data.clone()); }
protected IntOrderedSet create(int[] data) { return new IntArraySet(data.clone()); }
}

View File

@ -3,21 +3,14 @@ package speiger.src.collections.ints.sets;
import java.util.EnumSet;
import speiger.src.collections.ints.base.BaseIntCollectionTest;
import speiger.src.collections.ints.base.BaseIntSortedSetTest;
import speiger.src.collections.ints.base.BaseIntOrderedSetTest;
import speiger.src.collections.ints.collections.IntCollection;
import speiger.src.collections.ints.utils.IntStrategy;
import speiger.src.collections.tests.CollectionTest;
import speiger.src.collections.tests.SortedSetTest;
@SuppressWarnings("javadoc")
public class IntHashSetTests
{
public static abstract class BaseIntOpenHashSetTests extends BaseIntSortedSetTest
{
@Override
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.of(SortedSetTest.ADD_MOVE, SortedSetTest.MOVE, SortedSetTest.PEEK, SortedSetTest.POLL); }
}
public static class IntOpenHashSetTests extends BaseIntCollectionTest
{
@Override
@ -32,10 +25,10 @@ public class IntHashSetTests
}
}
public static class IntLinkedOpenHashSetTests extends BaseIntOpenHashSetTests
public static class IntLinkedOpenHashSetTests extends BaseIntOrderedSetTest
{
@Override
protected IntSortedSet create(int[] data) { return new IntLinkedOpenHashSet(data); }
protected IntOrderedSet create(int[] data) { return new IntLinkedOpenHashSet(data); }
}
public static class IntOpenCustomHashSetTests extends BaseIntCollectionTest
@ -52,10 +45,10 @@ public class IntHashSetTests
}
}
public static class IntLinkedOpenCustomHashSetTests extends BaseIntOpenHashSetTests
public static class IntLinkedOpenCustomHashSetTests extends BaseIntOrderedSetTest
{
@Override
protected IntSortedSet create(int[] data) { return new IntLinkedOpenCustomHashSet(data, new DefaultStrategy()); }
protected IntOrderedSet create(int[] data) { return new IntLinkedOpenCustomHashSet(data, new DefaultStrategy()); }
}
public static class DefaultStrategy implements IntStrategy

View File

@ -1,9 +1,6 @@
package speiger.src.collections.ints.sets;
import java.util.EnumSet;
import speiger.src.collections.ints.base.BaseIntNavigableSetTest;
import speiger.src.collections.tests.SortedSetTest;
@SuppressWarnings("javadoc")
public class IntRBTreeSetTests extends BaseIntNavigableSetTest
@ -13,7 +10,4 @@ public class IntRBTreeSetTests extends BaseIntNavigableSetTest
protected IntNavigableSet create(int[] data) {
return new IntRBTreeSet(data);
}
@Override
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.of(SortedSetTest.PEEK, SortedSetTest.POLL, SortedSetTest.HEAD_SET, SortedSetTest.SUB_SET, SortedSetTest.TAIL_SET);}
}

View File

@ -0,0 +1,11 @@
package speiger.src.collections.tests;
@SuppressWarnings("javadoc")
public enum OrderedMapTests
{
PUT_MOVE,
MOVE,
GET_MOVE,
FIRST,
LAST;
}

View File

@ -0,0 +1,10 @@
package speiger.src.collections.tests;
@SuppressWarnings("javadoc")
public enum OrderedSetTest
{
ADD_MOVE,
MOVE,
PEEK,
POLL;
}

View File

@ -3,9 +3,6 @@ package speiger.src.collections.tests;
@SuppressWarnings("javadoc")
public enum SortedMapTests
{
PUT_MOVE,
MOVE,
GET_MOVE,
FIRST,
LAST,
SUB_MAP,

View File

@ -3,8 +3,6 @@ package speiger.src.collections.tests;
@SuppressWarnings("javadoc")
public enum SortedSetTest
{
ADD_MOVE,
MOVE,
PEEK,
POLL,
SUB_SET,