1 18 package org.objectweb.speedo.usercache.lib; 19 20 import org.objectweb.speedo.usercache.api.UserCache; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 31 public class UserCacheImpl implements UserCache { 32 33 public final static int DEFAULT_SIZE = 50; 34 35 38 protected Map key2oid; 39 40 43 protected Map oid2key; 44 45 48 protected String name; 49 50 53 protected int id; 54 55 58 protected boolean active; 59 60 63 protected String [] fields; 64 65 70 public UserCacheImpl() { 71 this(DEFAULT_SIZE); 72 } 73 74 80 public UserCacheImpl(int size) { 81 key2oid = new HashMap (size); 82 oid2key = new HashMap (size); 83 } 84 85 public synchronized Object bind(Object key, Object oid) { 86 Object oldKey = oid2key.put(oid, key); 87 if (oldKey != null && !oldKey.equals(key)) { 88 key2oid.remove(oldKey); 90 } else { 91 key2oid.put(key, oid); 92 } 93 return oldKey; 94 } 95 96 public synchronized Object unbindFromKey(Object key) { 97 Object oldOID = key2oid.remove(key); 98 if (oldOID != null) { 99 oid2key.remove(oldOID); 100 } 101 return oldOID; 102 } 103 104 public synchronized Object unbindFromOID(Object oid) { 105 Object oldKey = oid2key.remove(oid); 106 if (oldKey != null) { 107 key2oid.remove(oldKey); 108 } 109 return oldKey; 110 } 111 112 public synchronized Object lookup(Object key) { 113 return key2oid.get(key); 114 } 115 116 public int getId() { 117 return id; 118 } 119 120 public void setId(int _id) { 121 this.id = _id; 122 } 123 public String [] getIndexFieldNames() { 124 return fields; 125 } 126 public void setIndexFieldNames(String [] fns) { 127 this.fields = fns; 128 } 129 public String getName() { 130 return name; 131 } 132 public void setName(String n) { 133 this.name = n; 134 } 135 public boolean isActive() { 136 return active; 137 } 138 public void setActive(boolean a) { 139 this.active = a; 140 } 141 } 142 | Popular Tags |