1 46 package groovy.util; 47 48 import java.util.Map ; 49 50 import org.codehaus.groovy.runtime.InvokerHelper; 51 52 59 public class MapEntry implements Map.Entry { 60 61 private Object key; 62 private Object value; 63 64 public MapEntry(Object key, Object value) { 65 this.key = key; 66 this.value = value; 67 } 68 69 public boolean equals(Object that) { 70 if (that instanceof MapEntry) { 71 return equals((MapEntry) that); 72 } 73 return false; 74 } 75 76 public boolean equals(MapEntry that) { 77 return InvokerHelper.compareEqual(this.key, that.key) && InvokerHelper.compareEqual(this.value, that.value); 78 } 79 80 public int hashCode() { 81 return hash(key) ^ hash(value); 82 } 83 84 public String toString() { 85 return "" + key + ":" + value; 86 } 87 88 public Object getKey() { 89 return key; 90 } 91 92 public void setKey(Object key) { 93 this.key = key; 94 } 95 96 public Object getValue() { 97 return value; 98 } 99 100 public Object setValue(Object value) { 101 this.value = value; 102 return value; 103 } 104 105 108 protected int hash(Object object) { 109 return (object == null) ? 0xbabe : object.hashCode(); 110 } 111 112 } 113 | Popular Tags |