forked from erasmuss22/Music-Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoubleListnode.java
112 lines (101 loc) · 2.69 KB
/
DoubleListnode.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* Generic doubly linked list node. It serves as the basic building block for
* storing data in doubly linked lists, but is not visible outside of the linked
* list implementation. <strong>Do not modify this file in any way!</strong>
*
* @author Ben Liblit
* @param <E>
* the type of data to be stored in each node
* @see <a href="../../../../../../readings/Linked-Lists/#double">Doubly linked
* lists</a>
*/
public final class DoubleListnode<E> {
/**
* the data value stored in this node
*/
private E data;
/**
* the next node after this one, or {@code null} if there is no following
* node
*/
private DoubleListnode<E> next;
/**
* the previous node before this one, or {@code null} if there is no
* preceding node
*/
private DoubleListnode<E> prev;
/**
* constructs a new list node and links it to its neighbors
*
* @param prev
* the node before this one
* @param data
* the data to be stored in this node
* @param next
* the node after this one
*/
public DoubleListnode(final DoubleListnode<E> prev, final E data, final DoubleListnode<E> next) {
this.data = data;
this.next = next;
this.prev = prev;
}
/**
* constructs a new list node with no connections to neighbors. The node's
* {@link #next} and {@link #prev} fields are set to {@code null}.
*
* @param data
* the data to be stored in this node
*/
public DoubleListnode(final E data) {
this(null, data, null);
}
/**
* @return the current data
*/
public E getData() {
return data;
}
/**
* @return the current next node
*/
public DoubleListnode<E> getNext() {
return next;
}
/**
* @return the current previous node
*/
public DoubleListnode<E> getPrev() {
return prev;
}
/**
* @param data
* the new data
*/
public void setData(final E data) {
this.data = data;
}
/**
* @param next
* the new next node
*/
public void setNext(final DoubleListnode<E> next) {
this.next = next;
}
/**
* @param prev
* the new previous node
*/
public void setPrev(final DoubleListnode<E> prev) {
this.prev = prev;
}
/**
* Returns a string representation of this node's data, or "(null)" if this
* node's data is {@code null}.
*
* @return the node's data as a string
*/
@Override
public String toString() {
return data == null ? "(null)" : data.toString();
}
}