From 320b5de0fee4c623e76635d0ba6fe31b00b67a50 Mon Sep 17 00:00:00 2001 From: asri71 Date: Tue, 5 Mar 2019 17:05:11 +0530 Subject: [PATCH] Making changes into method as per Oracle specifications --- .../java/com/dataStructures/GeneralQueue.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/dataStructures/GeneralQueue.java b/src/main/java/com/dataStructures/GeneralQueue.java index ebb92302..9098c71e 100644 --- a/src/main/java/com/dataStructures/GeneralQueue.java +++ b/src/main/java/com/dataStructures/GeneralQueue.java @@ -4,6 +4,7 @@ import src.main.java.com.types.Queue; import java.util.Iterator; import java.util.LinkedList; +import java.util.NoSuchElementException; /** * linkedList based implementation of queue. @@ -24,18 +25,23 @@ public class GeneralQueue implements Queue { public boolean add(T t) { if(queue == null) { - throw new NullPointerException(); + throw new IllegalStateException(); + } + if(t == null){ + throw new NullPointerException(); } - queue.add(t); return true; } @Override public boolean remove(T t) { - if(null == queue || queue.size() == 0){ + if(null == queue){ throw new NullPointerException(); } + if(queue.isEmpty()) { + throw new NoSuchElementException(); + } queue.remove(t); return true; } @@ -65,7 +71,9 @@ public class GeneralQueue implements Queue { if(null == queue) { return false; } - + if(t == null){ + throw new NullPointerException(); + } queue.add(t); return true; } @@ -84,7 +92,7 @@ public class GeneralQueue implements Queue { public T element() { if(queue == null || queue.isEmpty()) { - throw new NullPointerException(); + throw new NoSuchElementException(); } return queue.peekFirst();