@Test void toArray() { FixedStack<String> stack = new FixedStack<>(2); Assertions.assertEquals("[]", Arrays.toString(stack.toArray(String[].class))); stack.push("1"); stack.push("2"); Assertions.assertEquals("[2, 1]", Arrays.toString(stack.toArray(String[].class))); }
@Override public final T[] toArray(Class<T[]> arrayType) { Object[] array = new Object[size()]; for (int stackIndex = size() - 1, arrayIndex = 0; stackIndex > -1; stackIndex--, arrayIndex++) { array[arrayIndex] = stack[stackIndex]; } return Arrays.copyOf(array, array.length, arrayType); }
FixedStack implements IStack<T> { @Override public final T[] toArray(Class<T[]> arrayType) { Object[] array = new Object[size()]; for (int stackIndex = size() - 1, arrayIndex = 0; stackIndex > -1; stackIndex--, arrayIndex++) { array[arrayIndex] = stack[stackIndex]; } return Arrays.copyOf(array, array.length, arrayType); } }
FixedStack implements IStack<T> { @Override public final T[] toArray(Class<T[]> arrayType) { Object[] array = new Object[size()]; for (int stackIndex = size() - 1, arrayIndex = 0; stackIndex > -1; stackIndex--, arrayIndex++) { array[arrayIndex] = stack[stackIndex]; } return Arrays.copyOf(array, array.length, arrayType); } @SuppressWarnings("unchecked")  FixedStack(int size); }
FixedStack implements IStack<T> { @Override public final T[] toArray(Class<T[]> arrayType) { Object[] array = new Object[size()]; for (int stackIndex = size() - 1, arrayIndex = 0; stackIndex > -1; stackIndex--, arrayIndex++) { array[arrayIndex] = stack[stackIndex]; } return Arrays.copyOf(array, array.length, arrayType); } @SuppressWarnings("unchecked")  FixedStack(int size); @Override void push(T element); @Override T peek(); @Override T pop(); @Override int size(); @Override boolean isEmpty(); @Override void clear(); @Override final T[] toArray(Class<T[]> arrayType); }
FixedStack implements IStack<T> { @Override public final T[] toArray(Class<T[]> arrayType) { Object[] array = new Object[size()]; for (int stackIndex = size() - 1, arrayIndex = 0; stackIndex > -1; stackIndex--, arrayIndex++) { array[arrayIndex] = stack[stackIndex]; } return Arrays.copyOf(array, array.length, arrayType); } @SuppressWarnings("unchecked")  FixedStack(int size); @Override void push(T element); @Override T peek(); @Override T pop(); @Override int size(); @Override boolean isEmpty(); @Override void clear(); @Override final T[] toArray(Class<T[]> arrayType);  }