File tree Expand file tree Collapse file tree
src/main/java/com/dataStructures Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55import java .util .Iterator ;
66import 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 ();
You can’t perform that action at this time.
0 commit comments