-
Notifications
You must be signed in to change notification settings - Fork 0
/
StackImpl.java
56 lines (48 loc) · 1.14 KB
/
StackImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* A Stack Implementation
*
* @author Laurent Mignot
*/
public class StackImpl extends AbstractStack {
public StackImpl (List list) {
super(list);
}
/**
* @see Stack#isEmpty()
*/
public boolean isEmpty () {
return this.internalList != null ? this.internalList.isEmpty() : true;
}
/**
* @see Stack#size()
*/
public int size () {
return this.internalList != null ? this.internalList.size() : 0;
}
/**
* @see Stack#push()
*/
public void push (Object item) {
if (this.internalList != null && item != null) {
this.internalList.add(item);
}
}
/**
* @see Stack#top()
*/
public ReturnObject top () {
if (this.isEmpty()) {
return new ReturnObjectImpl(ErrorMessage.EMPTY_STRUCTURE);
}
return this.internalList.get(this.size() - 1);
}
/**
* @see Stack#pop()
*/
public ReturnObject pop () {
if (this.isEmpty()) {
return new ReturnObjectImpl(ErrorMessage.EMPTY_STRUCTURE);
}
return this.internalList.remove(this.size() - 1);
}
}