01: /**
02: * $RCSfile$
03: * $Revision: 42 $
04: * $Date: 2004-10-21 00:28:12 -0700 (Thu, 21 Oct 2004) $
05: *
06: * Copyright (C) 2004 Jive Software. All rights reserved.
07: *
08: * This software is published under the terms of the GNU Public License (GPL),
09: * a copy of which is included in this distribution.
10: */package org.jivesoftware.util;
11:
12: /**
13: * Doubly linked node in a LinkedList. Most LinkedList implementations keep the
14: * equivalent of this class private. We make it public so that references
15: * to each node in the list can be maintained externally.
16: * <p/>
17: * Exposing this class lets us make remove operations very fast. Remove is
18: * built into this class and only requires two reference reassignments. If
19: * remove existed in the main LinkedList class, a linear scan would have to
20: * be performed to find the correct node to delete.
21: * <p/>
22: * The linked list implementation was specifically written for the Jive
23: * cache system. While it can be used as a general purpose linked list, for
24: * most applications, it is more suitable to use the linked list that is part
25: * of the Java Collections package.
26: *
27: * @author Jive Software
28: * @see org.jivesoftware.util.LinkedList
29: */
30: public class LinkedListNode {
31:
32: public LinkedListNode previous;
33: public LinkedListNode next;
34: public Object object;
35:
36: /**
37: * This class is further customized for the CoolServlets cache system. It
38: * maintains a timestamp of when a Cacheable object was first added to
39: * cache. Timestamps are stored as long values and represent the number
40: * of milleseconds passed since January 1, 1970 00:00:00.000 GMT.<p>
41: * <p/>
42: * The creation timestamp is used in the case that the cache has a
43: * maximum lifetime set. In that case, when
44: * [current time] - [creation time] > [max lifetime], the object will be
45: * deleted from cache.
46: */
47: public long timestamp;
48:
49: /**
50: * Constructs a new linked list node.
51: *
52: * @param object the Object that the node represents.
53: * @param next a reference to the next LinkedListNode in the list.
54: * @param previous a reference to the previous LinkedListNode in the list.
55: */
56: public LinkedListNode(Object object, LinkedListNode next,
57: LinkedListNode previous) {
58: this .object = object;
59: this .next = next;
60: this .previous = previous;
61: }
62:
63: /**
64: * Removes this node from the linked list that it is a part of.
65: */
66: public void remove() {
67: previous.next = next;
68: next.previous = previous;
69: }
70:
71: /**
72: * Returns a String representation of the linked list node by calling the
73: * toString method of the node's object.
74: *
75: * @return a String representation of the LinkedListNode.
76: */
77: public String toString() {
78: return object == null ? "null" : object.toString();
79: }
80: }
|