mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
Add generic Node classes (#2782)
Co-authored-by: Andrii Siriak <siryaka@gmail.com>
This commit is contained in:
committed by
GitHub
parent
78f770683a
commit
7f3eb1b6dc
55
DevUtils/Nodes/SimpleNode.java
Normal file
55
DevUtils/Nodes/SimpleNode.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package DevUtils.Nodes;
|
||||
|
||||
/**
|
||||
* Simple Node implementation that holds
|
||||
* a reference to the next Node.
|
||||
*
|
||||
* @param <E> The type of the data held in the Node.
|
||||
*
|
||||
* @author <a href="https://github.com/aitorfi">aitorfi</a>
|
||||
*/
|
||||
public class SimpleNode<E> extends Node<E> {
|
||||
/** Reference to the next Node. */
|
||||
private SimpleNode<E> nextNode;
|
||||
|
||||
/** Empty contructor. */
|
||||
public SimpleNode() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Nodes' data.
|
||||
*
|
||||
* @param data Value to which data will be initialized.
|
||||
* @see Node#Node(Object)
|
||||
*/
|
||||
public SimpleNode(E data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Nodes' data and next node reference.
|
||||
*
|
||||
* @param data Value to which data will be initialized.
|
||||
* @param nextNode Value to which the next node reference will be set.
|
||||
*/
|
||||
public SimpleNode(E data, SimpleNode<E> nextNode) {
|
||||
super(data);
|
||||
this.nextNode = nextNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if there is a next node, otherwise false.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return (nextNode != null);
|
||||
}
|
||||
|
||||
public SimpleNode<E> getNextNode() {
|
||||
return nextNode;
|
||||
}
|
||||
|
||||
public void setNextNode(SimpleNode<E> nextNode) {
|
||||
this.nextNode = nextNode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user