diff --git a/build.gradle b/build.gradle
index 7b4eb6d..8a27cd6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,15 +1,15 @@
-plugins {
- id 'java-library'
-}
-
-tasks.withType(JavaCompile) {
- options.encoding = 'UTF-8'
-}
-
-repositories {
- jcenter()
-}
-
-dependencies {
- testImplementation 'junit:junit:4.12'
-}
+plugins {
+ id 'java-library'
+}
+
+tasks.withType(JavaCompile) {
+ options.encoding = 'UTF-8'
+}
+
+repositories {
+ jcenter()
+}
+
+dependencies {
+ testImplementation 'junit:junit:4.12'
+}
diff --git a/src/main/resources/speiger/assets/collections/templates/collections/AbstractCollection.template b/src/main/resources/speiger/assets/collections/templates/collections/AbstractCollection.template
index e718343..b6a73e7 100644
--- a/src/main/resources/speiger/assets/collections/templates/collections/AbstractCollection.template
+++ b/src/main/resources/speiger/assets/collections/templates/collections/AbstractCollection.template
@@ -54,16 +54,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
}
#endif
- /** {@inheritDoc}
- *
This default implementation delegates to the corresponding type-specific function.
- * @deprecated Please use the corresponding type-specific function instead.
- */
- @Override
- @Deprecated
- public boolean containsAll(Collection> c)
- {
- return c instanceof COLLECTION ? containsAll((COLLECTION KEY_GENERIC_TYPE)c) : super.containsAll(c);
- }
/** {@inheritDoc}
*
This default implementation delegates to the corresponding type-specific function.
@@ -76,28 +66,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
return c instanceof COLLECTION ? addAll((COLLECTION KEY_GENERIC_TYPE)c) : super.addAll(c);
}
- /** {@inheritDoc}
- *
This default implementation delegates to the corresponding type-specific function.
- * @deprecated Please use the corresponding type-specific function instead.
- */
- @Override
- @Primitive
- public boolean removeAll(Collection> c)
- {
- return c instanceof COLLECTION ? removeAll((COLLECTION KEY_GENERIC_TYPE)c) : super.removeAll(c);
- }
-
- /** {@inheritDoc}
- *
This default implementation delegates to the corresponding type-specific function.
- * @deprecated Please use the corresponding type-specific function instead.
- */
- @Override
- @Primitive
- public boolean retainAll(Collection> c)
- {
- return c instanceof COLLECTION ? retainAll((COLLECTION KEY_GENERIC_TYPE)c) : super.retainAll(c);
- }
-
/**
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
* @param the collection that should be checked if it contains all elements.
diff --git a/src/main/resources/speiger/assets/collections/templates/collections/Collection.template b/src/main/resources/speiger/assets/collections/templates/collections/Collection.template
index 505c41e..09ab2be 100644
--- a/src/main/resources/speiger/assets/collections/templates/collections/Collection.template
+++ b/src/main/resources/speiger/assets/collections/templates/collections/Collection.template
@@ -63,7 +63,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection, ITE
@Primitive
public boolean containsAny(Collection> c);
-#if !TYPE_OBJECT
+ #if !TYPE_OBJECT
/**
* A Type-Specific remove function that reduces (un)boxing.
* @return true if the element was removed
diff --git a/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template b/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template
index 77a0389..e2b5e16 100644
--- a/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template
+++ b/src/main/resources/speiger/assets/collections/templates/lists/ArrayList.template
@@ -369,7 +369,6 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
@Override
@Primitive
public boolean containsAll(Collection> c) {
- if(c instanceof COLLECTION) return containsAll((COLLECTION KEY_GENERIC_TYPE)c);
Objects.requireNonNull(c);
for(int i = 0,m=size;i c)
- {
- if(c instanceof COLLECTION) return containsAny((COLLECTION KEY_GENERIC_TYPE)c);
+ public boolean containsAny(Collection> c) {
Objects.requireNonNull(c);
for(int i = 0,m=size;i c) {
if(c.isEmpty()) return false;
- if(c instanceof COLLECTION) return removeAll((COLLECTION KEY_GENERIC_TYPE)c);
boolean modified = false;
int j = 0;
for(int i = 0;i=0;i--)
if(EQUALS(data[i], o)) return i;
return -1;
}
+#endif
+ protected int findIndex(Object o) {
+ for(int i = size-1;i>=0;i--)
+ if(EQUALS_KEY_TYPE(data[i], o)) return i;
+ return -1;
+ }
+
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
return new SetIterator(0);
@@ -359,13 +365,12 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
return findIndex(e) != -1;
}
-#else
+#endif
@Override
public boolean contains(Object e) {
- return findIndex((KEY_TYPE)e) != -1;
+ return findIndex(e) != -1;
}
-#endif
@Override
public KEY_TYPE FIRST_KEY() {
if(length == 0) throw new NoSuchElementException();
@@ -391,10 +396,10 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
return false;
}
-#else
+#endif
@Override
public boolean remove(Object o) {
- int index = findIndex((KEY_TYPE)o);
+ int index = findIndex(o);
if(index != -1) {
System.arraycopy(data, index+1, data, index, size - index);
data[size-1] = EMPTY_VALUE;
@@ -405,7 +410,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
return false;
}
-#endif
@Override
public KEY_TYPE POLL_FIRST_KEY() {
if(length == 0) throw new NoSuchElementException();
@@ -476,9 +480,17 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
return length;
}
- private int findIndex(KEY_TYPE o) {
- for(int i = length-1;i>=0;i--)
- if(data[offset+i] == o) return i + offset;
+#if !TYPE_OBJECT
+ protected int findIndex(KEY_TYPE o) {
+ for(int i = size-1;i>=0;i--)
+ if(EQUALS(data[offset+i], o)) return i + offset;
+ return -1;
+ }
+
+#endif
+ protected int findIndex(Object o) {
+ for(int i = size-1;i>=0;i--)
+ if(EQUALS_KEY_TYPE(data[offset+i], o)) return i + offset;
return -1;
}
}
diff --git a/src/main/resources/speiger/assets/collections/templates/sets/OpenHashSet.template b/src/main/resources/speiger/assets/collections/templates/sets/OpenHashSet.template
index 60bf2ea..60f10ee 100644
--- a/src/main/resources/speiger/assets/collections/templates/sets/OpenHashSet.template
+++ b/src/main/resources/speiger/assets/collections/templates/sets/OpenHashSet.template
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
-#if TYPE_OBJECT
import java.util.Objects;
-#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION;
import speiger.src.collections.PACKAGE.collections.ITERATOR;
@@ -152,34 +150,33 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
return super.addAll(c);
}
-#if TYPE_OBJECT
@Override
public boolean contains(Object o) {
- if(EQUALS_NULL(o)) return containsNull;
- int pos = HashUtil.mix(TO_HASH(o)) & mask;
+ if(o == null) return containsNull;
+ int pos = HashUtil.mix(o.hashCode()) & mask;
KEY_TYPE current = keys[pos];
if(EQUALS_NULL(current)) return false;
- if(EQUALS(current, o)) return true;
+ if(EQUALS_KEY_TYPE(current, o)) return true;
while(true) {
if(EQUALS_NULL((current = keys[++pos & mask]))) return false;
- else if(EQUALS(current, o)) return true;
+ else if(EQUALS_KEY_TYPE(current, o)) return true;
}
}
@Override
public boolean remove(Object o) {
- if(EQUALS_NULL(o)) return (containsNull ? removeNullIndex() : false);
- int pos = HashUtil.mix(TO_HASH(o)) & mask;
+ if(o == null) return (containsNull ? removeNullIndex() : false);
+ int pos = HashUtil.mix(o.hashCode()) & mask;
KEY_TYPE current = keys[pos];
if(EQUALS_NULL(current)) return false;
- if(EQUALS(current, o)) return removeIndex(pos);
+ if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos);
while(true) {
if(EQUALS_NULL((current = keys[++pos & mask]))) return false;
- else if(EQUALS(current, o)) return removeIndex(pos);
+ else if(EQUALS_KEY_TYPE(current, o)) return removeIndex(pos);
}
}
-#else
+#if !TYPE_OBJECT
@Override
public boolean contains(KEY_TYPE o) {
if(EQUALS_NULL(o)) return containsNull;
diff --git a/src/main/resources/speiger/assets/collections/templates/sets/RBTreeSet.template b/src/main/resources/speiger/assets/collections/templates/sets/RBTreeSet.template
index 1bcc45d..02171b8 100644
--- a/src/main/resources/speiger/assets/collections/templates/sets/RBTreeSet.template
+++ b/src/main/resources/speiger/assets/collections/templates/sets/RBTreeSet.template
@@ -240,13 +240,12 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return findNode(e) != null;
}
-#else
+#endif
@Override
public boolean contains(Object e) {
- return findNode((T)e) != null;
+ return findNode(OBJ_TO_KEY(((CLASS_TYPE)e))) != null;
}
-#endif
@Override
public KEY_TYPE FIRST_KEY() {
if(tree == null) throw new NoSuchElementException();
@@ -271,11 +270,11 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return false;
}
-#else
+#endif
@Override
public boolean remove(Object o) {
if(tree == null) return false;
- Entry KEY_GENERIC_TYPE entry = findNode((T)o);
+ Entry KEY_GENERIC_TYPE entry = findNode(OBJ_TO_KEY(((CLASS_TYPE)o)));
if(entry != null) {
removeNode(entry);
return true;
@@ -283,7 +282,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return false;
}
-#endif
@Override
public KEY_TYPE POLL_FIRST_KEY() {
if(tree == null) throw new NoSuchElementException();
@@ -766,18 +764,19 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return inRange(o) && set.remove(o);
}
-#else
+#endif
@Override
public boolean contains(Object e) {
- return inRange((T)e) && set.contains((T)e);
+ KEY_TYPE o = OBJ_TO_KEY(((CLASS_TYPE)e));
+ return inRange(o) && set.contains(o);
}
@Override
- public boolean remove(Object o) {
- return inRange((T)o) && set.remove((T)o);
+ public boolean remove(Object e) {
+ KEY_TYPE o = OBJ_TO_KEY(((CLASS_TYPE)e));
+ return inRange(o) && set.remove(o);
}
-#endif
@Override
public KEY_TYPE lower(KEY_TYPE e) {
if(tooHigh(e)) {