forked from Speiger/Primitive-Collections
New Tests & BugFixes
-Added: Tests for the Copying of Collections. -Fixed: PriorityQueues didn't have hashCode/equals/toString implemented
This commit is contained in:
parent
0c4ef7f6c4
commit
54c9660145
|
@ -184,6 +184,7 @@ public class GlobalVariables
|
||||||
|
|
||||||
//Abstract Classes
|
//Abstract Classes
|
||||||
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
||||||
|
addAbstractMapper("ABSTRACT_PRIORITY_QUEUE", "Abstract%sPriorityQueue");
|
||||||
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
|
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
|
||||||
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
|
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
|
||||||
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||||
nameRemapper.put("IArray", "I%sArray");
|
nameRemapper.put("IArray", "I%sArray");
|
||||||
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
||||||
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
|
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
|
||||||
|
nameRemapper.put("AbstractPriorityQueue", "Abstract%sPriorityQueue");
|
||||||
nameRemapper.put("AbstractSet", "Abstract%sSet");
|
nameRemapper.put("AbstractSet", "Abstract%sSet");
|
||||||
nameRemapper.put("AbstractList", "Abstract%sList");
|
nameRemapper.put("AbstractList", "Abstract%sList");
|
||||||
nameRemapper.put("EnumMap", "Enum2%sMap");
|
nameRemapper.put("EnumMap", "Enum2%sMap");
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.
|
* Its specific implementation uses a backing array that grows and shrinks as it is needed.
|
||||||
* @Type(T)
|
* @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 */
|
/** Max Possible ArraySize without the JVM Crashing */
|
||||||
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
|
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
|
||||||
|
|
|
@ -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
|
* It is highly suggested to use HeapPriorityQueue otherwise, unless you know why you need this specific implementation
|
||||||
* @Type(T)
|
* @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 */
|
/** The Backing Array */
|
||||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||||
|
|
|
@ -23,7 +23,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
* It is a ArrayBased Alternative to TreeSets that has less object allocations
|
* It is a ArrayBased Alternative to TreeSets that has less object allocations
|
||||||
* @Type(T)
|
* @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 */
|
/** The Backing Array */
|
||||||
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
protected transient KEY_TYPE[] array = EMPTY_KEY_ARRAY;
|
||||||
|
|
|
@ -620,6 +620,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||||
set.containsNull = containsNull;
|
set.containsNull = containsNull;
|
||||||
set.size = size;
|
set.size = size;
|
||||||
set.keys = Arrays.copyOf(keys, keys.length);
|
set.keys = Arrays.copyOf(keys, keys.length);
|
||||||
|
set.links = Arrays.copyOf(links, links.length);
|
||||||
set.firstIndex = firstIndex;
|
set.firstIndex = firstIndex;
|
||||||
set.lastIndex = lastIndex;
|
set.lastIndex = lastIndex;
|
||||||
return set;
|
return set;
|
||||||
|
|
|
@ -591,6 +591,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||||
set.containsNull = containsNull;
|
set.containsNull = containsNull;
|
||||||
set.size = size;
|
set.size = size;
|
||||||
set.keys = Arrays.copyOf(keys, keys.length);
|
set.keys = Arrays.copyOf(keys, keys.length);
|
||||||
|
set.links = Arrays.copyOf(links, links.length);
|
||||||
set.firstIndex = firstIndex;
|
set.firstIndex = firstIndex;
|
||||||
set.lastIndex = lastIndex;
|
set.lastIndex = lastIndex;
|
||||||
return set;
|
return set;
|
||||||
|
|
|
@ -135,6 +135,16 @@ public abstract class BaseInt2IntMapTest
|
||||||
Assert.assertTrue(map.remove(PUT_VALUE_ARRAY[51], PUT_ARRAY[51]));
|
Assert.assertTrue(map.remove(PUT_VALUE_ARRAY[51], PUT_ARRAY[51]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSort()
|
||||||
|
{
|
||||||
|
if(!getValidMapTests().contains(MapTests.COPY)) return;
|
||||||
|
Int2IntMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||||
|
Int2IntMap copy = map.copy();
|
||||||
|
Assert.assertFalse(map == copy);
|
||||||
|
Assert.assertEquals(map, copy);
|
||||||
|
}
|
||||||
|
|
||||||
public static class Strategy implements IntStrategy
|
public static class Strategy implements IntStrategy
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -178,4 +178,13 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
||||||
Assert.assertEquals(base, IntCollections.synchronize(collection).toString());
|
Assert.assertEquals(base, IntCollections.synchronize(collection).toString());
|
||||||
Assert.assertEquals(base, IntCollections.unmodifiable(collection).toString());
|
Assert.assertEquals(base, IntCollections.unmodifiable(collection).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCopy() {
|
||||||
|
if(!getValidCollectionTests().contains(CollectionTest.COPY)) return;
|
||||||
|
IntCollection collection = create(BULK_ADD_ARRAY);
|
||||||
|
IntCollection copy = collection.copy();
|
||||||
|
Assert.assertFalse(collection == copy);
|
||||||
|
Assert.assertEquals(collection, copy);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -120,4 +120,13 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCopy() {
|
||||||
|
if(!getValidPriorityQueueTests().contains(PriorityQueueTest.COPY)) return;
|
||||||
|
IntPriorityQueue queue = create(TEST_ARRAY);
|
||||||
|
IntPriorityQueue copy = queue.copy();
|
||||||
|
Assert.assertFalse(queue == copy);
|
||||||
|
Assert.assertEquals(queue, copy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,5 +15,6 @@ public enum CollectionTest
|
||||||
TO_ARRAY,
|
TO_ARRAY,
|
||||||
CLEAR,
|
CLEAR,
|
||||||
WRAPPER,
|
WRAPPER,
|
||||||
TO_STRING;
|
TO_STRING,
|
||||||
|
COPY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,6 @@ public enum MapTests
|
||||||
MERGE,
|
MERGE,
|
||||||
GET,
|
GET,
|
||||||
ITERATORS,
|
ITERATORS,
|
||||||
REMOVE;
|
REMOVE,
|
||||||
|
COPY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,5 @@ public enum PriorityQueueTest
|
||||||
PEEK,
|
PEEK,
|
||||||
REMOVE,
|
REMOVE,
|
||||||
TO_ARRAY,
|
TO_ARRAY,
|
||||||
|
COPY;
|
||||||
}
|
}
|
Loading…
Reference in New Issue