1 4 package com.nightlabs.ipanema.jdo.cache; 5 6 import java.util.Set ; 7 8 import org.apache.log4j.Logger; 9 10 import com.nightlabs.jdo.ObjectID; 11 12 15 public class Key 16 { 17 private String scope; 18 private Object objectID; 19 private Set fetchGroups; 20 21 31 public Key(String scope, Object objectID, Set fetchGroups) 32 { 33 this.scope = scope; 34 35 if (objectID == null) 36 throw new NullPointerException ("objectID"); 37 38 this.objectID = objectID; 39 if (!(objectID instanceof ObjectID)) { 40 Logger.getLogger(Key.class).warn( 41 "objectID (class " + objectID.getClass().getName() + ") does not implement " + ObjectID.class.getName() + "!"); 42 } 43 44 this.fetchGroups = fetchGroups; 45 } 46 47 private int _hashCode = 0; 48 49 52 public int hashCode() 53 { 54 if (_hashCode == 0) { 55 _hashCode = 56 (scope == null ? 0 : scope.hashCode()) ^ 57 (objectID == null ? 0 : objectID.hashCode()) ^ 58 (fetchGroups == null ? 0 : fetchGroups.hashCode()); 59 } 60 61 return _hashCode; 62 } 63 64 67 public boolean equals(Object obj) 68 { 69 if (obj == this) 70 return true; 71 72 if (obj.hashCode() != this.hashCode()) 73 return false; 74 75 if (!(obj instanceof Key)) 76 return false; 77 78 Key other = (Key)obj; 79 80 return 81 (this.scope == null ? other.scope == null : this.scope.equals(other.scope)) 82 && 83 (this.objectID == null ? other.objectID == null : this.objectID.equals(other.objectID)) 84 && 85 (this.fetchGroups == null ? other.fetchGroups == null : this.fetchGroups.equals(other.fetchGroups)); 86 } 87 88 private transient String thisString = null; 89 90 93 public String toString() 94 { 95 if (thisString == null) { 96 StringBuffer sb = new StringBuffer (); 97 sb.append(this.getClass().getName()); 98 sb.append('{'); 99 sb.append("scope="); 100 sb.append(scope); 101 sb.append(';'); 102 sb.append("objectID="); 103 sb.append(objectID); 104 sb.append(';'); 105 sb.append("fetchGroups="); 106 sb.append(fetchGroups); 107 sb.append('}'); 108 thisString = sb.toString(); 109 } 110 return thisString; 111 } 112 113 118 public Set getFetchGroups() 119 { 120 return fetchGroups; 121 } 122 125 public Object getObjectID() 126 { 127 return objectID; 128 } 129 132 public String getScope() 133 { 134 return scope; 135 } 136 } 137 | Popular Tags |