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

@ -4,3 +4,5 @@
## Version 0.3.0 ## Version 0.3.0
- Added: Stack.isEmpty was missing - 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"); addFunctionValueMapper("MERGE", "merge");
addFunctionMapper("NEXT", "next"); addFunctionMapper("NEXT", "next");
addFunctionMapper("PREVIOUS", "previous"); addFunctionMapper("PREVIOUS", "previous");
addFunctionMapper("PEEK", "peek");
addFunctionMapper("POP", "pop");
addFunctionMapper("PUSH", "push");
addFunctionMapper("REMOVE_KEY", "rem"); addFunctionMapper("REMOVE_KEY", "rem");
addFunctionMapper("REMOVE_LAST", "removeLast"); addFunctionMapper("REMOVE_LAST", "removeLast");
addFunctionMapper("REMOVE", "remove"); addFunctionMapper("REMOVE", "remove");
@ -246,7 +243,6 @@ public class GlobalVariables
addFunctionMappers("SORT", "sort%ss"); addFunctionMappers("SORT", "sort%ss");
addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream"); addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream");
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array"); addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
addFunctionMapper("TOP", "top");
return this; return this;
} }

View File

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

View File

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