From 6eded1f4beee25d8dad881ba59f34c5401365d89 Mon Sep 17 00:00:00 2001 From: Speiger Date: Wed, 6 Oct 2021 17:43:46 +0200 Subject: [PATCH] Sets are now Copyable --- .../LinkedOpenCustomHashMap.template | 6 ++++ .../customHash/OpenCustomHashMap.template | 3 ++ .../maps/impl/hash/LinkedOpenHashMap.template | 6 ++++ .../maps/impl/hash/OpenHashMap.template | 3 ++ .../immutable/ImmutableOpenHashMap.template | 6 ++++ .../maps/impl/misc/ArrayMap.template | 12 +++++++ .../maps/impl/misc/LinkedEnumMap.template | 4 +++ .../maps/impl/tree/AVLTreeMap.template | 3 ++ .../maps/impl/tree/RBTreeMap.template | 3 ++ .../templates/sets/AVLTreeSet.template | 34 +++++++++++++++++++ .../templates/sets/AbstractSet.template | 2 ++ .../templates/sets/ArraySet.template | 12 ++++++- .../sets/ImmutableOpenHashSet.template | 21 ++++++++++++ .../sets/LinkedOpenCustomHashSet.template | 16 +++++++++ .../templates/sets/LinkedOpenHashSet.template | 16 +++++++++ .../templates/sets/NavigableSet.template | 2 ++ .../templates/sets/OpenCustomHashSet.template | 13 +++++++ .../templates/sets/OpenHashSet.template | 13 +++++++ .../templates/sets/RBTreeSet.template | 34 +++++++++++++++++++ .../collections/templates/sets/Set.template | 3 ++ .../templates/sets/SortedSet.template | 3 ++ .../collections/templates/utils/Sets.template | 25 +++++++++++++- 22 files changed, 238 insertions(+), 2 deletions(-) diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template index 55fa76d..ec9c70f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template @@ -653,6 +653,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M return new FastEntryIterator(fromElement); } + @Override + public MapEntrySet copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(Consumer action) { int index = firstIndex; @@ -861,6 +864,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M return new KeyIterator(fromElement); } + @Override + public KeySet copy() { throw new UnsupportedOperationException(); } + @Override public int size() { return LINKED_CUSTOM_HASH_MAP.this.size(); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template index e4ab8bb..c4dded1 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template @@ -964,6 +964,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL return new KeyIterator(); } + @Override + public KeySet copy() { throw new UnsupportedOperationException(); } + @Override public int size() { return CUSTOM_HASH_MAP.this.size(); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template index d292f08..83f7832 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template @@ -630,6 +630,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G return new FastEntryIterator(fromElement); } + @Override + public MapEntrySet copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(Consumer action) { int index = firstIndex; @@ -838,6 +841,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G return new KeyIterator(fromElement); } + @Override + public KeySet copy() { throw new UnsupportedOperationException(); } + @Override public int size() { return LINKED_HASH_MAP.this.size(); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template index a4111e4..74f1fbb 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template @@ -934,6 +934,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE HASH_MAP.this.clear(); } + @Override + public KeySet copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { if(containsNull) action.accept(keys[nullIndex]); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/immutable/ImmutableOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/immutable/ImmutableOpenHashMap.template index f4d2517..94c8339 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/immutable/ImmutableOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/immutable/ImmutableOpenHashMap.template @@ -589,6 +589,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_ return new FastEntryIterator(fromElement); } + @Override + public MapEntrySet copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(Consumer action) { int index = firstIndex; @@ -773,6 +776,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_ return new KeyIterator(fromElement); } + @Override + public KeySet copy() { throw new UnsupportedOperationException(); } + @Override public int size() { return IMMUTABLE_HASH_MAP.this.size(); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template index c7064e4..21a02c9 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template @@ -1133,6 +1133,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN return new SubFastEntryIterator(fromElement); } + @Override + public SubMapEntrySet copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(Consumer action) { Objects.requireNonNull(action); @@ -1316,6 +1319,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN @Override public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); } + @Override + public SubKeySet copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { Objects.requireNonNull(action); @@ -1698,6 +1704,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN return new FastEntryIterator(fromElement); } + @Override + public MapEntrySet copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(Consumer action) { Objects.requireNonNull(action); @@ -1882,6 +1891,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN @Override public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); } + @Override + public KeySet copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { Objects.requireNonNull(action); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template index 995dc37..4704c0b 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template @@ -351,6 +351,8 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA return new FastEntryIterator(fromElement); } + public MapEntrySet copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(Consumer action) { int index = firstIndex; @@ -477,6 +479,8 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA return new KeyIterator(fromElement); } + public KeySet copy() { throw new UnsupportedOperationException(); } + @Override public int size() { return LINKED_ENUM_MAP.this.size(); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template index e47ef45..ad126ff 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template @@ -1952,6 +1952,9 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ } #endif + @Override + public KeySet KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + @Override public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return new KeySetKV_BRACES(m.subMap(fromElement, fromInclusive, toElement, toInclusive)); diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template index 68ec382..8e13d3b 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template @@ -2018,6 +2018,9 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G } #endif + @Override + public KeySet KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + @Override public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return new KeySetKV_BRACES(m.subMap(fromElement, fromInclusive, toElement, toInclusive)); diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template index 5b67db7..677e44c 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template @@ -538,6 +538,21 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE tree = null; } + public AVL_TREE_SET KEY_GENERIC_TYPE copy() { + AVL_TREE_SET KEY_GENERIC_TYPE set = new AVL_TREE_SETBRACES(); + set.size = size; + if(tree != null) { + set.tree = tree.copy(); + Entry KEY_GENERIC_TYPE lastFound = null; + for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry; + set.first = lastFound; + lastFound = null; + for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry; + set.last = lastFound; + } + return set; + } + @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; } @@ -1009,6 +1024,9 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE); } + @Override + public SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { Objects.requireNonNull(action); @@ -1250,6 +1268,22 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE this.parent = parent; } + Entry KEY_GENERIC_TYPE copy() { + Entry KEY_GENERIC_TYPE entry = new EntryBRACES(key, null); + entry.state = state; + if(left != null) { + Entry KEY_GENERIC_TYPE newLeft = left.copy(); + entry.left = newLeft; + newLeft.parent = entry; + } + if(right != null) { + Entry KEY_GENERIC_TYPE newRight = right.copy(); + entry.right = newRight; + newRight.parent = entry; + } + return entry; + } + int getHeight() { return state; } void updateHeight() { state = (1 + Math.max(left == null ? -1 : left.getHeight(), right == null ? -1 : right.getHeight())); } diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/AbstractSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/AbstractSet.template index ba6249a..74db7e2 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/AbstractSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/AbstractSet.template @@ -15,6 +15,8 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION { @Override public abstract ITERATOR KEY_GENERIC_TYPE iterator(); + @Override + public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } @Override public int hashCode() { diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template b/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template index 98593b6..253c3a7 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/ArraySet.template @@ -450,6 +450,13 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im return new SubSet(fromIndex, size - fromIndex); } + public ARRAY_SET KEY_GENERIC_TYPE copy() { + ARRAY_SET KEY_GENERIC_TYPE set = new ARRAY_SETBRACES(); + set.data = Arrays.copyOf(data, data.length); + set.size = size; + return set; + } + @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; @@ -675,7 +682,10 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im if(index != -1) return new SetIterator(index); throw new NoSuchElementException(); } - + + @Override + public SubSet copy() { throw new UnsupportedOperationException(); } + @Override public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { int fromIndex = findIndex(fromElement); diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/ImmutableOpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/ImmutableOpenHashSet.template index ba08d82..cc13a4a 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/ImmutableOpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/ImmutableOpenHashSet.template @@ -4,6 +4,7 @@ package speiger.src.collections.PACKAGE.sets; import java.util.Comparator; import java.util.function.Consumer; #endif +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; @@ -50,6 +51,12 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI /** The Last Index in the Map */ protected int lastIndex = -1; + /** + * Helper constructor to optimize the copying + * Only accessible through implementations + */ + protected IMMUTABLE_HASH_SET() {} + /** * Helper constructor that allow to create a set from unboxed values * @param array the elements that should be put into the set @@ -372,6 +379,20 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI return new SetIterator(fromElement); } + @Override + public IMMUTABLE_HASH_SET KEY_GENERIC_TYPE copy() { + IMMUTABLE_HASH_SET KEY_GENERIC_TYPE set = new IMMUTABLE_HASH_SETBRACES(); + set.containsNull = containsNull; + set.firstIndex = firstIndex; + set.lastIndex = lastIndex; + set.size = size; + set.mask = mask; + set.nullIndex = nullIndex; + set.keys = Arrays.copyOf(keys, keys.length); + set.links = Arrays.copyOf(links, links.length); + return set; + } + @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; } diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template index e521eec..5a2f540 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template @@ -4,6 +4,7 @@ package speiger.src.collections.PACKAGE.sets; import java.util.Comparator; import java.util.function.Consumer; #endif +import java.util.Arrays; import java.util.Objects; import java.util.Collection; import java.util.Iterator; @@ -609,6 +610,21 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY return new SetIterator(fromElement); } + @Override + public LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE copy() { + LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE set = new LINKED_CUSTOM_HASH_SETBRACES(0, loadFactor, strategy); + set.minCapacity = minCapacity; + set.mask = mask; + set.maxFill = maxFill; + set.nullIndex = nullIndex; + set.containsNull = containsNull; + set.size = size; + set.keys = Arrays.copyOf(keys, keys.length); + set.firstIndex = firstIndex; + set.lastIndex = lastIndex; + return set; + } + @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; } diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template index 21fcde3..b1a7bb4 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template @@ -3,6 +3,7 @@ package speiger.src.collections.PACKAGE.sets; #if TYPE_OBJECT import java.util.Comparator; #endif +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; @@ -580,6 +581,21 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE return new SetIterator(fromElement); } + @Override + public LINKED_HASH_SET KEY_GENERIC_TYPE copy() { + LINKED_HASH_SET KEY_GENERIC_TYPE set = new LINKED_HASH_SETBRACES(0, loadFactor); + set.minCapacity = minCapacity; + set.mask = mask; + set.maxFill = maxFill; + set.nullIndex = nullIndex; + set.containsNull = containsNull; + set.size = size; + set.keys = Arrays.copyOf(keys, keys.length); + set.firstIndex = firstIndex; + set.lastIndex = lastIndex; + return set; + } + @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; } diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/NavigableSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/NavigableSet.template index 6d77bc3..185a5ae 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/NavigableSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/NavigableSet.template @@ -115,6 +115,8 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet /** @return a Type Specific desendingSet */ @Override public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet(); + @Override + public NAVIGABLE_SET KEY_GENERIC_TYPE copy(); /** * A Type Specific Type Splititerator to reduce boxing/unboxing diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template index 337df70..efab719 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template @@ -445,6 +445,19 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T return new SetIterator(); } + @Override + public CUSTOM_HASH_SET KEY_GENERIC_TYPE copy() { + CUSTOM_HASH_SET KEY_GENERIC_TYPE set = new CUSTOM_HASH_SETBRACES(0, loadFactor, strategy); + set.minCapacity = minCapacity; + set.mask = mask; + set.maxFill = maxFill; + set.nullIndex = nullIndex; + set.containsNull = containsNull; + set.size = size; + set.keys = Arrays.copyOf(keys, keys.length); + return set; + } + @Override public void clear() { if(size == 0) return; diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template index 2ba3ed8..942a16f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template @@ -477,6 +477,19 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp return new SetIterator(); } + @Override + public HASH_SET KEY_GENERIC_TYPE copy() { + HASH_SET KEY_GENERIC_TYPE set = new HASH_SETBRACES(0, loadFactor); + set.minCapacity = minCapacity; + set.mask = mask; + set.maxFill = maxFill; + set.nullIndex = nullIndex; + set.containsNull = containsNull; + set.size = size; + set.keys = Arrays.copyOf(keys, keys.length); + return set; + } + @Override public void clear() { if(size == 0) return; diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template index 1860c0b..532291e 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/RBTreeSet.template @@ -540,6 +540,21 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE tree = null; } + public RB_TREE_SET KEY_GENERIC_TYPE copy() { + RB_TREE_SET KEY_GENERIC_TYPE set = new RB_TREE_SETBRACES(); + set.size = size; + if(tree != null) { + set.tree = tree.copy(); + Entry KEY_GENERIC_TYPE lastFound = null; + for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.left) lastFound = entry; + set.first = lastFound; + lastFound = null; + for(Entry KEY_GENERIC_TYPE entry = tree;entry != null;entry = entry.right) lastFound = entry; + set.last = lastFound; + } + return set; + } + @Override public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; } @@ -1070,6 +1085,9 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE return fromStart && toEnd ? set.size() : iterator().skip(Integer.MAX_VALUE); } + @Override + public SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + @Override public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { Objects.requireNonNull(action); @@ -1314,6 +1332,22 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE this.parent = parent; } + Entry KEY_GENERIC_TYPE copy() { + Entry KEY_GENERIC_TYPE entry = new EntryBRACES(key, null); + entry.state = state; + if(left != null) { + Entry KEY_GENERIC_TYPE newLeft = left.copy(); + entry.left = newLeft; + newLeft.parent = entry; + } + if(right != null) { + Entry KEY_GENERIC_TYPE newRight = right.copy(); + entry.right = newRight; + newRight.parent = entry; + } + return entry; + } + boolean isBlack() { return (state & BLACK) != 0; } diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/Set.template b/src/builder/resources/speiger/assets/collections/templates/sets/Set.template index 9a37736..80b37eb 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/Set.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/Set.template @@ -16,6 +16,9 @@ public interface SET KEY_GENERIC_TYPE extends Set, COLLECTION KEY_GE @Override public ITERATOR KEY_GENERIC_TYPE iterator(); + @Override + public SET KEY_GENERIC_TYPE copy(); + #if !TYPE_OBJECT /** * A Type Specific remove function to reduce boxing/unboxing diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template index 76d40a8..152ee7b 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/SortedSet.template @@ -60,6 +60,9 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte @Override public COMPARATOR KEY_GENERIC_TYPE comparator(); + @Override + public SORTED_SET KEY_GENERIC_TYPE copy(); + @Override public BI_ITERATOR KEY_GENERIC_TYPE iterator(); /** diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template b/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template index 1013aed..2f54598 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Sets.template @@ -190,6 +190,9 @@ public class SETS } @Override public int size() { return 1; } + + @Override + public SingletonSet KEY_GENERIC_TYPE copy() { return new SingletonSetBRACES(element); } } private static class EmptySet KEY_GENERIC_TYPE extends EmptyCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE @@ -198,6 +201,8 @@ public class SETS @Override public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); } #endif + @Override + public EmptySet KEY_GENERIC_TYPE copy() { return this; } } #if !TYPE_BOOLEAN @@ -245,6 +250,9 @@ public class SETS public KEY_TYPE getDefaultMinValue() { return n.getDefaultMinValue(); } #endif + @Override + public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + @Override public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); } @@ -300,6 +308,9 @@ public class SETS @Override public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); } + @Override + public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + @Override public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(s.subSet(fromElement, toElement)); } @@ -336,6 +347,9 @@ public class SETS s = c; } + @Override + public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + #if !TYPE_OBJECT @Override public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); } @@ -412,6 +426,9 @@ public class SETS public KEY_TYPE getDefaultMinValue() { synchronized(mutex) { return n.getDefaultMinValue(); } } #endif + @Override + public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + @Override public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } } @@ -492,7 +509,10 @@ public class SETS @Override public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } } - + + @Override + public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + @Override public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.subSet(fromElement, toElement), mutex); } } @@ -556,6 +576,9 @@ public class SETS #endif } + @Override + public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + #if !TYPE_OBJECT @Override public boolean remove(KEY_TYPE o) { synchronized(mutex) { return s.remove(o); } }