1 24 package org.objectweb.jalisto.se.impl.cache; 25 26 import java.util.ArrayList ; 27 28 public class CacheCell { 29 30 private CacheCell() { 31 instanceCounter++; 32 } 33 34 private void init(Object id, Object object) { 35 this.object = object; 36 this.id = id; 37 } 38 39 public Object getId() { 40 return id; 41 } 42 43 public void setObject(Object newObject) { 44 object = newObject; 45 } 46 47 public Object 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 toString() { 88 StringBuffer sb = new StringBuffer (); 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 id; 96 private Object object; 97 98 99 public static CacheCell newInstance(Object id, Object 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 c = new ArrayList (); 111 public static int instanceCounter = 0; 112 } | Popular Tags |