@Test void peek() { FixedStack<String> stack = new FixedStack<>(2); Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, stack::peek); stack.push("1"); Assertions.assertEquals("1", stack.peek()); stack.push("2"); Assertions.assertEquals("2", stack.peek()); stack.pop(); Assertions.assertEquals("1", stack.peek()); }
@Override public T peek() { return stack[index - 1]; }
FixedStack implements IStack<T> { @Override public T peek() { return stack[index - 1]; } }
FixedStack implements IStack<T> { @Override public T peek() { return stack[index - 1]; } @SuppressWarnings("unchecked")  FixedStack(int size); }
FixedStack implements IStack<T> { @Override public T peek() { return stack[index - 1]; } @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 T peek() { return stack[index - 1]; } @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);  }