forked from Speiger/Primitive-Collections
Fixed Bugs found with wrapper collections
-Fixed: AbstractCollection.Iterator was changing the pointer before validating if the element was added. (ImmutableLists) -Fixed: EmptyCollections containsAll should return true if it is compared against a emptyCollection. -Fixed: HashCode/Equals for the Lists/Sets implementations. -Changed: Iterators.wrap(Array) allows now dynamic arrays.
This commit is contained in:
parent
9eb220194f
commit
1e7da394a1
|
@ -18,7 +18,7 @@ repositories {
|
|||
}
|
||||
|
||||
archivesBaseName = 'Primitive Collections'
|
||||
version = '0.6.2.6-SNAPSHOT';
|
||||
version = '0.6.2.8-SNAPSHOT';
|
||||
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
||||
|
||||
|
|
|
@ -540,7 +540,8 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||
|
||||
@Override
|
||||
public void add(KEY_TYPE e) {
|
||||
ABSTRACT_LIST.this.add(index++, e);
|
||||
ABSTRACT_LIST.this.add(index, e);
|
||||
index++;
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -350,7 +350,7 @@ public class COLLECTIONS
|
|||
@Override
|
||||
public boolean contains(KEY_TYPE o) { return false; }
|
||||
@Override
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return false; }
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return c.isEmpty(); }
|
||||
@Override
|
||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { return false; }
|
||||
#else
|
||||
|
@ -362,7 +362,7 @@ public class COLLECTIONS
|
|||
public boolean containsAny(Collection<?> c) { return false; }
|
||||
@Override
|
||||
@Primitive
|
||||
public boolean containsAll(Collection<?> c) { return false; }
|
||||
public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
|
||||
@Override
|
||||
public int hashCode() { return 0; }
|
||||
|
||||
|
@ -401,14 +401,28 @@ public class COLLECTIONS
|
|||
public Object[] toArray() { return ObjectArrays.EMPTY_ARRAY; }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) { return a; }
|
||||
public <T> T[] toArray(T[] a) {
|
||||
if(a != null && a.length > 0)
|
||||
a[0] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY() { return ARRAYS.EMPTY_ARRAY; }
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { return a; }
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a != null && a.length > 0)
|
||||
a[0] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <E> E[] toArray(E[] a) { return a; }
|
||||
public <E> E[] toArray(E[] a) {
|
||||
if(a != null && a.length > 0)
|
||||
a[0] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.empty(); }
|
||||
|
|
|
@ -299,7 +299,7 @@ public class ITERATORS
|
|||
* @ArrayType(T)
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
|
@ -755,7 +755,7 @@ public class ITERATORS
|
|||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.RandomAccess;
|
||||
|
@ -601,6 +602,16 @@ public class LISTS
|
|||
return ITERATORS.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() { return 1; }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o == this) return true;
|
||||
if(!(o instanceof List)) return false;
|
||||
return ((List<?>)o).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) { throw new UnsupportedOperationException(); }
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
#if TYPE_BOOLEAN
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.booleans.sets.AbstractBooleanSet;
|
||||
|
@ -242,6 +243,13 @@ public class SETS
|
|||
@Override
|
||||
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o == this) return true;
|
||||
if(!(o instanceof Set)) return false;
|
||||
return ((Set<?>)o).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue