From 2da45884306570d0caf7364366ffdcc463aeea87 Mon Sep 17 00:00:00 2001 From: Speiger Date: Wed, 17 May 2023 09:20:45 +0200 Subject: [PATCH] Added getFirst/getLast/removeFirst/removeLast to lists --- Changelog.md | 521 ++++---- .../src/builder/modules/JavaModule.java | 442 +++---- .../src/builder/modules/ListModule.java | 5 +- .../src/builder/modules/SetModule.java | 2 +- .../templates/lists/LinkedList.template | 29 +- .../collections/templates/lists/List.template | 1106 +++++++++-------- 6 files changed, 1086 insertions(+), 1019 deletions(-) diff --git a/Changelog.md b/Changelog.md index 21af5b7..818499a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,260 +1,263 @@ -# Changelog of versions - -### Version 0.8.0 -- Added: ISizeProvider interface (Optimization Helper) -- Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons) -- Added: ToArray function into Iterable which uses ISizeProvider to reduce overhead of duplicating arrays. -- Added: Functions that have the same type, Int2IntFunction as example, have now a identity function. -- Added: Functions of a BooleanValue have now alwaysTrue/False function. -- Added: ForEachIndexed for all Iterable implementations -- Added: RandomGenerator support (Java17), though requires self compilation -- Added: Optimizations for HashUtils next power of function. -- Added: toArray() now returns a cached empty array if the collection is empty. -- Added: toArray function for AsyncBuilder -- Added: Modularization to the library where feature can be disabled as needed. (Requires Self-Compilation) -- Fixed: putIfAbsent now replaces defaultValues -- Fixed: OpenHashSet/Map and their Custom Variants no longer rely on List implementations. -- Fixed: ObjectCopyOnWriteList.of did create a ObjectArrayList instead of the CopyOnWrite variant. -- Removed: BooleanSet and Maps that start with a Boolean classes since they can not be used anyways. -- Breaking Change: Function classes now use the "apply/applyAs/test" format from Java itself, instead of the "get" format. This cleans up a lot of things. But will break existing function class implementations -- Breaking Change: Classes that used PrimitiveCollection functions now default to java functions where applicable, this is to increase compat. -- Breaking Change: Some function classes now get closer to javas terms. (Predicate/UnaryOperator etc) - -### Version 0.7.0 -- Added: Over 11 Million Unit Tests to this library to ensure quality. -- Added: ArrayList size constructor now throws IllegalStateException if the size parameter is negative -- Added: EnumMap specialized forEach implementation. -- Added: AbstractMap.remove now delegates to its primitive counterpart. -- Added: ConcurrentHashMap now implements ITrimmable -- Refactor: Removed a lot of disabled code from ArraySet. -- Removed: LinkedList.addAll(index, List) now delegates to LinkedList.addAll(index, Collection) due to no special optimization required. -- Fixed: AbstractList.SubList.get/set/swapRemove didn't calculate their List index Properly -- Fixed: AbstractList.SubList chains now properly if you create SubLists within SubLists. -- Fixed: AbstractList.Iterator.add now respects Immutable/UnmodifiableLists. -- Fixed: AbstractList.Iterator.skip/back now keep track of the last returned value for remove function to work properly. -- Fixed: CopyOnWriteArrayList.extract/removeElements(int, int) does now proper range checks and remove elements properly. -- Fixed: CopyOnWriteArrayList.SubList now works properly. (Reimplemented entirely) -- Fixed: CopyOnWriteArrayList.Iterator.previous() was returning the wrong values. -- Fixed: CopyOnWriteArrayList.Iterator.skip now skips the right amount of elements and stops where it should. -- Fixed: LinkedList.first/last/dequeue/dequeueLast now throws NoSuchElementException when empty instead of IllegalStateException. -- Fixed: LinkedList had an edge case where the entire reverse iterator would break if the wrong element was removed. -- Fixed: LinkedList.extractElement now returns the correct values. -- Fixed: AbstractMap.entrySet().remove(Object) now returns true if defaultReturnValue elements were removed. -- Fixed: ConcurrentHashMap.remove(Object, Object) checks if the type matches before comparing against null Values. -- Fixed: LinkedHashMap.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map. -- Fixed: HashMap.trim/clearToTrim() was using the wrong value to determin if something should be done. -- Fixed: HashMap now compares empty values (0) against nullKeys when Object Variants of the type are used. -- Fixed: ImmutableMap now compares empty values (0) against nullKeys when Object Variants of the type are used. -- Fixed: ArrayMap.iterator(key) now throws NoSuchElementException when the element wasn't found. -- Fixed: Linked/EnumMap array constructor was creating the wrong size values array. -- Fixed: LinkedEnumMap.getAndMoveToFirst/Last was moving elements even if the element wasn't present. -- Fixed: AVL/RBTreeMap.getFirst/LastKey was not throwing a NoSuchElementException if the map was empty. -- Fixed: Map.Builder wasn't throwing a IllegalStateException when creating a negative size builder. -- Fixed: AVL/RBTreeSet.DecendingSet.subSet(from, fromInclusive, to, toInclusive) was creating a corrupt asending subset. -- Fixed: ArraySet throws now a IllegalStateException when trying to create it with a negative size. -- Fixed: ArraySet.addMoveToLast(key) was crashing when a key was already present. -- Fixed: Immutable/LinkedHashSet now keep track of their iteration index properly. -- Fixed: LinkedHashSet.moveToFirst/Last(key) would crash if the Set was empty. -- Fixed: LinkedHashSet.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map. -- Fixed: HashSet.trim/clearToTrim() was using the wrong value to determin if something should be done. - - -### Version 0.6.2 -- Added: Array only sorting function return the inputed array. This was done to allow for static final references to use the method in one go without having to make lambda wrappers. Cleaner code. -- Added: Iterator Wrappers are now a bit more in Compliance with Java Standards. -- Added: AsyncBuilders now Support Array Inputs to create cleaner code. -- Changed: LinkedList.addBulk variable definition was triggering a false positive. -- Fixed: TreeMap.subMap().entrySet().remove() wouldn't check primitives properly. -- Fixed: SortedMap.sub/tail/headMap were looping into themselves. -- Fixed: AbstractCollection.retainAll didn't push removed values through the consumer. -- Fixed: AbstractCollection.toArray wouldn't reset the last entry if the input array was larger then the elements in the collection. -- Fixed: SubList didn't check for ranges properly or didn't use parent list to validate changes. -- Fixed: ArrayList.addElements didn't check input array fully and used the wrong variable to move the elements around. -- Fixed: LinkedList.addElements(EmptyInput) would crash. -- Fixed: LinkedList.swapRemove didn't account for if the removed element was the prelast one. -- Fixed: LinkedList.removeElements would break the implementation if the list was almost empty and the middle element was removed. -- Fixed: LinkedHashSet.addAndMoveToFirst wouldn't move elements to the first place. -- Fixed: ArrayList/LinkedList extractElements crashing when 0 or less elements are desired. -- Fixed: TreeMap pollFirst/LastKey should return the defaultMin/max value instead of a Empty value. -- Fixed: TreeMap keySet implementation was missing the class type implementations to pass keySet tests. -- Fixed: TreeMap.SubMap Iterator (primitive Keys) was crashing because a Null was set on to a primitive. - - -### Version 0.6.1 -- Fixed: FIFO queue crashing when the last index is before the first index when peek is called. -- Fixed: FIFO queue only clears the array if it was in use. -- Added: Sorted Method for the stream replacing functions. - -### Version 0.6.0 -- Added: addOrGet for sets. -- Added: Async API which allows to easily execute Iterables/Collections offthread without the complexity. -- Added: CopyOnWriteArrayList and tests for it -- Added: Support up to Java17. -- Added: Build System now adds module-info if the Running JVM is 9 or higher -- Added: ArrayList.of(Class, size) that allows you to allocate a size right at the creation of the List without having to create a wrapper array. -- Added: A ConcurrentHashMap implementation. -- Fixed: containsValue in the HashMap wouldn't check the nullKey -- Removed: Deprecated functions from SortedMaps/Sets - -### Version 0.5.3 -- Added: OrderedMap/Set -- Added: Deprecation to Functions that are specific to Ordered interfaces in the SortedMap/Set -- Added: subFrom to Maps which is the counterpart of the addTo method -- Added: pourAsList and pourAsSet (booleans excluded for sets) to Iterable -- Fixed: ArrayList.grow had a small bug where it would trigger to early causing performance problems with exact sized collections. -- Fixed: FIFOQueue size constructor had a small bug where it would trigger a array enlargement when all elements were inserted. - -### Version 0.5.2 -- Fixed: Bugs with Queues starting with the wrong size -- Fixed: ArrayGrowth for Queues was +1 instead of +50% -- Added: Benchmarks with java and FastUtil - -### Version 0.5.1 -- Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps so they are now deemed stable. -- Added: Another 150k Unit tests. -- Added: List and Set Unit tests for Integer (or Primitives in this case) to ensure basic stability there. (Now covering all sets and lists) -- Fixed: Bugs with null values for primitive collections. -- Removed: ArraySet/Map subSet/subMap implementation was removed. - -### Version 0.5.0 -- Added: 2 Helper functions to find out how many bits are required to store a Number. -- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly. -- Added: The new ToArray method from Java9 and newer into the library. Using a functional interface. (Just a backport) -- Changed: Reworked how the Map Builder functions are created. They are now in a SubClass that moves them out of the way. Less Clutter. (This might break things if that was used before) -- Added: Map Builder that allows now to Build Maps like Guava ImmutableMaps can be build. Note: This has a slight performance overhead. -- Added: Unmodifiable and Synchronize wrapper functions direclty into Collection Interfaces. This is mostly a quality of life thing. -- Added: Unmodifiable and Synchronized Wrapper Collections can now be cloned. They clone the underlying map which doesn't break functionality. (Had a usecase for it) -- Added: A boxed putAll array variant. -- Fixed: EnumMaps didn't keep track of their size and now got proper care and implementations as needed. There might be more work required but at least the core functionality is now up to date. -- Added: Tests for the new Stream replace functions to ensure no bugs are left. -- Fixed: Custom HashSet reduce function with a default value was checking incorrectly for present keys. -- Added: Guava TestSuit -- Fixed: HashCode and toString method would crash if the Object Key/Value was null -- Added: AbstractTypeCollection now delegates the contains check to type-specific Collections if it detects it. -- Fixed: Map.Entry toString wasn't writing values not like it should do. -- Fixed: Set.hashCode now is the sum of the elements instead of a Unique HashCode based on the elements. -- Fixed: Added missing NonNull Checks. -- Fixed: Custom/OpenHashMap.containsValue implementation was wrong. -- Fixed: Custom/OpenHashMap.compute/present/absent now works how it is specified in the Java Documentation -- Fixed: Custom/OpenHashMap.merge/BulkMerge now works how it is specified in the Java Documentation -- Fixed: Custom/Linked/OpenHashMap.keySet.remove was causing a infinite loop. -- Fixed: Custom/Linked/OpenHashMap.entrySet.contains was not correctly comparing the entry. -- Fixed: Custom/OpenHashMap.mapIterator now no longer crashes in certain cases. -- Added: Custom/LinkedOpenHashMap now takes use of the improved Iterator it has for containsValue -- Fixed: CustomOpenHashMap.keySet.forEach was basically putting out keys even if they were present -- Fixed: ImmutableMaps issues thanks to the tests. Roughly the same as the rest of the maps -- Fixed: RB/AVLTreeMaps issues. Roughly the same as the rest of the maps -- Fixed: SubLists are now properly implemented. -- Fixed: HashSet Iterator bugs now fixed... That was Painful. -- Added: Tests for Lists and Sets - -### Version 0.4.5 -- Added: removeAll/retainAll(Collection c, Consumer r) which receives all the elements that got deleted from the collection -- Fixed: Supplier get function wasn't referencing original function. -- Added: addIfPresent/Absent to lists -- Added: distinct, limit and peek iterators -- Added: Iterable's can now reduce its contents -- Added: Better ForEach support for IterableWrappers so a Iterator chain is not created -- Added: SwapRemove to Lists which moves the last element into the desired space to be deleted -- Added: More Test cases - -### Version 0.4.4 -- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation. -- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash. -- Added: Array/Collection version of enqueue and enqueueFirst to PriorityQueues. -- Added: fillBuffer function into PrimitiveLists which allow to optimize JavaNio buffers if needed. - -### Version 0.4.3 -- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance. -- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently. - -### Version 0.4.2 -- Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function. - Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function. -- Fixed: PriorityQueues didn't implement: hashCode/equals/toString - -### Version 0.4.1 -- Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly -- Added: addAll with Array-types in collections. -- Added: Java Iterator/Iterable support for Stream replacing methods -- Added: Suppliers. -- Added: SupplyIfAbsent. It is ComputeIfAbsent but using suppliers -- Added: Count feature into Iterable -- Fixed: A couple bugs with the new StreamReplacing functions in LinkedCollections Iterating to Infinity - -### Version 0.4.0 -- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables -- Added: New Stream replacing functions: findFirst, matchesAny/All/None -- Fixed: Compute/ComputeIfAbsent/ComputeIfPresent/Merge/BulkMerge in maps now behave like they should. -- Added: Implementations for New Stream replacing functions. -- Changed: Removed a lot of duplicated forEach implementations -- Added: Flat/Mapping functions (to object) are now accessible to primitive maps. -- Added: Filter function to Iterators/Iterables (Iterable implements it by default) -- Changed: Cleanup of some variables/mappers -- Added/Fixed: AVL/RBTreeMap got reworked and SubMaps work more properly now. Also forEach support got improved a lot -- Added/Fixed: TreeSubSets (RB/AVL) got their functional implementations improved too. -- Added: Pairs are now a thing. In Mutable/Immutable Form - -### Version 0.3.6 -- Fixed: addAll non Type Specific Lists was causing crashes. -- Fixed/Changed: clearAndTrim's implementation was all over the place. In some cases causing crash scenarios. -- Fixed: Wrappers didn't implement toString/equals/hashCode -- Added: Tests for addAll Bug -- Changed: Cleaned up CodeStyle as bugs were fixed. - -### Version 0.3.5 -- Fixed: Simple Code Generator dependency was declared wrong. Its only needed for runtime. Not for Compilation. -- Fixed: ObjectLists Crashed when a null was provided as a Comparator. (Unless the List was Initialized with the ClassType) -- Fixed: LinkedLists didn't implement add(Object) -- Fixed: Object Collections did have the JavaCollections deprecated as the Constructor. This should only be deprecated for Primitives -- Added: Tests with 5k Random names for Object sorting. -- Changed: Object Arrays no longer require a Comparable[] it just assumes now that the elements in the Array are Comparable -- Fixed: Dependency to SimpleCodeGenerator should be no longer a thing. Because the resulting library doesn't need it only the builder does. - -### Version 0.3.4 -- Fixed: ArrayLists didn't resize properly if they were empty. - - -### Version 0.3.3 -- Added: Flat/Mapping function for Iterables/Iterators to help avoid streams for cleaner looking code -- Fixed: AVLTrees pollFirst/Last is now keeping orders and is fixed -- Fixed: AbstractCollection bulk adding methods now link to the specialized implementations. -- Fixed: A bug with getElements in ArrayList. -- Fixed: PriorityQueue remove/toArray function were renamed so they fit better with other interfaces. (remove => removeFirst and toArray uses a different genericType) -- Added: LinkedList which is a List/PriorityDequeue/Stack which allows for more optimized use-cases and reduced boxing/unboxing. -- Added: Tests for LinkedList - -### Version 0.3.2 -- Fixed: Map.put wasn't referring to primitive variants. -- Added: ImmutableList. -- Added: Iterator pour function into a List or Array -- Changed: Arrays Wrap is now accessible to Objects and now is ? extends TYPE instead of TYPE. -- Added: OpenHashSets now implement foreach and have less overhead. -- Added: ImmutableOpenHashSet that is not editable (is linked by default for fast iteration) -- Added: CustomOpenHashSets now implement foreach and have less overhead. -- Added: ImmutableOpenHashMap that is not editable (is linked by default for fast iteration) -- Added: Maps can now be created through the interface. -- Fixed: Lists.addElements(T...elements) was adding elements at the beginning of a list instead of the end. -- Fixed: Bugs with the AVLTreeSet. And marked bugs with AVLTreeX that are still present. - -### Version 0.3.1 -- Fixed: containsKey & containsValue in HashMaps were deprecated for Object Variants. -- Fixed: HashMap wasn't deleting Keys & Values references when removing a Object -- Fixed: AVLTreeMap didn't balance properly. -- Changed: EnumMap no longer tries to access SharedSecrets since its gone in java11 -- Added: HashMaps now implement ITrimmable -- Added: AVLTreeSet didn't balance properly -- Fixed: HashMaps & LinkedMaps weren't clearing references properly. - -### Version 0.3.0 (Breaking 0.2.0) -- Added: Stack.isEmpty was missing -- Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes -- Removed: Suffixes for unmodifiable & synchronize functions. -- Changed: Primitive Stacks no longer depend on the base Stack class. Because seriously not needed. -- Changed: PriorityQueues no longer extends Object Variant. -- Changed: Maps.get function is no longer using Suffixes unless its absolutely necessary. -- Changed: Maps.remove function is no longer using Suffixes unless its absolutely necessary. -- Changed: ObjectList methods are no longer marked Deprecated even so it was for primitive ones. -- Added: Shuffle & Reverse Methods. -- Added: Concat Iterators. +# Changelog of versions + +### Version 0.8.0 +- Added: getFirst/getLast/removeFirst/removeLast to Lists + +### Version 0.8.0 +- Added: ISizeProvider interface (Optimization Helper) +- Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons) +- Added: ToArray function into Iterable which uses ISizeProvider to reduce overhead of duplicating arrays. +- Added: Functions that have the same type, Int2IntFunction as example, have now a identity function. +- Added: Functions of a BooleanValue have now alwaysTrue/False function. +- Added: ForEachIndexed for all Iterable implementations +- Added: RandomGenerator support (Java17), though requires self compilation +- Added: Optimizations for HashUtils next power of function. +- Added: toArray() now returns a cached empty array if the collection is empty. +- Added: toArray function for AsyncBuilder +- Added: Modularization to the library where feature can be disabled as needed. (Requires Self-Compilation) +- Fixed: putIfAbsent now replaces defaultValues +- Fixed: OpenHashSet/Map and their Custom Variants no longer rely on List implementations. +- Fixed: ObjectCopyOnWriteList.of did create a ObjectArrayList instead of the CopyOnWrite variant. +- Removed: BooleanSet and Maps that start with a Boolean classes since they can not be used anyways. +- Breaking Change: Function classes now use the "apply/applyAs/test" format from Java itself, instead of the "get" format. This cleans up a lot of things. But will break existing function class implementations +- Breaking Change: Classes that used PrimitiveCollection functions now default to java functions where applicable, this is to increase compat. +- Breaking Change: Some function classes now get closer to javas terms. (Predicate/UnaryOperator etc) + +### Version 0.7.0 +- Added: Over 11 Million Unit Tests to this library to ensure quality. +- Added: ArrayList size constructor now throws IllegalStateException if the size parameter is negative +- Added: EnumMap specialized forEach implementation. +- Added: AbstractMap.remove now delegates to its primitive counterpart. +- Added: ConcurrentHashMap now implements ITrimmable +- Refactor: Removed a lot of disabled code from ArraySet. +- Removed: LinkedList.addAll(index, List) now delegates to LinkedList.addAll(index, Collection) due to no special optimization required. +- Fixed: AbstractList.SubList.get/set/swapRemove didn't calculate their List index Properly +- Fixed: AbstractList.SubList chains now properly if you create SubLists within SubLists. +- Fixed: AbstractList.Iterator.add now respects Immutable/UnmodifiableLists. +- Fixed: AbstractList.Iterator.skip/back now keep track of the last returned value for remove function to work properly. +- Fixed: CopyOnWriteArrayList.extract/removeElements(int, int) does now proper range checks and remove elements properly. +- Fixed: CopyOnWriteArrayList.SubList now works properly. (Reimplemented entirely) +- Fixed: CopyOnWriteArrayList.Iterator.previous() was returning the wrong values. +- Fixed: CopyOnWriteArrayList.Iterator.skip now skips the right amount of elements and stops where it should. +- Fixed: LinkedList.first/last/dequeue/dequeueLast now throws NoSuchElementException when empty instead of IllegalStateException. +- Fixed: LinkedList had an edge case where the entire reverse iterator would break if the wrong element was removed. +- Fixed: LinkedList.extractElement now returns the correct values. +- Fixed: AbstractMap.entrySet().remove(Object) now returns true if defaultReturnValue elements were removed. +- Fixed: ConcurrentHashMap.remove(Object, Object) checks if the type matches before comparing against null Values. +- Fixed: LinkedHashMap.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map. +- Fixed: HashMap.trim/clearToTrim() was using the wrong value to determin if something should be done. +- Fixed: HashMap now compares empty values (0) against nullKeys when Object Variants of the type are used. +- Fixed: ImmutableMap now compares empty values (0) against nullKeys when Object Variants of the type are used. +- Fixed: ArrayMap.iterator(key) now throws NoSuchElementException when the element wasn't found. +- Fixed: Linked/EnumMap array constructor was creating the wrong size values array. +- Fixed: LinkedEnumMap.getAndMoveToFirst/Last was moving elements even if the element wasn't present. +- Fixed: AVL/RBTreeMap.getFirst/LastKey was not throwing a NoSuchElementException if the map was empty. +- Fixed: Map.Builder wasn't throwing a IllegalStateException when creating a negative size builder. +- Fixed: AVL/RBTreeSet.DecendingSet.subSet(from, fromInclusive, to, toInclusive) was creating a corrupt asending subset. +- Fixed: ArraySet throws now a IllegalStateException when trying to create it with a negative size. +- Fixed: ArraySet.addMoveToLast(key) was crashing when a key was already present. +- Fixed: Immutable/LinkedHashSet now keep track of their iteration index properly. +- Fixed: LinkedHashSet.moveToFirst/Last(key) would crash if the Set was empty. +- Fixed: LinkedHashSet.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map. +- Fixed: HashSet.trim/clearToTrim() was using the wrong value to determin if something should be done. + + +### Version 0.6.2 +- Added: Array only sorting function return the inputed array. This was done to allow for static final references to use the method in one go without having to make lambda wrappers. Cleaner code. +- Added: Iterator Wrappers are now a bit more in Compliance with Java Standards. +- Added: AsyncBuilders now Support Array Inputs to create cleaner code. +- Changed: LinkedList.addBulk variable definition was triggering a false positive. +- Fixed: TreeMap.subMap().entrySet().remove() wouldn't check primitives properly. +- Fixed: SortedMap.sub/tail/headMap were looping into themselves. +- Fixed: AbstractCollection.retainAll didn't push removed values through the consumer. +- Fixed: AbstractCollection.toArray wouldn't reset the last entry if the input array was larger then the elements in the collection. +- Fixed: SubList didn't check for ranges properly or didn't use parent list to validate changes. +- Fixed: ArrayList.addElements didn't check input array fully and used the wrong variable to move the elements around. +- Fixed: LinkedList.addElements(EmptyInput) would crash. +- Fixed: LinkedList.swapRemove didn't account for if the removed element was the prelast one. +- Fixed: LinkedList.removeElements would break the implementation if the list was almost empty and the middle element was removed. +- Fixed: LinkedHashSet.addAndMoveToFirst wouldn't move elements to the first place. +- Fixed: ArrayList/LinkedList extractElements crashing when 0 or less elements are desired. +- Fixed: TreeMap pollFirst/LastKey should return the defaultMin/max value instead of a Empty value. +- Fixed: TreeMap keySet implementation was missing the class type implementations to pass keySet tests. +- Fixed: TreeMap.SubMap Iterator (primitive Keys) was crashing because a Null was set on to a primitive. + + +### Version 0.6.1 +- Fixed: FIFO queue crashing when the last index is before the first index when peek is called. +- Fixed: FIFO queue only clears the array if it was in use. +- Added: Sorted Method for the stream replacing functions. + +### Version 0.6.0 +- Added: addOrGet for sets. +- Added: Async API which allows to easily execute Iterables/Collections offthread without the complexity. +- Added: CopyOnWriteArrayList and tests for it +- Added: Support up to Java17. +- Added: Build System now adds module-info if the Running JVM is 9 or higher +- Added: ArrayList.of(Class, size) that allows you to allocate a size right at the creation of the List without having to create a wrapper array. +- Added: A ConcurrentHashMap implementation. +- Fixed: containsValue in the HashMap wouldn't check the nullKey +- Removed: Deprecated functions from SortedMaps/Sets + +### Version 0.5.3 +- Added: OrderedMap/Set +- Added: Deprecation to Functions that are specific to Ordered interfaces in the SortedMap/Set +- Added: subFrom to Maps which is the counterpart of the addTo method +- Added: pourAsList and pourAsSet (booleans excluded for sets) to Iterable +- Fixed: ArrayList.grow had a small bug where it would trigger to early causing performance problems with exact sized collections. +- Fixed: FIFOQueue size constructor had a small bug where it would trigger a array enlargement when all elements were inserted. + +### Version 0.5.2 +- Fixed: Bugs with Queues starting with the wrong size +- Fixed: ArrayGrowth for Queues was +1 instead of +50% +- Added: Benchmarks with java and FastUtil + +### Version 0.5.1 +- Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps so they are now deemed stable. +- Added: Another 150k Unit tests. +- Added: List and Set Unit tests for Integer (or Primitives in this case) to ensure basic stability there. (Now covering all sets and lists) +- Fixed: Bugs with null values for primitive collections. +- Removed: ArraySet/Map subSet/subMap implementation was removed. + +### Version 0.5.0 +- Added: 2 Helper functions to find out how many bits are required to store a Number. +- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly. +- Added: The new ToArray method from Java9 and newer into the library. Using a functional interface. (Just a backport) +- Changed: Reworked how the Map Builder functions are created. They are now in a SubClass that moves them out of the way. Less Clutter. (This might break things if that was used before) +- Added: Map Builder that allows now to Build Maps like Guava ImmutableMaps can be build. Note: This has a slight performance overhead. +- Added: Unmodifiable and Synchronize wrapper functions direclty into Collection Interfaces. This is mostly a quality of life thing. +- Added: Unmodifiable and Synchronized Wrapper Collections can now be cloned. They clone the underlying map which doesn't break functionality. (Had a usecase for it) +- Added: A boxed putAll array variant. +- Fixed: EnumMaps didn't keep track of their size and now got proper care and implementations as needed. There might be more work required but at least the core functionality is now up to date. +- Added: Tests for the new Stream replace functions to ensure no bugs are left. +- Fixed: Custom HashSet reduce function with a default value was checking incorrectly for present keys. +- Added: Guava TestSuit +- Fixed: HashCode and toString method would crash if the Object Key/Value was null +- Added: AbstractTypeCollection now delegates the contains check to type-specific Collections if it detects it. +- Fixed: Map.Entry toString wasn't writing values not like it should do. +- Fixed: Set.hashCode now is the sum of the elements instead of a Unique HashCode based on the elements. +- Fixed: Added missing NonNull Checks. +- Fixed: Custom/OpenHashMap.containsValue implementation was wrong. +- Fixed: Custom/OpenHashMap.compute/present/absent now works how it is specified in the Java Documentation +- Fixed: Custom/OpenHashMap.merge/BulkMerge now works how it is specified in the Java Documentation +- Fixed: Custom/Linked/OpenHashMap.keySet.remove was causing a infinite loop. +- Fixed: Custom/Linked/OpenHashMap.entrySet.contains was not correctly comparing the entry. +- Fixed: Custom/OpenHashMap.mapIterator now no longer crashes in certain cases. +- Added: Custom/LinkedOpenHashMap now takes use of the improved Iterator it has for containsValue +- Fixed: CustomOpenHashMap.keySet.forEach was basically putting out keys even if they were present +- Fixed: ImmutableMaps issues thanks to the tests. Roughly the same as the rest of the maps +- Fixed: RB/AVLTreeMaps issues. Roughly the same as the rest of the maps +- Fixed: SubLists are now properly implemented. +- Fixed: HashSet Iterator bugs now fixed... That was Painful. +- Added: Tests for Lists and Sets + +### Version 0.4.5 +- Added: removeAll/retainAll(Collection c, Consumer r) which receives all the elements that got deleted from the collection +- Fixed: Supplier get function wasn't referencing original function. +- Added: addIfPresent/Absent to lists +- Added: distinct, limit and peek iterators +- Added: Iterable's can now reduce its contents +- Added: Better ForEach support for IterableWrappers so a Iterator chain is not created +- Added: SwapRemove to Lists which moves the last element into the desired space to be deleted +- Added: More Test cases + +### Version 0.4.4 +- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation. +- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash. +- Added: Array/Collection version of enqueue and enqueueFirst to PriorityQueues. +- Added: fillBuffer function into PrimitiveLists which allow to optimize JavaNio buffers if needed. + +### Version 0.4.3 +- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance. +- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently. + +### Version 0.4.2 +- Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function. + Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function. +- Fixed: PriorityQueues didn't implement: hashCode/equals/toString + +### Version 0.4.1 +- Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly +- Added: addAll with Array-types in collections. +- Added: Java Iterator/Iterable support for Stream replacing methods +- Added: Suppliers. +- Added: SupplyIfAbsent. It is ComputeIfAbsent but using suppliers +- Added: Count feature into Iterable +- Fixed: A couple bugs with the new StreamReplacing functions in LinkedCollections Iterating to Infinity + +### Version 0.4.0 +- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables +- Added: New Stream replacing functions: findFirst, matchesAny/All/None +- Fixed: Compute/ComputeIfAbsent/ComputeIfPresent/Merge/BulkMerge in maps now behave like they should. +- Added: Implementations for New Stream replacing functions. +- Changed: Removed a lot of duplicated forEach implementations +- Added: Flat/Mapping functions (to object) are now accessible to primitive maps. +- Added: Filter function to Iterators/Iterables (Iterable implements it by default) +- Changed: Cleanup of some variables/mappers +- Added/Fixed: AVL/RBTreeMap got reworked and SubMaps work more properly now. Also forEach support got improved a lot +- Added/Fixed: TreeSubSets (RB/AVL) got their functional implementations improved too. +- Added: Pairs are now a thing. In Mutable/Immutable Form + +### Version 0.3.6 +- Fixed: addAll non Type Specific Lists was causing crashes. +- Fixed/Changed: clearAndTrim's implementation was all over the place. In some cases causing crash scenarios. +- Fixed: Wrappers didn't implement toString/equals/hashCode +- Added: Tests for addAll Bug +- Changed: Cleaned up CodeStyle as bugs were fixed. + +### Version 0.3.5 +- Fixed: Simple Code Generator dependency was declared wrong. Its only needed for runtime. Not for Compilation. +- Fixed: ObjectLists Crashed when a null was provided as a Comparator. (Unless the List was Initialized with the ClassType) +- Fixed: LinkedLists didn't implement add(Object) +- Fixed: Object Collections did have the JavaCollections deprecated as the Constructor. This should only be deprecated for Primitives +- Added: Tests with 5k Random names for Object sorting. +- Changed: Object Arrays no longer require a Comparable[] it just assumes now that the elements in the Array are Comparable +- Fixed: Dependency to SimpleCodeGenerator should be no longer a thing. Because the resulting library doesn't need it only the builder does. + +### Version 0.3.4 +- Fixed: ArrayLists didn't resize properly if they were empty. + + +### Version 0.3.3 +- Added: Flat/Mapping function for Iterables/Iterators to help avoid streams for cleaner looking code +- Fixed: AVLTrees pollFirst/Last is now keeping orders and is fixed +- Fixed: AbstractCollection bulk adding methods now link to the specialized implementations. +- Fixed: A bug with getElements in ArrayList. +- Fixed: PriorityQueue remove/toArray function were renamed so they fit better with other interfaces. (remove => removeFirst and toArray uses a different genericType) +- Added: LinkedList which is a List/PriorityDequeue/Stack which allows for more optimized use-cases and reduced boxing/unboxing. +- Added: Tests for LinkedList + +### Version 0.3.2 +- Fixed: Map.put wasn't referring to primitive variants. +- Added: ImmutableList. +- Added: Iterator pour function into a List or Array +- Changed: Arrays Wrap is now accessible to Objects and now is ? extends TYPE instead of TYPE. +- Added: OpenHashSets now implement foreach and have less overhead. +- Added: ImmutableOpenHashSet that is not editable (is linked by default for fast iteration) +- Added: CustomOpenHashSets now implement foreach and have less overhead. +- Added: ImmutableOpenHashMap that is not editable (is linked by default for fast iteration) +- Added: Maps can now be created through the interface. +- Fixed: Lists.addElements(T...elements) was adding elements at the beginning of a list instead of the end. +- Fixed: Bugs with the AVLTreeSet. And marked bugs with AVLTreeX that are still present. + +### Version 0.3.1 +- Fixed: containsKey & containsValue in HashMaps were deprecated for Object Variants. +- Fixed: HashMap wasn't deleting Keys & Values references when removing a Object +- Fixed: AVLTreeMap didn't balance properly. +- Changed: EnumMap no longer tries to access SharedSecrets since its gone in java11 +- Added: HashMaps now implement ITrimmable +- Added: AVLTreeSet didn't balance properly +- Fixed: HashMaps & LinkedMaps weren't clearing references properly. + +### Version 0.3.0 (Breaking 0.2.0) +- Added: Stack.isEmpty was missing +- Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes +- Removed: Suffixes for unmodifiable & synchronize functions. +- Changed: Primitive Stacks no longer depend on the base Stack class. Because seriously not needed. +- Changed: PriorityQueues no longer extends Object Variant. +- Changed: Maps.get function is no longer using Suffixes unless its absolutely necessary. +- Changed: Maps.remove function is no longer using Suffixes unless its absolutely necessary. +- Changed: ObjectList methods are no longer marked Deprecated even so it was for primitive ones. +- Added: Shuffle & Reverse Methods. +- Added: Concat Iterators. - Added: PriorityQueues \ No newline at end of file diff --git a/src/builder/java/speiger/src/builder/modules/JavaModule.java b/src/builder/java/speiger/src/builder/modules/JavaModule.java index 61b7811..e172507 100644 --- a/src/builder/java/speiger/src/builder/modules/JavaModule.java +++ b/src/builder/java/speiger/src/builder/modules/JavaModule.java @@ -1,221 +1,221 @@ -package speiger.src.builder.modules; - -import speiger.src.builder.ClassType; - -@SuppressWarnings("javadoc") -public class JavaModule extends BaseModule -{ - public static final BaseModule INSTANCE = new JavaModule(); - - @Override - public String getModuleName() { return "Base"; } - @Override - protected void loadVariables() - { - createHelperVars(keyType, false, "KEY"); - createHelperVars(valueType, true, "VALUE"); - loadBaseVariables(); - } - - @Override - protected void loadFlags() - { - addFlag("TYPE_"+keyType.getCapType()); - addFlag("VALUE_"+valueType.getCapType()); - addValue("JAVA_VERSION", getVersion()); - if(keyType == valueType) addFlag("SAME_TYPE"); - if(keyType.hasFunction(valueType)) addFlag("JDK_FUNCTION"); - if(!keyType.needsCustomJDKType()) addFlag("JDK_TYPE"); - if(!keyType.isPrimitiveBlocking()) addFlag("PRIMITIVES"); - if(!valueType.isPrimitiveBlocking()) addFlag("VALUE_PRIMITIVES"); - if(!valueType.needsCustomJDKType()) addFlag("JDK_VALUE"); - } - - private int getVersion() { - String version = System.getProperty("java.version"); - if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3)); - int dot = version.indexOf("."); - return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version); - } - - @Override - protected void loadRemappers() {} - @Override - protected void loadBlockades() {} - - @Override - protected void loadFunctions() - { - addSimpleMapper("APPLY_KEY_VALUE", keyType.isObject() ? "apply" : "applyAs"+keyType.getNonFileType()); - addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType()); - addSimpleMapper("APPLY_CAST", "applyAs"+keyType.getCustomJDKType().getNonFileType()); - - //Shared by Maps and Pairs so moved to java. - addFunctionMappers("ENTRY_KEY", "get%sKey"); - addFunctionValueMappers("ENTRY_VALUE", "get%sValue"); - addFunctionMappers("KEY_ENTRY", "set%sKey"); - addFunctionValueMappers("VALUE_ENTRY", "set%sValue"); - } - - @Override - protected void loadClasses() - { - if(getVersion() >= 17) addSimpleMapper("RANDOM", "RandomGenerator"); - else addSimpleMapper("RANDOM", "Random"); - addSimpleMapper("JAVA_PREDICATE", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Predicate"); - addSimpleMapper("JAVA_CONSUMER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Consumer"); - addSimpleMapper("JAVA_SUPPLIER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Supplier"); - addSimpleMapper("JAVA_FUNCTION", keyType.getFunctionClass(valueType)); - addSimpleMapper("JAVA_BINARY_OPERATOR", keyType == ClassType.BOOLEAN ? "" : (keyType.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"BinaryOperator")); - addSimpleMapper("JAVA_UNARY_OPERATOR", keyType.isObject() ? "BinaryOperator" : keyType == ClassType.BOOLEAN ? "" : keyType.getCustomJDKType().getFileType()+"UnaryOperator"); - addSimpleMapper("JAVA_SPLIT_ITERATOR", keyType.isPrimitiveBlocking() ? "Spliterator" : "Of"+keyType.getCustomJDKType().getFileType()); - addSimpleMapper("JAVA_STREAM", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Stream"); - addSimpleMapper("JAVA_BUFFER", keyType.getFileType()+"Buffer"); - } - - @Override - protected void loadTestClasses() - { - addClassMapper("HELPERS", "Helpers"); - addClassMapper("SAMPLE_ELEMENTS", "Samples"); - } - - private void loadBaseVariables() - { - addSimpleMapper("VALUE_PACKAGE", valueType.getPathType()); - addSimpleMapper("PACKAGE", keyType.getPathType()); - addSimpleMapper("CLASS_TYPE", keyType.getClassType()); - addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType()); - addSimpleMapper("KEY_TYPE", keyType.getKeyType()); - addSimpleMapper("KEY_OBJECT_TYPE", keyType.isObject() ? "Object" : keyType.getKeyType()); - addSimpleMapper("KEY_STRING_TYPE", keyType.isObject() ? "String" : keyType.getKeyType()); - addSimpleMapper("KEY_SPECIAL_TYPE", keyType.isObject() ? "E" : keyType.getKeyType()); - addSimpleMapper("CLASS_OBJECT_TYPE", keyType.getClassType()); - addSimpleMapper("CLASS_OBJECT_VALUE_TYPE", valueType.getClassValueType()); - addSimpleMapper("CLASS_STRING_TYPE", keyType.isObject() ? "String" : keyType.getClassType()); - addSimpleMapper("CLASS_STRING_VALUE_TYPE", valueType.isObject() ? "String" : valueType.getClassValueType()); - addSimpleMapper("VALUE_TYPE", valueType.getValueType()); - addSimpleMapper("VALUE_OBJECT_TYPE", valueType.isObject() ? "Object" : valueType.getValueType()); - addSimpleMapper("VALUE_STRING_TYPE", valueType.isObject() ? "String" : valueType.getValueType()); - addSimpleMapper("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType()); - addSimpleMapper("KEY_JAVA_TYPE", keyType.getCustomJDKType().getKeyType()); - addSimpleMapper("VALUE_JAVA_TYPE", keyType.getCustomJDKType().getKeyType()); - - addSimpleMapper("EMPTY_KEY_VALUE", keyType.getEmptyValue()); - addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue()); - - addSimpleMapper("INVALID_KEY_VALUE", keyType.getInvalidValue()); - addSimpleMapper("INVALID_VALUE", valueType.getInvalidValue()); - - addSimpleMapper(" KEY_STRING_GENERIC_TYPE", keyType.isObject() ? "" : ""); - addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "" : ""); - addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); - - addSimpleMapper(" KEY_SAME_GENERIC_TYPE", keyType.isObject() ? "" : ""); - addSimpleMapper(" VALUE_SAME_GENERIC_TYPE", keyType.isObject() ? "" : ""); - - addSimpleMapper(" KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+">" : ""); - addSimpleMapper(" KEY_KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", "+keyType.getKeyType()+">" : ""); - addSimpleMapper(" KEY_CLASS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getClassType()+">" : ""); - - - addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : ""); - addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""); - addSimpleMapper(" VALUE_CLASS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getClassValueType()+">" : ""); - - addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : "")); - addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "")); - addInjectMapper(" KEY_VALUE_SPECIAL_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+", %s>" : "<"+keyType.getKeyType()+", %s>") : (valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>")).setBraceType("<>").removeBraces(); - - addSimpleMapper(" NO_GENERIC_TYPE", keyType.isObject() ? "" : ""); - addSimpleMapper(" NO_KV_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "" : "") : valueType.isObject() ? "" : ""); - addSimpleMapper(" KEY_COMPAREABLE_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+" extends Comparable>" : ""); - - addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", keyType.isObject() ? "" : ""); - addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "" : ""); - addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); - - addSimpleMapper(" KEY_UNKNOWN_GENERIC_TYPE", keyType.isObject() ? "" : ""); - addSimpleMapper(" VALUE_UNKNOWN_GENERIC_TYPE", valueType.isObject() ? "" : ""); - addSimpleMapper(" KEY_VALUE_UNKNOWN_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); - - addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">, "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : "")); - addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "")); - - addInjectMapper(" KEY_SPECIAL_GENERIC_TYPE", keyType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>"); - addInjectMapper(" VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>"); - addInjectMapper(" KSK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>"); - addInjectMapper(" KKS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>"); - addArgumentMapper(" KSS_GENERIC_TYPE", keyType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>"); - addInjectMapper(" SK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "").removeBraces().setBraceType("<>"); - addInjectMapper(" KS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "").removeBraces().setBraceType("<>"); - addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>"); - addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>"); - addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>"); - addInjectMapper(" SV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "").removeBraces().setBraceType("<>"); - addInjectMapper(" VS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "").removeBraces().setBraceType("<>"); - - - addSimpleMapper(" GENERIC_KEY_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+">" : ""); - addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : ""); - addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", keyType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>"); - addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>"); - addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", keyType.isObject() ? (valueType.isObject() ? " <"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">, "+valueType.getValueType()+">" : " <"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : "")); - - addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>"); - addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>"); - - addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", keyType.isObject() ? (valueType.isObject() ? " <"+keyType.getKeyType()+", "+valueType.getValueType()+">" : " <"+keyType.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : "")); - addSimpleMapper(" COMPAREABLE_KEY_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+" extends Comparable>" : ""); - addSimpleMapper("KV_BRACES", keyType.isObject() || valueType.isObject() ? "<>" : ""); - addSimpleMapper("VALUE_BRACES", valueType.isObject() ? "<>" : ""); - addSimpleMapper("BRACES", keyType.isObject() ? "<>" : ""); - if(keyType.needsCustomJDKType()) - { - addSimpleMapper("JAVA_TYPE", keyType.getCustomJDKType().getKeyType()); - addSimpleMapper("SANITY_CAST", "castTo"+keyType.getFileType()); - } - addSimpleMapper("JAVA_CLASS", keyType.getCustomJDKType().getClassType()); - if(valueType.needsCustomJDKType()) - { - addSimpleMapper("SANITY_CAST_VALUE", "castTo"+valueType.getFileType()); - } - addSimpleMapper("[SPACE]", " "); - addComment("@ArrayType", "@param <%s> the keyType of array that the operation should be applied"); - addComment("@Type", "@param <%s> the keyType of elements maintained by this Collection"); - addValueComment("@ValueArrayType", "@param <%s> the keyType of array that the operation should be applied"); - addValueComment("@ValueType", "@param <%s> the keyType of elements maintained by this Collection"); - addAnnontion("@PrimitiveOverride", "@Override"); - addSimpleMapper("@PrimitiveDoc", ""); - addAnnontion("@Primitive", "@Deprecated"); - addValueAnnontion("@ValuePrimitiveOverride", "@Override"); - addValueAnnontion("@ValuePrimitive", "@Deprecated"); - } - - private void createHelperVars(ClassType type, boolean value, String fix) - { - addArgumentMapper("EQUALS_"+fix+"_TYPE", "Objects.equals(%2$s, "+(type.isObject() ? "%1$s" : fix+"_TO_OBJ(%1$s)")+")").removeBraces(); - addInjectMapper(fix+"_EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces(); - addInjectMapper(fix+"_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces(); - addArgumentMapper(fix+"_EQUALS_NOT", type.getEquals(true)).removeBraces(); - addArgumentMapper(fix+"_EQUALS", type.getEquals(false)).removeBraces(); - addSimpleMapper("FILE_"+fix+"_TYPE", type.getFileType()); - - addArgumentMapper("COMPAREABLE_TO_"+fix, type.isObject() ? "((Comparable<"+type.getKeyType(value)+">)%1$s).compareTo(("+type.getKeyType(value)+")%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces(); - addArgumentMapper("COMPARE_TO_"+fix, type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces(); - - addInjectMapper(fix+"_TO_OBJ", type.isObject() ? "%s" : type.getClassType(value)+".valueOf(%s)").removeBraces(); - addInjectMapper("OBJ_TO_"+fix, type.isObject() ? "%s" : "%s."+type.getKeyType(value)+"Value()").removeBraces(); - addInjectMapper("CLASS_TO_"+fix, type.isObject() ? "("+type.getKeyType(value)+")%s" : "(("+type.getClassType(value)+")%s)."+type.getKeyType(value)+"Value()").removeBraces(); - - addInjectMapper(fix+"_TO_HASH", type.isObject() ? "Objects.hashCode(%s)" : type.getClassType(value)+".hashCode(%s)").removeBraces(); - addInjectMapper(fix+"_TO_STRING", type.isObject() ? "Objects.toString(%s)" : type.getClassType(value)+".toString(%s)").removeBraces(); - - addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : ""); - addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY"); - addInjectMapper("NEW_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces(); - addInjectMapper("NEW_SPECIAL_"+fix+"_ARRAY", type.isObject() ? "(E[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces(); - if(value) addInjectMapper("NEW_CLASS_VALUE_ARRAY", type.isObject() ? "(CLASS_VALUE_TYPE[])new Object[%s]" : "new CLASS_VALUE_TYPE[%s]").removeBraces(); - else addInjectMapper("NEW_CLASS_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces(); - } -} +package speiger.src.builder.modules; + +import speiger.src.builder.ClassType; + +@SuppressWarnings("javadoc") +public class JavaModule extends BaseModule +{ + public static final BaseModule INSTANCE = new JavaModule(); + + @Override + public String getModuleName() { return "Base"; } + @Override + protected void loadVariables() + { + createHelperVars(keyType, false, "KEY"); + createHelperVars(valueType, true, "VALUE"); + loadBaseVariables(); + } + + @Override + protected void loadFlags() + { + addFlag("TYPE_"+keyType.getCapType()); + addFlag("VALUE_"+valueType.getCapType()); + addValue("JAVA_VERSION", getVersion()); + if(keyType == valueType) addFlag("SAME_TYPE"); + if(keyType.hasFunction(valueType)) addFlag("JDK_FUNCTION"); + if(!keyType.needsCustomJDKType()) addFlag("JDK_TYPE"); + if(!keyType.isPrimitiveBlocking()) addFlag("PRIMITIVES"); + if(!valueType.isPrimitiveBlocking()) addFlag("VALUE_PRIMITIVES"); + if(!valueType.needsCustomJDKType()) addFlag("JDK_VALUE"); + } + + private int getVersion() { + String version = System.getProperty("java.version"); + if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3)); + int dot = version.indexOf("."); + return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version); + } + + @Override + protected void loadRemappers() {} + @Override + protected void loadBlockades() {} + + @Override + protected void loadFunctions() + { + addSimpleMapper("APPLY_KEY_VALUE", keyType.isObject() ? "apply" : "applyAs"+keyType.getNonFileType()); + addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType()); + addSimpleMapper("APPLY_CAST", "applyAs"+keyType.getCustomJDKType().getNonFileType()); + + //Shared by Maps and Pairs so moved to java. + addFunctionMappers("ENTRY_KEY", "get%sKey"); + addFunctionValueMappers("ENTRY_VALUE", "get%sValue"); + addFunctionMappers("KEY_ENTRY", "set%sKey"); + addFunctionValueMappers("VALUE_ENTRY", "set%sValue"); + } + + @Override + protected void loadClasses() + { + if(getVersion() >= 17) addSimpleMapper("RANDOM", "RandomGenerator"); + else addSimpleMapper("RANDOM", "Random"); + addSimpleMapper("JAVA_PREDICATE", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Predicate"); + addSimpleMapper("JAVA_CONSUMER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Consumer"); + addSimpleMapper("JAVA_SUPPLIER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Supplier"); + addSimpleMapper("JAVA_FUNCTION", keyType.getFunctionClass(valueType)); + addSimpleMapper("JAVA_BINARY_OPERATOR", keyType == ClassType.BOOLEAN ? "" : (keyType.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"BinaryOperator")); + addSimpleMapper("JAVA_UNARY_OPERATOR", keyType.isObject() ? "BinaryOperator" : keyType == ClassType.BOOLEAN ? "" : keyType.getCustomJDKType().getFileType()+"UnaryOperator"); + addSimpleMapper("JAVA_SPLIT_ITERATOR", keyType.isPrimitiveBlocking() ? "Spliterator" : "Of"+keyType.getCustomJDKType().getFileType()); + addSimpleMapper("JAVA_STREAM", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Stream"); + addSimpleMapper("JAVA_BUFFER", keyType.getFileType()+"Buffer"); + } + + @Override + protected void loadTestClasses() + { + addClassMapper("HELPERS", "Helpers"); + addClassMapper("SAMPLE_ELEMENTS", "Samples"); + } + + private void loadBaseVariables() + { + addSimpleMapper("VALUE_PACKAGE", valueType.getPathType()); + addSimpleMapper("PACKAGE", keyType.getPathType()); + addSimpleMapper("CLASS_TYPE", keyType.getClassType()); + addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType()); + addSimpleMapper("KEY_TYPE", keyType.getKeyType()); + addSimpleMapper("KEY_OBJECT_TYPE", keyType.isObject() ? "Object" : keyType.getKeyType()); + addSimpleMapper("KEY_STRING_TYPE", keyType.isObject() ? "String" : keyType.getKeyType()); + addSimpleMapper("KEY_SPECIAL_TYPE", keyType.isObject() ? "E" : keyType.getKeyType()); + addSimpleMapper("CLASS_OBJECT_TYPE", keyType.getClassType()); + addSimpleMapper("CLASS_OBJECT_VALUE_TYPE", valueType.getClassValueType()); + addSimpleMapper("CLASS_STRING_TYPE", keyType.isObject() ? "String" : keyType.getClassType()); + addSimpleMapper("CLASS_STRING_VALUE_TYPE", valueType.isObject() ? "String" : valueType.getClassValueType()); + addSimpleMapper("VALUE_TYPE", valueType.getValueType()); + addSimpleMapper("VALUE_OBJECT_TYPE", valueType.isObject() ? "Object" : valueType.getValueType()); + addSimpleMapper("VALUE_STRING_TYPE", valueType.isObject() ? "String" : valueType.getValueType()); + addSimpleMapper("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType()); + addSimpleMapper("KEY_JAVA_TYPE", keyType.getCustomJDKType().getKeyType()); + addSimpleMapper("VALUE_JAVA_TYPE", keyType.getCustomJDKType().getKeyType()); + + addSimpleMapper("EMPTY_KEY_VALUE", keyType.getEmptyValue()); + addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue()); + + addSimpleMapper("INVALID_KEY_VALUE", keyType.getInvalidValue()); + addSimpleMapper("INVALID_VALUE", valueType.getInvalidValue()); + + addSimpleMapper(" KEY_STRING_GENERIC_TYPE", keyType.isObject() ? "" : ""); + addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "" : ""); + addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); + + addSimpleMapper(" KEY_SAME_GENERIC_TYPE", keyType.isObject() ? "" : ""); + addSimpleMapper(" VALUE_SAME_GENERIC_TYPE", keyType.isObject() ? "" : ""); + + addSimpleMapper(" KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+">" : ""); + addSimpleMapper(" KEY_KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", "+keyType.getKeyType()+">" : ""); + addSimpleMapper(" KEY_CLASS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getClassType()+">" : ""); + + + addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : ""); + addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""); + addSimpleMapper(" VALUE_CLASS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getClassValueType()+">" : ""); + + addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : "")); + addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "")); + addInjectMapper(" KEY_VALUE_SPECIAL_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+", %s>" : "<"+keyType.getKeyType()+", %s>") : (valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>")).setBraceType("<>").removeBraces(); + + addSimpleMapper(" NO_GENERIC_TYPE", keyType.isObject() ? "" : ""); + addSimpleMapper(" NO_KV_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "" : "") : valueType.isObject() ? "" : ""); + addSimpleMapper(" KEY_COMPAREABLE_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+" extends Comparable>" : ""); + + addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", keyType.isObject() ? "" : ""); + addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "" : ""); + addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); + + addSimpleMapper(" KEY_UNKNOWN_GENERIC_TYPE", keyType.isObject() ? "" : ""); + addSimpleMapper(" VALUE_UNKNOWN_GENERIC_TYPE", valueType.isObject() ? "" : ""); + addSimpleMapper(" KEY_VALUE_UNKNOWN_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); + + addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">, "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : "")); + addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "")); + + addInjectMapper(" KEY_SPECIAL_GENERIC_TYPE", keyType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>"); + addInjectMapper(" VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>"); + addInjectMapper(" KSK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>"); + addInjectMapper(" KKS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>"); + addArgumentMapper(" KSS_GENERIC_TYPE", keyType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>"); + addInjectMapper(" SK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "").removeBraces().setBraceType("<>"); + addInjectMapper(" KS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "").removeBraces().setBraceType("<>"); + addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>"); + addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>"); + addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>"); + addInjectMapper(" SV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "").removeBraces().setBraceType("<>"); + addInjectMapper(" VS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "").removeBraces().setBraceType("<>"); + + + addSimpleMapper(" GENERIC_KEY_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+">" : ""); + addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : ""); + addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", keyType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>"); + addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>"); + addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", keyType.isObject() ? (valueType.isObject() ? " <"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">, "+valueType.getValueType()+">" : " <"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : "")); + + addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>"); + addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>"); + + addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", keyType.isObject() ? (valueType.isObject() ? " <"+keyType.getKeyType()+", "+valueType.getValueType()+">" : " <"+keyType.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : "")); + addSimpleMapper(" COMPAREABLE_KEY_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+" extends Comparable>" : ""); + addSimpleMapper("KV_BRACES", keyType.isObject() || valueType.isObject() ? "<>" : ""); + addSimpleMapper("VALUE_BRACES", valueType.isObject() ? "<>" : ""); + addSimpleMapper("BRACES", keyType.isObject() ? "<>" : ""); + if(keyType.needsCustomJDKType()) + { + addSimpleMapper("JAVA_TYPE", keyType.getCustomJDKType().getKeyType()); + addSimpleMapper("SANITY_CAST", "castTo"+keyType.getFileType()); + } + addSimpleMapper("JAVA_CLASS", keyType.getCustomJDKType().getClassType()); + if(valueType.needsCustomJDKType()) + { + addSimpleMapper("SANITY_CAST_VALUE", "castTo"+valueType.getFileType()); + } + addSimpleMapper("[SPACE]", " "); + addComment("@ArrayType", "@param <%s> the keyType of array that the operation should be applied"); + addComment("@Type", "@param <%s> the keyType of elements maintained by this Collection"); + addValueComment("@ValueArrayType", "@param <%s> the keyType of array that the operation should be applied"); + addValueComment("@ValueType", "@param <%s> the keyType of elements maintained by this Collection"); + addAnnontion("@PrimitiveOverride", "@Override"); + addSimpleMapper("@PrimitiveDoc", ""); + addAnnontion("@Primitive", "@Deprecated"); + addValueAnnontion("@ValuePrimitiveOverride", "@Override"); + addValueAnnontion("@ValuePrimitive", "@Deprecated"); + } + + private void createHelperVars(ClassType type, boolean value, String fix) + { + addArgumentMapper("EQUALS_"+fix+"_TYPE", "Objects.equals(%2$s, "+(type.isObject() ? "%1$s" : fix+"_TO_OBJ(%1$s)")+")").removeBraces(); + addInjectMapper(fix+"_EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces(); + addInjectMapper(fix+"_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces(); + addArgumentMapper(fix+"_EQUALS_NOT", type.getEquals(true)).removeBraces(); + addArgumentMapper(fix+"_EQUALS", type.getEquals(false)).removeBraces(); + addSimpleMapper("FILE_"+fix+"_TYPE", type.getFileType()); + + addArgumentMapper("COMPAREABLE_TO_"+fix, type.isObject() ? "((Comparable<"+type.getKeyType(value)+">)%1$s).compareTo(("+type.getKeyType(value)+")%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces(); + addArgumentMapper("COMPARE_TO_"+fix, type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces(); + + addInjectMapper(fix+"_TO_OBJ", type.isObject() ? "%s" : type.getClassType(value)+".valueOf(%s)").removeBraces(); + addInjectMapper("OBJ_TO_"+fix, type.isObject() ? "%s" : "%s."+type.getKeyType(value)+"Value()").removeBraces(); + addInjectMapper("CLASS_TO_"+fix, type.isObject() ? "("+type.getKeyType(value)+")%s" : "(("+type.getClassType(value)+")%s)."+type.getKeyType(value)+"Value()").removeBraces(); + + addInjectMapper(fix+"_TO_HASH", type.isObject() ? "Objects.hashCode(%s)" : type.getClassType(value)+".hashCode(%s)").removeBraces(); + addInjectMapper(fix+"_TO_STRING", type.isObject() ? "Objects.toString(%s)" : type.getClassType(value)+".toString(%s)").removeBraces(); + + addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : ""); + addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY"); + addInjectMapper("NEW_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces(); + addInjectMapper("NEW_SPECIAL_"+fix+"_ARRAY", type.isObject() ? "(E[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces(); + if(value) addInjectMapper("NEW_CLASS_VALUE_ARRAY", type.isObject() ? "(CLASS_VALUE_TYPE[])new Object[%s]" : "new CLASS_VALUE_TYPE[%s]").removeBraces(); + else addInjectMapper("NEW_CLASS_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces(); + } +} diff --git a/src/builder/java/speiger/src/builder/modules/ListModule.java b/src/builder/java/speiger/src/builder/modules/ListModule.java index ef53f84..e8881f0 100644 --- a/src/builder/java/speiger/src/builder/modules/ListModule.java +++ b/src/builder/java/speiger/src/builder/modules/ListModule.java @@ -69,7 +69,10 @@ public class ListModule extends BaseModule protected void loadFunctions() { addFunctionMapper("GET_KEY", "get"); - addFunctionMapper("REMOVE_LAST", "removeLast"); + addFunctionMapper("GET_FIRST_KEY", "getFirst"); + addFunctionMapper("GET_LAST_KEY", "getLast"); + addFunctionMapper("REMOVE_FIRST_KEY", "removeFirst"); + addFunctionMapper("REMOVE_LAST_KEY", "removeLast"); addFunctionMapper("REMOVE_SWAP", "swapRemove"); addFunctionMappers("REPLACE", keyType.isObject() ? "replaceObjects" : "replace%ss"); addFunctionMappers("SORT", "sort%ss"); diff --git a/src/builder/java/speiger/src/builder/modules/SetModule.java b/src/builder/java/speiger/src/builder/modules/SetModule.java index 0617e17..1d7bba8 100644 --- a/src/builder/java/speiger/src/builder/modules/SetModule.java +++ b/src/builder/java/speiger/src/builder/modules/SetModule.java @@ -120,7 +120,7 @@ public class SetModule extends BaseModule addFunctionMapper("POLL_FIRST_KEY", "pollFirst"); addFunctionMapper("POLL_LAST_KEY", "pollLast"); addFunctionMapper("FIRST_KEY", "first"); - addFunctionMapper("LAST_KEY", "last"); + addFunctionMapper("LAST_KEY", "last"); } @Override diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template b/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template index af52b60..b8d336b 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template @@ -314,21 +314,43 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE #if DEQUEUE_FEATURE @Override public KEY_TYPE first() { + return GET_FIRST_KEY(); + } + + @Override + public KEY_TYPE last() { + return GET_LAST_KEY(); + } + +#endif + @Override + public KEY_TYPE GET_FIRST_KEY() { if(first == null) throw new NoSuchElementException(); return first.value; } @Override - public KEY_TYPE last() { + public KEY_TYPE GET_LAST_KEY() { if(last == null) throw new NoSuchElementException(); return last.value; } -#endif + @Override + public KEY_TYPE REMOVE_FIRST_KEY() { + if(first == null) throw new NoSuchElementException(); + return unlinkFirst(first); + } + + @Override + public KEY_TYPE REMOVE_LAST_KEY() { + return pop(); + } + @Override public KEY_TYPE peek(int index) { return GET_KEY((size() - 1) - index); } + @Override public KEY_TYPE GET_KEY(int index) { checkRange(index); @@ -1146,8 +1168,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE Entry KEY_GENERIC_TYPE prev; Entry KEY_GENERIC_TYPE next; - public Entry(KEY_TYPE value, Entry KEY_GENERIC_TYPE prev, Entry KEY_GENERIC_TYPE next) - { + public Entry(KEY_TYPE value, Entry KEY_GENERIC_TYPE prev, Entry KEY_GENERIC_TYPE next) { this.value = value; this.prev = prev; this.next = next; diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/List.template b/src/builder/resources/speiger/assets/collections/templates/lists/List.template index 080e374..f39ed7d 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/List.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/List.template @@ -1,534 +1,574 @@ -package speiger.src.collections.PACKAGE.lists; - -#if PRIMITIVES -import java.nio.JAVA_BUFFER; -#endif -import java.util.List; -#if !TYPE_OBJECT && !TYPE_BOOLEAN -import java.util.function.JAVA_UNARY_OPERATOR; -#endif - -import java.util.Objects; -import java.util.Comparator; -#if !TYPE_BOOLEAN -import java.util.function.UnaryOperator; -#endif - -import speiger.src.collections.PACKAGE.collections.COLLECTION; -import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; -import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER; -#if !TYPE_OBJECT -import speiger.src.collections.PACKAGE.functions.COMPARATOR; -#endif -import speiger.src.collections.PACKAGE.utils.ARRAYS; -#if LISTS_FEATURE -import speiger.src.collections.PACKAGE.utils.LISTS; -#endif -import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; -#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT -import speiger.src.collections.utils.SanityChecks; -#endif - -/** - * A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features - * @Type(T) - */ -public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List -{ -#if !TYPE_OBJECT - /** - * A Type-Specific add Function to reduce (un)boxing - * @param e the element to add - * @return true if the list was modified - * @see List#add(Object) - */ - @Override - public boolean add(KEY_TYPE e); - - /** - * A Type-Specific add Function to reduce (un)boxing - * @param e the element to add - * @param index index at which the specified element is to be inserted - * @see List#add(int, Object) - */ - public void add(int index, KEY_TYPE e); - -#endif - /** - * A Helper function that will only add elements if it is not present. - * @param e the element to add - * @return true if the list was modified - */ - public default boolean addIfAbsent(KEY_TYPE e) { - if(indexOf(e) == -1) return add(e); - return false; - } - - /** - * A Helper function that will only add elements if it is present. - * @param e the element to add - * @return true if the list was modified - */ - public default boolean addIfPresent(KEY_TYPE e) { - if(indexOf(e) != -1) return add(e); - return false; - } - - /** - * A Type-Specific addAll Function to reduce (un)boxing - * @param c the elements that need to be added - * @param index index at which the specified elements is to be inserted - * @return true if the list was modified - * @see java.util.List#addAll(int, java.util.Collection) - */ - public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c); - - /** - * A Type-Specific and optimized addAll function that allows a faster transfer of elements - * @param c the elements that need to be added - * @return true if the list was modified - */ - public boolean addAll(LIST KEY_GENERIC_TYPE c); - - /** - * A Type-Specific and optimized addAll function that allows a faster transfer of elements - * @param c the elements that need to be added - * @param index index at which the specified elements is to be inserted - * @return true if the list was modified - */ - public boolean addAll(int index, LIST KEY_GENERIC_TYPE c); - -#if !TYPE_OBJECT - /** - * A Type-Specific get function to reduce (un)boxing - * @param index the index of the value that is requested - * @return the value at the given index - * @throws IndexOutOfBoundsException if the index is not within the list range - * @see List#get(int) - */ - public KEY_TYPE GET_KEY(int index); - - /** - * A Type-Specific set function to reduce (un)boxing - * @param index index of the element to replace - * @param e element to be stored at the specified position - * @return the element previously at the specified position - * @throws IndexOutOfBoundsException if the index is not within the list range - * @see List#set(int, Object) - */ - public KEY_TYPE set(int index, KEY_TYPE e); - - /** - * A Type-Specific remove function to reduce (un)boxing - * @param index the index of the element to be removed - * @return the element previously at the specified position - * @see List#remove(int) - */ - public KEY_TYPE REMOVE(int index); - - /** - * A Type-Specific indexOf function to reduce (un)boxing - * @param e the element that is searched for - * @return the index of the element if found. (if not found then -1) - * @note does not support null values - */ - public int indexOf(KEY_TYPE e); - - /** - * A Type-Specific lastIndexOf function to reduce (un)boxing - * @param e the element that is searched for - * @return the lastIndex of the element if found. (if not found then -1) - * @note does not support null values - */ - public int lastIndexOf(KEY_TYPE e); - -#if !TYPE_BOOLEAN - /** - * A Type-Specific replace function to reduce (un)boxing - * @param o the action to replace the values - * @throws NullPointerException if o is null - */ - public default void REPLACE(JAVA_UNARY_OPERATOR o) { - Objects.requireNonNull(o); - LIST_ITERATOR iter = listIterator(); - while (iter.hasNext()) -#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT - iter.set(SanityChecks.SANITY_CAST(o.APPLY_CAST(iter.NEXT()))); -#else - iter.set(o.APPLY(iter.NEXT())); -#endif - } - -#endif -#else - /** - * A function to replace all values in the list - * @param o the action to replace the values - * @throws NullPointerException if o is null - */ - @Override - public default void replaceAll(UnaryOperator o) { - Objects.requireNonNull(o); - LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); - while (iter.hasNext()) iter.set(o.apply(iter.NEXT())); - } - -#endif - /** - * A function to fast add elements to the list - * @param a the elements that should be added - * @throws IndexOutOfBoundsException if from is outside of the lists range - */ - public default void addElements(KEY_TYPE... a) { addElements(size(), a, 0, a.length); } - - /** - * A function to fast add elements to the list - * @param from the index where the elements should be added into the list - * @param a the elements that should be added - * @throws IndexOutOfBoundsException if from is outside of the lists range - */ - public default void addElements(int from, KEY_TYPE... a) { addElements(from, a, 0, a.length); } - - /** - * A function to fast add elements to the list - * @param from the index where the elements should be added into the list - * @param a the elements that should be added - * @param offset the start index of the array should be read from - * @param length how many elements should be read from - * @throws IndexOutOfBoundsException if from is outside of the lists range - */ - public void addElements(int from, KEY_TYPE[] a, int offset, int length); - - /** - * A function to fast fetch elements from the list - * @param from index where the list should be fetching elements from - * @param a the array where the values should be inserted to - * @return the inputArray - * @throws NullPointerException if the array is null - * @throws IndexOutOfBoundsException if from is outside of the lists range - * @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length - */ - public default KEY_TYPE[] getElements(int from, KEY_TYPE[] a) { return getElements(from, a, 0, a.length); } - - /** - * A function to fast fetch elements from the list - * @param from index where the list should be fetching elements from - * @param a the array where the values should be inserted to - * @param offset the startIndex of where the array should be written to - * @param length the number of elements the values should be fetched from - * @return the inputArray - * @throws NullPointerException if the array is null - * @throws IndexOutOfBoundsException if from is outside of the lists range - * @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length - */ - public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length); - - /** - * a function to fast remove elements from the list. - * @param from the start index of where the elements should be removed from (inclusive) - * @param to the end index of where the elements should be removed to (exclusive) - */ - public void removeElements(int from, int to); - - /** - * A Highly Optimized remove function that removes the desired element. - * But instead of shifting the elements to the left it moves the last element to the removed space. - * @param index the index of the element to be removed - * @return the element previously at the specified position - */ - public KEY_TYPE swapRemove(int index); - - /** - * A Highly Optimized remove function that removes the desired element. - * But instead of shifting the elements to the left it moves the last element to the removed space. - * @param e the element that should be removed - * @return true if the element was removed - */ - public boolean REMOVE_SWAP(KEY_TYPE e); - -#if TYPE_OBJECT - /** - * A function to fast extract elements out of the list, this removes the elements that were fetched. - * @param from the start index of where the elements should be fetched from (inclusive) - * @param to the end index of where the elements should be fetched to (exclusive) - * @param type the type of the OutputArray - * @return a array of the elements that were fetched - * @Type(K) - */ - public K[] extractElements(int from, int to, Class type); - - /** - * Sorts the elements specified by the Natural order either by using the Comparator or the elements - * @see java.util.List#sort(Comparator) - */ - @Override - public default void sort(Comparator c) { - KEY_TYPE[] array = (KEY_TYPE[])TO_ARRAY(); - if(c != null) ARRAYS.stableSort(array, c); - else ARRAYS.stableSort(array); - LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); - for (int i = 0,m=size();i c) { - KEY_TYPE[] array = (KEY_TYPE[])TO_ARRAY(); - if(c != null) ARRAYS.unstableSort(array, c); - else ARRAYS.unstableSort(array); - LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); - for (int i = 0,m=size();iThis default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - default void sort(Comparator c) { - sort((K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V))); - } - - /** - * Sorts the elements specified by the Natural order either by using the Comparator or the elements - * @param c the sorter of the elements, can be null - * @see java.util.List#sort(Comparator) - * @see ARRAYS#stableSort(KEY_TYPE[], COMPARATOR) - */ - public default void sort(COMPARATOR c) { - KEY_TYPE[] array = TO_ARRAY(); - if(c != null) ARRAYS.stableSort(array, c); - else ARRAYS.stableSort(array); - LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); - for (int i = 0,m=size();iThis default implementation delegates to the corresponding type-specific function. - * @param c the sorter of the elements, can be null - * @deprecated Please use the corresponding type-specific function instead. - */ - @Deprecated - public default void unstableSort(Comparator c) { - unstableSort((K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V))); - } - - /** - * Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort - * @param c the sorter of the elements, can be null - * @see java.util.List#sort(Comparator) - * @see ARRAYS#unstableSort(KEY_TYPE[], COMPARATOR) - */ - public default void unstableSort(COMPARATOR c) { - KEY_TYPE[] array = TO_ARRAY(); - if(c != null) ARRAYS.unstableSort(array, c); - else ARRAYS.unstableSort(array); - LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); - for (int i = 0,m=size();iThis default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - public default boolean add(CLASS_TYPE e) { - return COLLECTION.super.add(e); - } - - /** {@inheritDoc} - *

This default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - public default CLASS_TYPE get(int index) { - return KEY_TO_OBJ(GET_KEY(index)); - } - - /** {@inheritDoc} - *

This default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - public default CLASS_TYPE set(int index, CLASS_TYPE e) { - return KEY_TO_OBJ(set(index, OBJ_TO_KEY(e))); - } - - /** {@inheritDoc} - *

This default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - public default int indexOf(Object o) { - return indexOf(CLASS_TO_KEY(o)); - } - - /** {@inheritDoc} - *

This default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - public default int lastIndexOf(Object o) { - return lastIndexOf(CLASS_TO_KEY(o)); - } - - /** {@inheritDoc} - *

This default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - public default boolean contains(Object o) { - return COLLECTION.super.contains(o); - } - - /** {@inheritDoc} - *

This default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - public default boolean remove(Object o) { - return COLLECTION.super.remove(o); - } - - /** {@inheritDoc} - *

This default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - public default CLASS_TYPE remove(int index) { - return KEY_TO_OBJ(REMOVE(index)); - } - -#if !TYPE_BOOLEAN - /** {@inheritDoc} - *

This default implementation delegates to the corresponding type-specific function. - * @deprecated Please use the corresponding type-specific function instead. - */ - @Override - @Deprecated - public default void replaceAll(UnaryOperator o) { - Objects.requireNonNull(o); -#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT - REPLACE(T -> OBJ_TO_KEY(o.apply(KEY_TO_OBJ((KEY_TYPE)T)))); -#else - REPLACE(T -> OBJ_TO_KEY(o.apply(KEY_TO_OBJ(T)))); -#endif - } -#endif -#endif - /** - * 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); } +package speiger.src.collections.PACKAGE.lists; + +#if PRIMITIVES +import java.nio.JAVA_BUFFER; +#endif +import java.util.List; +#if !TYPE_OBJECT && !TYPE_BOOLEAN +import java.util.function.JAVA_UNARY_OPERATOR; +#endif + +import java.util.Objects; +import java.util.Comparator; +#if !TYPE_BOOLEAN +import java.util.function.UnaryOperator; +#endif + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; +import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.COMPARATOR; +#endif +import speiger.src.collections.PACKAGE.utils.ARRAYS; +#if LISTS_FEATURE +import speiger.src.collections.PACKAGE.utils.LISTS; +#endif +import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; +#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT +import speiger.src.collections.utils.SanityChecks; +#endif + +/** + * A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features + * @Type(T) + */ +public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List +{ +#if !TYPE_OBJECT + /** + * A Type-Specific add Function to reduce (un)boxing + * @param e the element to add + * @return true if the list was modified + * @see List#add(Object) + */ + @Override + public boolean add(KEY_TYPE e); + + /** + * A Type-Specific add Function to reduce (un)boxing + * @param e the element to add + * @param index index at which the specified element is to be inserted + * @see List#add(int, Object) + */ + public void add(int index, KEY_TYPE e); + +#endif + /** + * A Helper function that will only add elements if it is not present. + * @param e the element to add + * @return true if the list was modified + */ + public default boolean addIfAbsent(KEY_TYPE e) { + if(indexOf(e) == -1) return add(e); + return false; + } + + /** + * A Helper function that will only add elements if it is present. + * @param e the element to add + * @return true if the list was modified + */ + public default boolean addIfPresent(KEY_TYPE e) { + if(indexOf(e) != -1) return add(e); + return false; + } + + /** + * A Type-Specific addAll Function to reduce (un)boxing + * @param c the elements that need to be added + * @param index index at which the specified elements is to be inserted + * @return true if the list was modified + * @see java.util.List#addAll(int, java.util.Collection) + */ + public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c); + + /** + * A Type-Specific and optimized addAll function that allows a faster transfer of elements + * @param c the elements that need to be added + * @return true if the list was modified + */ + public boolean addAll(LIST KEY_GENERIC_TYPE c); + + /** + * A Type-Specific and optimized addAll function that allows a faster transfer of elements + * @param c the elements that need to be added + * @param index index at which the specified elements is to be inserted + * @return true if the list was modified + */ + public boolean addAll(int index, LIST KEY_GENERIC_TYPE c); + + /** + * Helper method that returns the first element of a List. + * This function was introduced due to how annoying it is to get/remove the last element of a list. + * This simplifies this process a bit. + * @return first element of the list + */ + public default KEY_TYPE GET_FIRST_KEY() { + return GET_KEY(0); + } + + /** + * Helper method that returns the last element of a List. + * This function was introduced due to how annoying it is to get/remove the last element of a list. + * This simplifies this process a bit. + * @return last element of the list + */ + public default KEY_TYPE GET_LAST_KEY() { + return GET_KEY(size() - 1); + } + + /** + * Helper method that removes and returns the first element of a List. + * This function was introduced due to how annoying it is to get/remove the last element of a list. + * This simplifies this process a bit. + * @return first element of the list and removes it + */ + public default KEY_TYPE REMOVE_FIRST_KEY() { + return REMOVE(0); + } + + /** + * Helper method that removes and returns the last element of a List. + * This function was introduced due to how annoying it is to get/remove the last element of a list. + * This simplifies this process a bit. + * @return last element of the list and removes it + */ + public default KEY_TYPE REMOVE_LAST_KEY() { + return REMOVE(size() - 1); + } + +#if !TYPE_OBJECT + /** + * A Type-Specific get function to reduce (un)boxing + * @param index the index of the value that is requested + * @return the value at the given index + * @throws IndexOutOfBoundsException if the index is not within the list range + * @see List#get(int) + */ + public KEY_TYPE GET_KEY(int index); + + /** + * A Type-Specific set function to reduce (un)boxing + * @param index index of the element to replace + * @param e element to be stored at the specified position + * @return the element previously at the specified position + * @throws IndexOutOfBoundsException if the index is not within the list range + * @see List#set(int, Object) + */ + public KEY_TYPE set(int index, KEY_TYPE e); + + /** + * A Type-Specific remove function to reduce (un)boxing + * @param index the index of the element to be removed + * @return the element previously at the specified position + * @see List#remove(int) + */ + public KEY_TYPE REMOVE(int index); + + /** + * A Type-Specific indexOf function to reduce (un)boxing + * @param e the element that is searched for + * @return the index of the element if found. (if not found then -1) + * @note does not support null values + */ + public int indexOf(KEY_TYPE e); + + /** + * A Type-Specific lastIndexOf function to reduce (un)boxing + * @param e the element that is searched for + * @return the lastIndex of the element if found. (if not found then -1) + * @note does not support null values + */ + public int lastIndexOf(KEY_TYPE e); + +#if !TYPE_BOOLEAN + /** + * A Type-Specific replace function to reduce (un)boxing + * @param o the action to replace the values + * @throws NullPointerException if o is null + */ + public default void REPLACE(JAVA_UNARY_OPERATOR o) { + Objects.requireNonNull(o); + LIST_ITERATOR iter = listIterator(); + while (iter.hasNext()) +#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT + iter.set(SanityChecks.SANITY_CAST(o.APPLY_CAST(iter.NEXT()))); +#else + iter.set(o.APPLY(iter.NEXT())); +#endif + } + +#endif +#else + /** + * A function to replace all values in the list + * @param o the action to replace the values + * @throws NullPointerException if o is null + */ + @Override + public default void replaceAll(UnaryOperator o) { + Objects.requireNonNull(o); + LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); + while (iter.hasNext()) iter.set(o.apply(iter.NEXT())); + } + +#endif + /** + * A function to fast add elements to the list + * @param a the elements that should be added + * @throws IndexOutOfBoundsException if from is outside of the lists range + */ + public default void addElements(KEY_TYPE... a) { addElements(size(), a, 0, a.length); } + + /** + * A function to fast add elements to the list + * @param from the index where the elements should be added into the list + * @param a the elements that should be added + * @throws IndexOutOfBoundsException if from is outside of the lists range + */ + public default void addElements(int from, KEY_TYPE... a) { addElements(from, a, 0, a.length); } + + /** + * A function to fast add elements to the list + * @param from the index where the elements should be added into the list + * @param a the elements that should be added + * @param offset the start index of the array should be read from + * @param length how many elements should be read from + * @throws IndexOutOfBoundsException if from is outside of the lists range + */ + public void addElements(int from, KEY_TYPE[] a, int offset, int length); + + /** + * A function to fast fetch elements from the list + * @param from index where the list should be fetching elements from + * @param a the array where the values should be inserted to + * @return the inputArray + * @throws NullPointerException if the array is null + * @throws IndexOutOfBoundsException if from is outside of the lists range + * @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length + */ + public default KEY_TYPE[] getElements(int from, KEY_TYPE[] a) { return getElements(from, a, 0, a.length); } + + /** + * A function to fast fetch elements from the list + * @param from index where the list should be fetching elements from + * @param a the array where the values should be inserted to + * @param offset the startIndex of where the array should be written to + * @param length the number of elements the values should be fetched from + * @return the inputArray + * @throws NullPointerException if the array is null + * @throws IndexOutOfBoundsException if from is outside of the lists range + * @throws IllegalStateException if offset or length are smaller then 0 or exceed the array length + */ + public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length); + + /** + * a function to fast remove elements from the list. + * @param from the start index of where the elements should be removed from (inclusive) + * @param to the end index of where the elements should be removed to (exclusive) + */ + public void removeElements(int from, int to); + + /** + * A Highly Optimized remove function that removes the desired element. + * But instead of shifting the elements to the left it moves the last element to the removed space. + * @param index the index of the element to be removed + * @return the element previously at the specified position + */ + public KEY_TYPE swapRemove(int index); + + /** + * A Highly Optimized remove function that removes the desired element. + * But instead of shifting the elements to the left it moves the last element to the removed space. + * @param e the element that should be removed + * @return true if the element was removed + */ + public boolean REMOVE_SWAP(KEY_TYPE e); + +#if TYPE_OBJECT + /** + * A function to fast extract elements out of the list, this removes the elements that were fetched. + * @param from the start index of where the elements should be fetched from (inclusive) + * @param to the end index of where the elements should be fetched to (exclusive) + * @param type the type of the OutputArray + * @return a array of the elements that were fetched + * @Type(K) + */ + public K[] extractElements(int from, int to, Class type); + + /** + * Sorts the elements specified by the Natural order either by using the Comparator or the elements + * @see java.util.List#sort(Comparator) + */ + @Override + public default void sort(Comparator c) { + KEY_TYPE[] array = (KEY_TYPE[])TO_ARRAY(); + if(c != null) ARRAYS.stableSort(array, c); + else ARRAYS.stableSort(array); + LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); + for (int i = 0,m=size();i c) { + KEY_TYPE[] array = (KEY_TYPE[])TO_ARRAY(); + if(c != null) ARRAYS.unstableSort(array, c); + else ARRAYS.unstableSort(array); + LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); + for (int i = 0,m=size();iThis default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + default void sort(Comparator c) { + sort((K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V))); + } + + /** + * Sorts the elements specified by the Natural order either by using the Comparator or the elements + * @param c the sorter of the elements, can be null + * @see java.util.List#sort(Comparator) + * @see ARRAYS#stableSort(KEY_TYPE[], COMPARATOR) + */ + public default void sort(COMPARATOR c) { + KEY_TYPE[] array = TO_ARRAY(); + if(c != null) ARRAYS.stableSort(array, c); + else ARRAYS.stableSort(array); + LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); + for (int i = 0,m=size();iThis default implementation delegates to the corresponding type-specific function. + * @param c the sorter of the elements, can be null + * @deprecated Please use the corresponding type-specific function instead. + */ + @Deprecated + public default void unstableSort(Comparator c) { + unstableSort((K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V))); + } + + /** + * Sorts the elements specified by the Natural order either by using the Comparator or the elements using a unstable sort + * @param c the sorter of the elements, can be null + * @see java.util.List#sort(Comparator) + * @see ARRAYS#unstableSort(KEY_TYPE[], COMPARATOR) + */ + public default void unstableSort(COMPARATOR c) { + KEY_TYPE[] array = TO_ARRAY(); + if(c != null) ARRAYS.unstableSort(array, c); + else ARRAYS.unstableSort(array); + LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(); + for (int i = 0,m=size();iThis default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + public default boolean add(CLASS_TYPE e) { + return COLLECTION.super.add(e); + } + + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + public default CLASS_TYPE get(int index) { + return KEY_TO_OBJ(GET_KEY(index)); + } + + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + public default CLASS_TYPE set(int index, CLASS_TYPE e) { + return KEY_TO_OBJ(set(index, OBJ_TO_KEY(e))); + } + + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + public default int indexOf(Object o) { + return indexOf(CLASS_TO_KEY(o)); + } + + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + public default int lastIndexOf(Object o) { + return lastIndexOf(CLASS_TO_KEY(o)); + } + + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + public default boolean contains(Object o) { + return COLLECTION.super.contains(o); + } + + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + public default boolean remove(Object o) { + return COLLECTION.super.remove(o); + } + + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + public default CLASS_TYPE remove(int index) { + return KEY_TO_OBJ(REMOVE(index)); + } + +#if !TYPE_BOOLEAN + /** {@inheritDoc} + *

This default implementation delegates to the corresponding type-specific function. + * @deprecated Please use the corresponding type-specific function instead. + */ + @Override + @Deprecated + public default void replaceAll(UnaryOperator o) { + Objects.requireNonNull(o); +#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT + REPLACE(T -> OBJ_TO_KEY(o.apply(KEY_TO_OBJ((KEY_TYPE)T)))); +#else + REPLACE(T -> OBJ_TO_KEY(o.apply(KEY_TO_OBJ(T)))); +#endif + } +#endif +#endif + /** + * 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); } } \ No newline at end of file