Primitive Stacks no longer depend on the base Stack class.

This commit is contained in:
Speiger 2021-06-23 19:07:30 +02:00
parent f4c25c683f
commit a669f69d99
5 changed files with 29 additions and 49 deletions

View File

@ -3,4 +3,6 @@
## Version 0.3.0
- Added: Stack.isEmpty was missing
- Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes
- Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes
- Removed: Suffixes for unmodifiable & synchronize functions.
- Changed: Primitive Stacks no longer depend on the base Stack class. Because seriously not needed.

View File

@ -235,9 +235,6 @@ public class GlobalVariables
addFunctionValueMapper("MERGE", "merge");
addFunctionMapper("NEXT", "next");
addFunctionMapper("PREVIOUS", "previous");
addFunctionMapper("PEEK", "peek");
addFunctionMapper("POP", "pop");
addFunctionMapper("PUSH", "push");
addFunctionMapper("REMOVE_KEY", "rem");
addFunctionMapper("REMOVE_LAST", "removeLast");
addFunctionMapper("REMOVE", "remove");
@ -246,7 +243,6 @@ public class GlobalVariables
addFunctionMappers("SORT", "sort%ss");
addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream");
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
addFunctionMapper("TOP", "top");
return this;
}

View File

@ -5,14 +5,14 @@ import speiger.src.collections.utils.Stack;
/**
* A Type-Specific {@link Stack} that reduces (un)boxing
*/
public interface STACK extends Stack<CLASS_TYPE>
public interface STACK
{
/**
* Inserts a given Object on top of the stack
* @param e the Object to insert
* @see Stack#push(Object)
*/
public void PUSH(KEY_TYPE e);
public void push(KEY_TYPE e);
/**
* Removes the Object on top of the stack.
@ -20,7 +20,7 @@ public interface STACK extends Stack<CLASS_TYPE>
* @throws ArrayIndexOutOfBoundsException if the stack is empty
* @see Stack#pop()
*/
public KEY_TYPE POP();
public KEY_TYPE pop();
/**
* Provides the Object on top of the stack
@ -28,8 +28,8 @@ public interface STACK extends Stack<CLASS_TYPE>
* @throws ArrayIndexOutOfBoundsException if the stack is empty
* @see Stack#top()
*/
public default KEY_TYPE TOP() {
return PEEK(0);
public default KEY_TYPE top() {
return peek(0);
}
/**
@ -40,41 +40,23 @@ public interface STACK extends Stack<CLASS_TYPE>
* @throws ArrayIndexOutOfBoundsException if the index is out of bounds
* @see Stack#peek(int)
*/
public KEY_TYPE PEEK(int index);
public KEY_TYPE peek(int index);
#if !OBJECT_TYPE
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default void push(CLASS_TYPE e) { PUSH(OBJ_TO_KEY(e)); }
/**
* Clears the stack
*/
public void clear();
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default CLASS_TYPE pop() { return KEY_TO_OBJ(POP()); }
/**
* Provides the amount of elements currently in the stack
* @return amount of elements in the list
*/
public int size();
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default CLASS_TYPE top() {
return peek(size() - 1);
/**
* @return if the stack is empty
*/
public default boolean isEmpty() {
return size() == 0;
}
/** {@inheritDoc}
* <p>This default implementation delegates to the corresponding type-specific function.
* @deprecated Please use the corresponding type-specific function instead.
*/
@Override
@Deprecated
public default CLASS_TYPE peek(int index) { return KEY_TO_OBJ(PEEK(index)); }
#endif
}

View File

@ -201,7 +201,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
* @param e element to be appended to this Stack
*/
@Override
public void PUSH(KEY_TYPE e) {
public void push(KEY_TYPE e) {
add(e);
}
@ -543,7 +543,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
* @see speiger.src.collections.utils.Stack#peek(int)
*/
@Override
public KEY_TYPE PEEK(int index) {
public KEY_TYPE peek(int index) {
checkRange((size() - 1) - index);
return data[(size() - 1) - index];
}
@ -683,7 +683,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override
public KEY_TYPE POP() {
public KEY_TYPE pop() {
return REMOVE(size() - 1);
}

View File

@ -18,13 +18,13 @@ public interface IIntStackTests
public default void testPush()
{
IntStack stacks = create(TEST_ARRAY);
stacks.pushInt(500);
Assert.assertEquals(500, stacks.topInt());
stacks.push(500);
Assert.assertEquals(500, stacks.top());
}
@Test
public default void testPop()
{
Assert.assertEquals(99, create(TEST_ARRAY).topInt());
Assert.assertEquals(99, create(TEST_ARRAY).top());
}
}