1 22 package org.jboss.util.collection; 23 24 import java.io.Serializable ; 25 26 import org.jboss.util.NullArgumentException; 27 import org.jboss.util.Objects; 28 import org.jboss.util.HashCode; 29 import org.jboss.util.Strings; 30 31 37 public class CompoundKey 38 implements Serializable , Cloneable 39 { 40 41 private final Object elements[]; 42 43 48 public CompoundKey(final Object elements[]) { 49 if (elements == null) 50 throw new NullArgumentException("elements"); 51 52 this.elements = elements; 53 } 54 55 61 public CompoundKey(final Object a, final Object b) { 62 this(new Object [] { a, b }); 63 } 64 65 72 public CompoundKey(final Object a, final Object b, final Object c) { 73 this(new Object [] { a, b, c }); 74 } 75 76 82 public boolean equals(final Object obj) { 83 if (obj == this) return true; 84 85 if (obj != null && obj.getClass() == getClass()) { 86 CompoundKey key = (CompoundKey)obj; 87 88 return Objects.equals(key.elements, elements); 89 } 90 91 return false; 92 } 93 94 99 public int hashCode() { 100 return HashCode.generate(elements); 101 } 102 103 108 public String toString() { 109 return super.toString() + Strings.join(elements, "[", ",", "]"); 110 } 111 112 117 public Object clone() { 118 try { 119 return super.clone(); 120 } 121 catch (CloneNotSupportedException e) { 122 throw new InternalError (); 123 } 124 } 125 } 126 | Popular Tags |