Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.perveev.container.node;
- import java.util.Objects;
- /**
- * Class, implementing the double linked list node with generic stored data type
- * <p>
- *
- * @author Sanlovty
- * @version 1.1
- * @since 1.0
- */
- public class Node<T> {
- /**
- * Stored data
- */
- public T data;
- /**
- * Pointer to the previous Node
- */
- public Node<T> previous;
- /**
- * Pointer to the next Node
- */
- public Node<T> next;
- /**
- * Creates an instance of Node with the specified data.
- *
- * @param data The data stored inside of Node.
- */
- public Node(T data) {
- this.data = data;
- previous = next = null;
- }
- /**
- * Creates an instance of Node with the specified data, next and previous nodes (pointers to)
- *
- * @param data The data stored inside of Node.
- * @param next The pointer to the next Node.
- * @param previous The pointer to the previous Node.
- */
- public Node(T data, Node<T> next, Node<T> previous) {
- this.data = data;
- this.previous = previous;
- this.next = next;
- }
- /**
- * Overriding of equals method from Object class to let correctly check equality
- *
- * @param obj Object, we are trying to compare with
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (obj.getClass() != this.getClass()) {
- return false;
- }
- final Node<?> other = (Node<?>) obj;
- return Objects.equals(this.data, other.data);
- }
- /**
- * Overriding of hashCode method from Object class because we override equals and we need to follow the rules Object.hashCode()
- *
- * @return hash of instance
- */
- @Override
- public int hashCode() {
- return 53 * 3 + (this.data != null ? this.data.hashCode() : 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment