KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > cache > CacheCell


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.impl.cache;
25
26 import java.util.ArrayList JavaDoc;
27
28 public class CacheCell {
29
30     private CacheCell() {
31         instanceCounter++;
32     }
33
34     private void init(Object JavaDoc id, Object JavaDoc object) {
35         this.object = object;
36         this.id = id;
37     }
38
39     public Object JavaDoc getId() {
40         return id;
41     }
42
43     public void setObject(Object JavaDoc newObject) {
44         object = newObject;
45     }
46
47     public Object JavaDoc getObject() {
48         return object;
49     }
50
51     public void setPrecedingCell(CacheCell cell) {
52         precedingCell = cell;
53     }
54
55     public CacheCell getPrecedingCell() {
56         return precedingCell;
57     }
58
59     public void setNextCell(CacheCell cell) {
60         nextCell = cell;
61     }
62
63     public CacheCell getNextCell() {
64         return nextCell;
65     }
66
67     public void delink() {
68         if (nextCell != null) {
69             nextCell.setPrecedingCell(precedingCell);
70         }
71         if (precedingCell != null) {
72             precedingCell.setNextCell(nextCell);
73         }
74         nextCell = null;
75         precedingCell = null;
76         id = null;
77         object = null;
78         if (c.size() < 0) {
79             c.add(this);
80         }
81     }
82
83     public int hashCode() {
84         return id.hashCode();
85     }
86
87     public String JavaDoc toString() {
88         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
89         sb.append("CC(").append(id).append(",").append(object).append(")");
90         return sb.toString();
91     }
92
93     private CacheCell precedingCell;
94     private CacheCell nextCell;
95     private Object JavaDoc id;
96     private Object JavaDoc object;
97
98
99     public static CacheCell newInstance(Object JavaDoc id, Object JavaDoc object) {
100         CacheCell newObject;
101         if (c.isEmpty()) {
102             newObject = new CacheCell();
103         } else {
104             newObject = (CacheCell) c.remove(0);
105         }
106         newObject.init(id, object);
107         return newObject;
108     }
109
110     private static ArrayList JavaDoc c = new ArrayList JavaDoc();
111     public static int instanceCounter = 0;
112 }
Popular Tags