View Javadoc

1   package fr.ove.utils;
2   
3   import java.io.Serializable;
4   
5   /***
6   * A element of linked structure (queue, lists, etc..
7   * <P>
8   * Contains the element added in the structure and the reference to the previous
9   * and the next element in the structure.
10  *
11  * @author © 2000 DIRAT Laurent
12  * @version 1.0 28/06/2000
13  */
14  public class LinkedElement implements Serializable {
15      /***
16      * The element in the structure.
17      */
18      private Object element;
19      
20      /***
21      * The previous element in the structure.
22      */
23      private LinkedElement previous;
24      
25      /***
26      * The next element in the structure.
27      */
28      private LinkedElement next;
29      
30      /***
31      * The default contstructor
32      */
33      public LinkedElement() {
34          this(null);
35      }
36      
37      /***
38      * The contstructor
39      * @param element the element in the structure
40      */
41      public LinkedElement(Object element) {
42          this.element = element;
43          previous = null;
44          next = null;
45      }
46      
47      /***
48      * Sets the element
49      */
50      public void setElement(Object element) {
51          this.element = element;
52      }
53      
54      /***
55      * Returns the element
56      */
57      public Object getElement() {
58          return element;
59      }
60      
61      /***
62      * Sets the previous element of the instance
63      */
64      public void setPrevious(LinkedElement previous) {
65          this.previous = previous;
66      }
67      
68      /***
69      * Returns the previous element of the instance
70      */
71      public LinkedElement getPrevious() {
72          return previous;
73      }
74      
75      /***
76      * Sets the next element of the instance
77      */
78      public void setNext(LinkedElement next) {
79          this.next = next;
80      }
81      
82      /***
83      * Returns the next element of the instance
84      */
85      public LinkedElement getNext() {
86          return next;
87      }
88      
89      /***
90      * Removes the instance from the structure
91      */
92      public void remove() {
93          element = null;
94          
95          if (previous != null)
96              previous.next = next;
97              
98          if (next != null)
99              next.previous = previous;
100     }
101     
102     /***
103     * Returns a string representation of the element
104     */
105     public String toString() {
106         return element.toString();
107     }
108 }