Skip to content

Commit 320b5de

Browse files
author
asri71
committed
Making changes into method as per Oracle specifications
1 parent c8ee96d commit 320b5de

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main/java/com/dataStructures/GeneralQueue.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.Iterator;
66
import java.util.LinkedList;
7+
import java.util.NoSuchElementException;
78

89
/**
910
* linkedList based implementation of queue.
@@ -24,18 +25,23 @@ public GeneralQueue() {
2425
public boolean add(T t) {
2526

2627
if(queue == null) {
27-
throw new NullPointerException();
28+
throw new IllegalStateException();
29+
}
30+
if(t == null){
31+
throw new NullPointerException();
2832
}
29-
3033
queue.add(t);
3134
return true;
3235
}
3336

3437
@Override
3538
public boolean remove(T t) {
36-
if(null == queue || queue.size() == 0){
39+
if(null == queue){
3740
throw new NullPointerException();
3841
}
42+
if(queue.isEmpty()) {
43+
throw new NoSuchElementException();
44+
}
3945
queue.remove(t);
4046
return true;
4147
}
@@ -65,7 +71,9 @@ public boolean offer(T t) {
6571
if(null == queue) {
6672
return false;
6773
}
68-
74+
if(t == null){
75+
throw new NullPointerException();
76+
}
6977
queue.add(t);
7078
return true;
7179
}
@@ -84,7 +92,7 @@ public T poll() {
8492
public T element() {
8593

8694
if(queue == null || queue.isEmpty()) {
87-
throw new NullPointerException();
95+
throw new NoSuchElementException();
8896
}
8997

9098
return queue.peekFirst();

0 commit comments

Comments
 (0)