KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > util > LinkedListNode


1 /**
2  * $RCSfile: LinkedListNode.java,v $
3  * $Revision: 1.2 $
4  * $Date: 2004/10/21 07:28:12 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.util;
13
14 /**
15  * Doubly linked node in a LinkedList. Most LinkedList implementations keep the
16  * equivalent of this class private. We make it public so that references
17  * to each node in the list can be maintained externally.
18  * <p/>
19  * Exposing this class lets us make remove operations very fast. Remove is
20  * built into this class and only requires two reference reassignments. If
21  * remove existed in the main LinkedList class, a linear scan would have to
22  * be performed to find the correct node to delete.
23  * <p/>
24  * The linked list implementation was specifically written for the Jive
25  * cache system. While it can be used as a general purpose linked list, for
26  * most applications, it is more suitable to use the linked list that is part
27  * of the Java Collections package.
28  *
29  * @author Jive Software
30  * @see org.jivesoftware.util.LinkedList
31  */

32 public class LinkedListNode {
33
34     public LinkedListNode previous;
35     public LinkedListNode next;
36     public Object JavaDoc object;
37
38     /**
39      * This class is further customized for the CoolServlets cache system. It
40      * maintains a timestamp of when a Cacheable object was first added to
41      * cache. Timestamps are stored as long values and represent the number
42      * of milleseconds passed since January 1, 1970 00:00:00.000 GMT.<p>
43      * <p/>
44      * The creation timestamp is used in the case that the cache has a
45      * maximum lifetime set. In that case, when
46      * [current time] - [creation time] > [max lifetime], the object will be
47      * deleted from cache.
48      */

49     public long timestamp;
50
51     /**
52      * Constructs a new linked list node.
53      *
54      * @param object the Object that the node represents.
55      * @param next a reference to the next LinkedListNode in the list.
56      * @param previous a reference to the previous LinkedListNode in the list.
57      */

58     public LinkedListNode(Object JavaDoc object, LinkedListNode next,
59                           LinkedListNode previous) {
60         this.object = object;
61         this.next = next;
62         this.previous = previous;
63     }
64
65     /**
66      * Removes this node from the linked list that it is a part of.
67      */

68     public void remove() {
69         previous.next = next;
70         next.previous = previous;
71     }
72
73     /**
74      * Returns a String representation of the linked list node by calling the
75      * toString method of the node's object.
76      *
77      * @return a String representation of the LinkedListNode.
78      */

79     public String JavaDoc toString() {
80         return object == null ? "null" : object.toString();
81     }
82 }
83
Popular Tags