KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nemesis > forum > util > LinkedListNode


1 /*
2  * NEMESIS-FORUM.
3  * Copyright (C) 2002 David Laurent(lithium2@free.fr). All rights reserved.
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
6  *
7  * Copyright (C) 2001 Yasna.com. All rights reserved.
8  *
9  * Copyright (C) 2000 CoolServlets.com. All rights reserved.
10  *
11  * NEMESIS-FORUM. is free software; you can redistribute it and/or
12  * modify it under the terms of the Apache Software License, Version 1.1,
13  * or (at your option) any later version.
14  *
15  * NEMESIS-FORUM core framework, NEMESIS-FORUM backoffice, NEMESIS-FORUM frontoffice
16  * application are parts of NEMESIS-FORUM and are distributed under
17  * same terms of licence.
18  *
19  *
20  * NEMESIS-FORUM includes software developed by the Apache Software Foundation (http://www.apache.org/)
21  * and software developed by CoolServlets.com (http://www.coolservlets.com).
22  * and software developed by Yasna.com (http://www.yasna.com).
23  *
24  */

25
26
27 package org.nemesis.forum.util;
28
29 /**
30  * Doubly linked node in a LinkedList. Most LinkedList implementations keep the
31  * equivalent of this class private. We make it public so that references
32  * to each node in the list can be maintained externally.
33  *
34  * Exposing this class lets us make remove operations very fast. Remove is
35  * built into this class and only requires to reference reassignments. If
36  * remove was built into the main LinkedList class, a linear scan would have to
37  * be performed to find the correct node to delete.
38  *
39  * The linked list implementation was specifically written for the CoolServlets
40  * cache system. While it can be used as a general purpose linked list, for
41  * most applications, it is more suitable to use the linked list that is part
42  * of the Java Collections package.
43  *
44  * @see LinkedList
45  */

46 public class LinkedListNode {
47
48     public LinkedListNode previous;
49     public LinkedListNode next;
50     public Object JavaDoc object;
51
52     /**
53      * This class is further customized for the CoolServlets cache system. It
54      * maintains a timestamp of when a Cacheable object was first added to
55      * cache. Timestamps are stored as long values and represent the number
56      * of milleseconds passed since January 1, 1970 00:00:00.000 GMT.<p>
57      *
58      * The creation timestamp is used in the case that the cache has a
59      * maximum lifetime set. In that case, when
60      * [current time] - [creation time] > [max lifetime], the object will be
61      * deleted from cache.
62      */

63     public long timestamp;
64
65     /**
66      * Constructs a new linked list node.
67      *
68      * @param object the Object that the node represents.
69      * @param next a reference to the next LinkedListNode in the list.
70      * @param previous a reference to the previous LinkedListNode in the list.
71      */

72     public LinkedListNode(Object JavaDoc object, LinkedListNode next,
73             LinkedListNode previous)
74     {
75         this.object = object;
76         this.next = next;
77         this.previous = previous;
78     }
79
80     /**
81      * Removes this node from the linked list that it is a part of.
82      */

83     public void remove() {
84         previous.next = next;
85         next.previous = previous;
86     }
87     /**
88      * Returns a String representation of the linked list node by calling the
89      * toString method of the node's object.
90      *
91      * @return a String representation of the LinkedListNode.
92      */

93     public String JavaDoc toString() {
94         return object.toString();
95     }
96 }
97
Popular Tags