55/**
66 * This class implements a GenericArrayListQueue.
77 *
8- * <p> A GenericArrayListQueue data structure functions the same as any specific-typed queue. The
9- * GenericArrayListQueue holds elemets of types to-be-specified at runtime. The elements that are
10- * added first are the first to be removed (FIFO) New elements are added to the back/rear of the
8+ * A GenericArrayListQueue data structure functions the same as any specific-typed queue. The
9+ * GenericArrayListQueue holds elements of types to-be-specified at runtime. The elements that are
10+ * added first are the first to be removed (FIFO). New elements are added to the back/rear of the
1111 * queue.
1212 */
1313public class GenericArrayListQueue <T > {
1414 /** The generic ArrayList for the queue T is the generic element */
15- ArrayList <T > _queue = new ArrayList <T >();
15+ ArrayList <T > _queue = new ArrayList <>();
1616
1717 /**
18- * Checks if the queue has elements (not empty)
18+ * Checks if the queue has elements (not empty).
1919 *
2020 * @return True if the queue has elements. False otherwise.
2121 */
@@ -24,7 +24,7 @@ private boolean hasElements() {
2424 }
2525
2626 /**
27- * Checks what's at the front of the queue
27+ * Checks what's at the front of the queue.
2828 *
2929 * @return If queue is not empty, element at the front of the queue. Otherwise, null
3030 */
@@ -51,7 +51,7 @@ public boolean add(T element) {
5151 *
5252 * @return If queue is not empty, element retrieved. Otherwise, null
5353 */
54- public T poll () {
54+ public T pull () {
5555 T result = null ;
5656 if (this .hasElements ()) {
5757 result = _queue .remove (0 );
@@ -65,19 +65,19 @@ public T poll() {
6565 * @param args Command line arguments
6666 */
6767 public static void main (String [] args ) {
68- GenericArrayListQueue <Integer > queue = new GenericArrayListQueue <Integer >();
68+ GenericArrayListQueue <Integer > queue = new GenericArrayListQueue <>();
6969 System .out .println ("Running..." );
7070 assert queue .peek () == null ;
71- assert queue .poll () == null ;
72- assert queue .add (1 ) == true ;
71+ assert queue .pull () == null ;
72+ assert queue .add (1 );
7373 assert queue .peek () == 1 ;
74- assert queue .add (2 ) == true ;
74+ assert queue .add (2 );
7575 assert queue .peek () == 1 ;
76- assert queue .poll () == 1 ;
76+ assert queue .pull () == 1 ;
7777 assert queue .peek () == 2 ;
78- assert queue .poll () == 2 ;
78+ assert queue .pull () == 2 ;
7979 assert queue .peek () == null ;
80- assert queue .poll () == null ;
80+ assert queue .pull () == null ;
8181 System .out .println ("Finished." );
8282 }
8383}
0 commit comments