From e6c9600b4004d26ec8788439c75cbbb391c17389 Mon Sep 17 00:00:00 2001 From: Speiger Date: Sat, 25 Dec 2021 03:46:51 +0100 Subject: [PATCH] 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 --- .../speiger/src/builder/GlobalVariables.java | 2 + .../builder/PrimitiveCollectionsBuilder.java | 6 +- .../LinkedOpenCustomHashMap.template | 3 +- .../maps/impl/hash/LinkedOpenHashMap.template | 3 +- .../maps/impl/misc/ArrayMap.template | 3 +- .../maps/impl/misc/LinkedEnumMap.template | 3 +- .../maps/interfaces/OrderedMap.template | 117 +++++++++++++ .../maps/interfaces/SortedMap.template | 10 +- .../templates/sets/ArraySet.template | 2 +- .../sets/LinkedOpenCustomHashSet.template | 2 +- .../templates/sets/LinkedOpenHashSet.template | 2 +- .../templates/sets/OrderedSet.template | 114 +++++++++++++ .../templates/sets/SortedSet.template | 8 +- .../collections/templates/utils/Sets.template | 160 +++++++++++++++--- .../templates/utils/maps/Maps.template | 143 +++++++++++++++- .../ints/base/BaseInt2IntOrderedMapTest.java | 75 ++++++++ .../ints/base/BaseInt2IntSortedMapTest.java | 39 ----- .../ints/base/BaseIntOrderedSetTest.java | 63 +++++++ .../ints/base/BaseIntSortedSetTest.java | 20 --- .../ints/maps/Int2IntAVLTreeMapTest.java | 8 +- .../ints/maps/Int2IntArrayMapTest.java | 18 +- .../Int2IntLinkedOpenCustomHashMapTest.java | 18 +- .../maps/Int2IntLinkedOpenHashMapTest.java | 16 +- .../ints/maps/Int2IntRBTreeMapTest.java | 6 - .../ints/sets/IntAVLTreeSetTests.java | 6 - .../ints/sets/IntArraySetTests.java | 11 +- .../ints/sets/IntHashSetTests.java | 17 +- .../ints/sets/IntRBTreeSetTests.java | 6 - .../collections/tests/OrderedMapTests.java | 11 ++ .../src/collections/tests/OrderedSetTest.java | 10 ++ .../src/collections/tests/SortedMapTests.java | 3 - .../src/collections/tests/SortedSetTest.java | 2 - 32 files changed, 720 insertions(+), 187 deletions(-) create mode 100644 src/builder/resources/speiger/assets/collections/templates/maps/interfaces/OrderedMap.template create mode 100644 src/builder/resources/speiger/assets/collections/templates/sets/OrderedSet.template create mode 100644 src/test/java/speiger/src/collections/ints/base/BaseInt2IntOrderedMapTest.java create mode 100644 src/test/java/speiger/src/collections/ints/base/BaseIntOrderedSetTest.java create mode 100644 src/test/java/speiger/src/collections/tests/OrderedMapTests.java create mode 100644 src/test/java/speiger/src/collections/tests/OrderedSetTest.java diff --git a/src/builder/java/speiger/src/builder/GlobalVariables.java b/src/builder/java/speiger/src/builder/GlobalVariables.java index 192d2283..b8a153f6 100644 --- a/src/builder/java/speiger/src/builder/GlobalVariables.java +++ b/src/builder/java/speiger/src/builder/GlobalVariables.java @@ -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"); diff --git a/src/builder/java/speiger/src/builder/PrimitiveCollectionsBuilder.java b/src/builder/java/speiger/src/builder/PrimitiveCollectionsBuilder.java index 20d60088..212d336e 100644 --- a/src/builder/java/speiger/src/builder/PrimitiveCollectionsBuilder.java +++ b/src/builder/java/speiger/src/builder/PrimitiveCollectionsBuilder.java @@ -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) diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template index f4a45e3d..e214de00 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template @@ -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; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template index 9b5b19de..c4fd59bf 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template @@ -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; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template index ebef0060..2514dac5 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template @@ -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; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template index 5b1cd4b9..c9b796d3 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template @@ -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; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/OrderedMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/OrderedMap.template new file mode 100644 index 00000000..dcdfc86f --- /dev/null +++ b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/OrderedMap.template @@ -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); } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template index 56e07f97..eb07cce4 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template @@ -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, MAP KEY_VALUE_GENERIC_TYPE +public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap, 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 Previous Entry, Right 32 Bits => Next Entry */ protected transient long[] links; diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template index 67adf2ab..aa5622af 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template @@ -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; diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OrderedSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OrderedSet.template new file mode 100644 index 00000000..03ca7039 --- /dev/null +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OrderedSet.template @@ -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 +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template index ea4b683a..a6cd23e7 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template @@ -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 +public interface SORTED_SET KEY_GENERIC_TYPE extends ORDERED_SET KEY_GENERIC_TYPE, SortedSet { /** @@ -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); diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template b/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template index 057bad01..ee8cca38 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template @@ -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(); } } } diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template b/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template index ccbd4901..03071abf 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/maps/Maps.template @@ -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(); } } diff --git a/src/test/java/speiger/src/collections/ints/base/BaseInt2IntOrderedMapTest.java b/src/test/java/speiger/src/collections/ints/base/BaseInt2IntOrderedMapTest.java new file mode 100644 index 00000000..c00662d5 --- /dev/null +++ b/src/test/java/speiger/src/collections/ints/base/BaseInt2IntOrderedMapTest.java @@ -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 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); + } +} diff --git a/src/test/java/speiger/src/collections/ints/base/BaseInt2IntSortedMapTest.java b/src/test/java/speiger/src/collections/ints/base/BaseInt2IntSortedMapTest.java index c19a90e1..35358def 100644 --- a/src/test/java/speiger/src/collections/ints/base/BaseInt2IntSortedMapTest.java +++ b/src/test/java/speiger/src/collections/ints/base/BaseInt2IntSortedMapTest.java @@ -18,45 +18,6 @@ public abstract class BaseInt2IntSortedMapTest extends BaseInt2IntMapTest public EnumSet 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() { diff --git a/src/test/java/speiger/src/collections/ints/base/BaseIntOrderedSetTest.java b/src/test/java/speiger/src/collections/ints/base/BaseIntOrderedSetTest.java new file mode 100644 index 00000000..d20947a2 --- /dev/null +++ b/src/test/java/speiger/src/collections/ints/base/BaseIntOrderedSetTest.java @@ -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 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()); + } + } + } +} \ No newline at end of file diff --git a/src/test/java/speiger/src/collections/ints/base/BaseIntSortedSetTest.java b/src/test/java/speiger/src/collections/ints/base/BaseIntSortedSetTest.java index f2716a86..e8dfc0c6 100644 --- a/src/test/java/speiger/src/collections/ints/base/BaseIntSortedSetTest.java +++ b/src/test/java/speiger/src/collections/ints/base/BaseIntSortedSetTest.java @@ -16,26 +16,6 @@ public abstract class BaseIntSortedSetTest extends BaseIntCollectionTest protected EnumSet 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)) { diff --git a/src/test/java/speiger/src/collections/ints/maps/Int2IntAVLTreeMapTest.java b/src/test/java/speiger/src/collections/ints/maps/Int2IntAVLTreeMapTest.java index 35de4c25..090ecb04 100644 --- a/src/test/java/speiger/src/collections/ints/maps/Int2IntAVLTreeMapTest.java +++ b/src/test/java/speiger/src/collections/ints/maps/Int2IntAVLTreeMapTest.java @@ -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 getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.GET_MOVE, SortedMapTests.MOVE, SortedMapTests.PUT_MOVE)); } - +{ @Override public Int2IntNavigableMap createMap(int[] keys, int[] values) { diff --git a/src/test/java/speiger/src/collections/ints/maps/Int2IntArrayMapTest.java b/src/test/java/speiger/src/collections/ints/maps/Int2IntArrayMapTest.java index edca9cbc..fa43a0db 100644 --- a/src/test/java/speiger/src/collections/ints/maps/Int2IntArrayMapTest.java +++ b/src/test/java/speiger/src/collections/ints/maps/Int2IntArrayMapTest.java @@ -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 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(); } diff --git a/src/test/java/speiger/src/collections/ints/maps/Int2IntLinkedOpenCustomHashMapTest.java b/src/test/java/speiger/src/collections/ints/maps/Int2IntLinkedOpenCustomHashMapTest.java index 53668bc6..71b37d5d 100644 --- a/src/test/java/speiger/src/collections/ints/maps/Int2IntLinkedOpenCustomHashMapTest.java +++ b/src/test/java/speiger/src/collections/ints/maps/Int2IntLinkedOpenCustomHashMapTest.java @@ -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 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); } diff --git a/src/test/java/speiger/src/collections/ints/maps/Int2IntLinkedOpenHashMapTest.java b/src/test/java/speiger/src/collections/ints/maps/Int2IntLinkedOpenHashMapTest.java index 22a32c12..71d7cd11 100644 --- a/src/test/java/speiger/src/collections/ints/maps/Int2IntLinkedOpenHashMapTest.java +++ b/src/test/java/speiger/src/collections/ints/maps/Int2IntLinkedOpenHashMapTest.java @@ -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 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(); } diff --git a/src/test/java/speiger/src/collections/ints/maps/Int2IntRBTreeMapTest.java b/src/test/java/speiger/src/collections/ints/maps/Int2IntRBTreeMapTest.java index 3a0fe198..654f99f6 100644 --- a/src/test/java/speiger/src/collections/ints/maps/Int2IntRBTreeMapTest.java +++ b/src/test/java/speiger/src/collections/ints/maps/Int2IntRBTreeMapTest.java @@ -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 getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.GET_MOVE, SortedMapTests.MOVE, SortedMapTests.PUT_MOVE)); } - @Override public Int2IntNavigableMap createMap(int[] keys, int[] values) { diff --git a/src/test/java/speiger/src/collections/ints/sets/IntAVLTreeSetTests.java b/src/test/java/speiger/src/collections/ints/sets/IntAVLTreeSetTests.java index 8dc3ca09..4d2a2dad 100644 --- a/src/test/java/speiger/src/collections/ints/sets/IntAVLTreeSetTests.java +++ b/src/test/java/speiger/src/collections/ints/sets/IntAVLTreeSetTests.java @@ -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 getValidSortedSetTests() { return EnumSet.of(SortedSetTest.PEEK, SortedSetTest.POLL, SortedSetTest.HEAD_SET, SortedSetTest.SUB_SET, SortedSetTest.TAIL_SET);} } diff --git a/src/test/java/speiger/src/collections/ints/sets/IntArraySetTests.java b/src/test/java/speiger/src/collections/ints/sets/IntArraySetTests.java index ca8330e6..a625e35f 100644 --- a/src/test/java/speiger/src/collections/ints/sets/IntArraySetTests.java +++ b/src/test/java/speiger/src/collections/ints/sets/IntArraySetTests.java @@ -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 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()); } } diff --git a/src/test/java/speiger/src/collections/ints/sets/IntHashSetTests.java b/src/test/java/speiger/src/collections/ints/sets/IntHashSetTests.java index 432e635f..4d77b188 100644 --- a/src/test/java/speiger/src/collections/ints/sets/IntHashSetTests.java +++ b/src/test/java/speiger/src/collections/ints/sets/IntHashSetTests.java @@ -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 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 diff --git a/src/test/java/speiger/src/collections/ints/sets/IntRBTreeSetTests.java b/src/test/java/speiger/src/collections/ints/sets/IntRBTreeSetTests.java index 44706587..50f103a0 100644 --- a/src/test/java/speiger/src/collections/ints/sets/IntRBTreeSetTests.java +++ b/src/test/java/speiger/src/collections/ints/sets/IntRBTreeSetTests.java @@ -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 getValidSortedSetTests() { return EnumSet.of(SortedSetTest.PEEK, SortedSetTest.POLL, SortedSetTest.HEAD_SET, SortedSetTest.SUB_SET, SortedSetTest.TAIL_SET);} } diff --git a/src/test/java/speiger/src/collections/tests/OrderedMapTests.java b/src/test/java/speiger/src/collections/tests/OrderedMapTests.java new file mode 100644 index 00000000..0d40ab7f --- /dev/null +++ b/src/test/java/speiger/src/collections/tests/OrderedMapTests.java @@ -0,0 +1,11 @@ +package speiger.src.collections.tests; + +@SuppressWarnings("javadoc") +public enum OrderedMapTests +{ + PUT_MOVE, + MOVE, + GET_MOVE, + FIRST, + LAST; +} diff --git a/src/test/java/speiger/src/collections/tests/OrderedSetTest.java b/src/test/java/speiger/src/collections/tests/OrderedSetTest.java new file mode 100644 index 00000000..df271f6e --- /dev/null +++ b/src/test/java/speiger/src/collections/tests/OrderedSetTest.java @@ -0,0 +1,10 @@ +package speiger.src.collections.tests; + +@SuppressWarnings("javadoc") +public enum OrderedSetTest +{ + ADD_MOVE, + MOVE, + PEEK, + POLL; +} diff --git a/src/test/java/speiger/src/collections/tests/SortedMapTests.java b/src/test/java/speiger/src/collections/tests/SortedMapTests.java index 4ee717dd..380bfd1d 100644 --- a/src/test/java/speiger/src/collections/tests/SortedMapTests.java +++ b/src/test/java/speiger/src/collections/tests/SortedMapTests.java @@ -3,9 +3,6 @@ package speiger.src.collections.tests; @SuppressWarnings("javadoc") public enum SortedMapTests { - PUT_MOVE, - MOVE, - GET_MOVE, FIRST, LAST, SUB_MAP, diff --git a/src/test/java/speiger/src/collections/tests/SortedSetTest.java b/src/test/java/speiger/src/collections/tests/SortedSetTest.java index 22ee615e..189001e2 100644 --- a/src/test/java/speiger/src/collections/tests/SortedSetTest.java +++ b/src/test/java/speiger/src/collections/tests/SortedSetTest.java @@ -3,8 +3,6 @@ package speiger.src.collections.tests; @SuppressWarnings("javadoc") public enum SortedSetTest { - ADD_MOVE, - MOVE, PEEK, POLL, SUB_SET,