1 16 package org.apache.commons.collections; 17 18 import java.util.Map ; 19 20 32 public class DefaultMapEntry implements Map.Entry , KeyValue { 33 34 35 private Object key; 36 37 private Object value; 38 39 43 public DefaultMapEntry() { 44 super(); 45 } 46 47 54 public DefaultMapEntry(Map.Entry entry) { 55 super(); 56 this.key = entry.getKey(); 57 this.value = entry.getValue(); 58 } 59 60 67 public DefaultMapEntry(Object key, Object value) { 68 super(); 69 this.key = key; 70 this.value = value; 71 } 72 73 80 public Object getKey() { 81 return key; 82 } 83 84 91 public void setKey(Object key) { 92 this.key = key; 93 } 94 95 100 public Object getValue() { 101 return value; 102 } 103 104 112 public Object setValue(Object value) { 113 Object answer = this.value; 114 this.value = value; 115 return answer; 116 } 117 118 128 public boolean equals(Object obj) { 129 if (obj == this) { 130 return true; 131 } 132 if (obj instanceof Map.Entry == false) { 133 return false; 134 } 135 Map.Entry other = (Map.Entry ) obj; 136 return 137 (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && 138 (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); 139 } 140 141 148 public int hashCode() { 149 return (getKey() == null ? 0 : getKey().hashCode()) ^ 150 (getValue() == null ? 0 : getValue().hashCode()); 151 } 152 153 158 public String toString() { 159 return ""+getKey()+"="+getValue(); 160 } 161 162 } 163 | Popular Tags |