1 24 package org.objectweb.speedo.usercache.lib; 25 26 32 public class UserCacheKey { 33 34 37 private Object [] elements; 38 39 public UserCacheKey(int size) { 40 elements = new Object [size]; 41 } 42 43 public UserCacheKey(Object [] elements) { 44 this.elements = elements; 45 } 46 47 public void setPart(int index, Object o) { 48 elements[index] = o; 49 } 50 51 55 public int hashCode() { 56 if (elements.length > 0 && elements[0] != null) { 57 return elements[0].hashCode(); 58 } else { 59 return elements.length; 60 } 61 } 62 63 67 public boolean equals(Object o) { 68 if (!(o instanceof UserCacheKey)) { 69 return false; 70 } 71 UserCacheKey uck = (UserCacheKey) o; 72 if (uck.elements.length != elements.length) { 73 return false; 74 } 75 for (int i = 0; i < elements.length; i++) { 76 if ((elements[i] == null && uck.elements[i] != null) 77 || (elements[i] != null && !elements[i].equals(uck.elements[i]))) { 78 return false; 79 } 80 } 81 return true; 82 } 83 84 85 } 86 | Popular Tags |