From 12d240414d738ab969720361a64fdc815613e2e8 Mon Sep 17 00:00:00 2001 From: Daher Daher <40135454+daher928@users.noreply.github.com> Date: Mon, 27 May 2019 13:39:33 +0300 Subject: [PATCH] Update GenericArrayListQueue.java Documentations added --- .../Queues/GenericArrayListQueue.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/DataStructures/Queues/GenericArrayListQueue.java b/DataStructures/Queues/GenericArrayListQueue.java index d287fdce..9c2f2658 100644 --- a/DataStructures/Queues/GenericArrayListQueue.java +++ b/DataStructures/Queues/GenericArrayListQueue.java @@ -2,29 +2,68 @@ package DataStructures.Queues; import java.util.ArrayList; +/** + * This class implements a GenericArrayListQueue. + *

+ * A GenericArrayListQueue data structure functions the same as any specific-typed queue. + * The GenericArrayListQueue holds elemets of types to-be-specified at runtime. + * The elements that are added first are the first to be removed (FIFO) + * New elements are added to the back/rear of the queue. + * + */ public class GenericArrayListQueue { + /** + * The generic ArrayList for the queue + * T is the generic element + */ ArrayList _queue = new ArrayList(); + /** + * Checks if the queue has elements (not empty) + * + * @return True if the queue has elements. False otherwise. + */ private boolean hasElements() { return !_queue.isEmpty(); } + /** + * Checks what's at the front of the queue + * + * @return If queue is not empty, element at the front of the queue. Otherwise, null + */ public T peek() { T result = null; if(this.hasElements()) { result = _queue.get(0); } return result; } + /** + * Inserts an element of type T to the queue. + * + * @param element of type T to be added + * @return True if the element was added successfully + */ public boolean add(T element) { return _queue.add(element); } + /** + * Retrieve what's at the front of the queue + * + * @return If queue is not empty, element retrieved. Otherwise, null + */ public T poll() { T result = null; if(this.hasElements()) { result = _queue.remove(0); } return result; } + /** + * Main method + * + * @param args Command line arguments + */ public static void main(String[] args) { GenericArrayListQueue queue = new GenericArrayListQueue(); System.out.println("Running...");