Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit320b5de

Browse files
author
asri71
committed
Making changes into method as per Oracle specifications
1 parentc8ee96d commit320b5de

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
importjava.util.Iterator;
66
importjava.util.LinkedList;
7+
importjava.util.NoSuchElementException;
78

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

2627
if(queue ==null) {
27-
thrownewNullPointerException();
28+
thrownewIllegalStateException();
29+
}
30+
if(t ==null){
31+
thrownewNullPointerException();
2832
}
29-
3033
queue.add(t);
3134
returntrue;
3235
}
3336

3437
@Override
3538
publicbooleanremove(Tt) {
36-
if(null ==queue ||queue.size() ==0){
39+
if(null ==queue){
3740
thrownewNullPointerException();
3841
}
42+
if(queue.isEmpty()) {
43+
thrownewNoSuchElementException();
44+
}
3945
queue.remove(t);
4046
returntrue;
4147
}
@@ -65,7 +71,9 @@ public boolean offer(T t) {
6571
if(null ==queue) {
6672
returnfalse;
6773
}
68-
74+
if(t ==null){
75+
thrownewNullPointerException();
76+
}
6977
queue.add(t);
7078
returntrue;
7179
}
@@ -84,7 +92,7 @@ public T poll() {
8492
publicTelement() {
8593

8694
if(queue ==null ||queue.isEmpty()) {
87-
thrownewNullPointerException();
95+
thrownewNoSuchElementException();
8896
}
8997

9098
returnqueue.peekFirst();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp