1 package com.fasterxml.jackson.databind.util; 2 3 /** 4 * Node of a forward-only linked list. 5 * 6 * @author tatu 7 */ 8 public final class LinkedNode<T> 9 { 10 private final T value; 11 12 private LinkedNode<T> next; 13 LinkedNode(T value, LinkedNode<T> next)14 public LinkedNode(T value, LinkedNode<T> next) 15 { 16 this.value = value; 17 this.next = next; 18 } 19 linkNext(LinkedNode<T> n)20 public void linkNext(LinkedNode<T> n) 21 { 22 if (next != null) { // sanity check 23 throw new IllegalStateException(); 24 } 25 next = n; 26 } 27 next()28 public LinkedNode<T> next() { return next; } 29 value()30 public T value() { return value; } 31 32 /** 33 * Convenience method that can be used to check if a linked list 34 * with given head node (which may be null to indicate empty list) 35 * contains given value 36 * 37 * @param <ST> Type argument that defines contents of the linked list parameter 38 * @param node Head node of the linked list 39 * @param value Value to look for 40 * @return True if linked list contains the value, false otherwise 41 */ contains(LinkedNode<ST> node, ST value)42 public static <ST> boolean contains(LinkedNode<ST> node, ST value) 43 { 44 while (node != null) { 45 if (node.value() == value) { 46 return true; 47 } 48 node = node.next(); 49 } 50 return false; 51 } 52 } 53