1 16 package org.apache.commons.collections.keyvalue; 17 18 import java.util.Map ; 19 20 import org.apache.commons.collections.KeyValue; 21 22 36 public class DefaultKeyValue extends AbstractKeyValue { 37 38 41 public DefaultKeyValue() { 42 super(null, null); 43 } 44 45 51 public DefaultKeyValue(final Object key, final Object value) { 52 super(key, value); 53 } 54 55 61 public DefaultKeyValue(final KeyValue pair) { 62 super(pair.getKey(), pair.getValue()); 63 } 64 65 71 public DefaultKeyValue(final Map.Entry entry) { 72 super(entry.getKey(), entry.getValue()); 73 } 74 75 83 public Object setKey(final Object key) { 84 if (key == this) { 85 throw new IllegalArgumentException ("DefaultKeyValue may not contain itself as a key."); 86 } 87 88 final Object old = this.key; 89 this.key = key; 90 return old; 91 } 92 93 100 public Object setValue(final Object value) { 101 if (value == this) { 102 throw new IllegalArgumentException ("DefaultKeyValue may not contain itself as a value."); 103 } 104 105 final Object old = this.value; 106 this.value = value; 107 return old; 108 } 109 110 116 public Map.Entry toMapEntry() { 117 return new DefaultMapEntry(this); 118 } 119 120 130 public boolean equals(final Object obj) { 131 if (obj == this) { 132 return true; 133 } 134 if (obj instanceof DefaultKeyValue == false) { 135 return false; 136 } 137 138 DefaultKeyValue other = (DefaultKeyValue) obj; 139 return 140 (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && 141 (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); 142 } 143 144 152 public int hashCode() { 153 return (getKey() == null ? 0 : getKey().hashCode()) ^ 154 (getValue() == null ? 0 : getValue().hashCode()); 155 } 156 157 } 158 | Popular Tags |