New Tests & BugFixes
-Added: Tests for the Copying of Collections. -Fixed: PriorityQueues didn't have hashCode/equals/toString implemented
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
package speiger.src.collections.PACKAGE.queues;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Objects;
|
||||
#endif
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Helper class that implements all the essential methods for the PriorityQueues
|
||||
* @Type(T)
|
||||
*/
|
||||
public abstract class ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof PRIORITY_QUEUE) {
|
||||
PRIORITY_QUEUE KEY_GENERIC_TYPE queue = (PRIORITY_QUEUE KEY_GENERIC_TYPE)obj;
|
||||
if(queue.size() != size()) return false;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(KEY_EQUALS_NOT(queue.peek(i), peek(i))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
result = 31 * result + KEY_TO_HASH(peek(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(isEmpty()) return "[]";
|
||||
StringJoiner joiner = new StringJoiner(", ", "[", "]");
|
||||
for (int i = 0,m=size();i<m;i++) {
|
||||
joiner.add(KEY_TO_STRING(peek(i)));
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@ import speiger.src.collections.utils.ITrimmable;
|
||||
* Its specific implementation uses a backing array that grows and shrinks as it is needed.
|
||||
* @Type(T)
|
||||
*/
|
||||
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
|
||||
public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_GENERIC_TYPE, ITrimmable
|
||||
{
|
||||
/** Max Possible ArraySize without the JVM Crashing */
|
||||
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
* It is highly suggested to use HeapPriorityQueue otherwise, unless you know why you need this specific implementation
|
||||
* @Type(T)
|
||||
*/
|
||||
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing Array */
|
||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
* It is a ArrayBased Alternative to TreeSets that has less object allocations
|
||||
* @Type(T)
|
||||
*/
|
||||
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing Array */
|
||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||
|
||||
+1
@@ -620,6 +620,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
set.links = Arrays.copyOf(links, links.length);
|
||||
set.firstIndex = firstIndex;
|
||||
set.lastIndex = lastIndex;
|
||||
return set;
|
||||
|
||||
+1
@@ -591,6 +591,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
set.containsNull = containsNull;
|
||||
set.size = size;
|
||||
set.keys = Arrays.copyOf(keys, keys.length);
|
||||
set.links = Arrays.copyOf(links, links.length);
|
||||
set.firstIndex = firstIndex;
|
||||
set.lastIndex = lastIndex;
|
||||
return set;
|
||||
|
||||
Reference in New Issue
Block a user