Making changes into method as per Oracle specifications

This commit is contained in:
asri71 2019-03-05 17:05:11 +05:30
parent c8ee96d9d5
commit 320b5de0fe

View File

@ -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<T> implements Queue<T> {
public boolean add(T t) {
if(queue == null) {
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<T> implements Queue<T> {
if(null == queue) {
return false;
}
if(t == null){
throw new NullPointerException();
}
queue.add(t);
return true;
}
@ -84,7 +92,7 @@ public class GeneralQueue<T> implements Queue<T> {
public T element() {
if(queue == null || queue.isEmpty()) {
throw new NullPointerException();
throw new NoSuchElementException();
}
return queue.peekFirst();