/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}, * however subclasses may override this. * * @return a suitable hash code */ public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}, * however subclasses may override this. * * @return a suitable hash code */ public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Returns true if the compared object is also a <code>DefaultKeyValue</code>, * and its key and value are equal to this object's key and value. * * @param obj the object to compare to * @return true if equal key and value */ public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof DefaultKeyValue == false) { return false; } DefaultKeyValue other = (DefaultKeyValue) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Returns true if the compared object is also a <code>DefaultKeyValue</code>, * and its key and value are equal to this object's key and value. * * @param obj the object to compare to * @return true if equal key and value */ public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof DefaultKeyValue == false) { return false; } DefaultKeyValue other = (DefaultKeyValue) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }
public void testToMapEntry() { DefaultKeyValue kv = makeDefaultKeyValue(key, value); Map map = new HashMap(); map.put(kv.getKey(), kv.getValue()); Map.Entry entry = (Map.Entry) map.entrySet().iterator().next(); assertTrue(entry.equals(kv.toMapEntry())); assertTrue(entry.hashCode() == kv.hashCode()); }
/** * Subclasses should override this method to test their own constructors. */ public void testConstructors() { // 1. test default constructor DefaultKeyValue kv = new DefaultKeyValue(); assertTrue(kv.getKey() == null && kv.getValue() == null); // 2. test key-value constructor kv = new DefaultKeyValue(key, value); assertTrue(kv.getKey() == key && kv.getValue() == value); // 3. test copy constructor DefaultKeyValue kv2 = new DefaultKeyValue(kv); assertTrue(kv2.getKey() == key && kv2.getValue() == value); // test that the KVPs are independent kv.setKey(null); kv.setValue(null); assertTrue(kv2.getKey() == key && kv2.getValue() == value); // 4. test Map.Entry constructor Map map = new HashMap(); map.put(key, value); Map.Entry entry = (Map.Entry) map.entrySet().iterator().next(); kv = new DefaultKeyValue(entry); assertTrue(kv.getKey() == key && kv.getValue() == value); // test that the KVP is independent of the Map.Entry entry.setValue(null); assertTrue(kv.getValue() == value); }
public void testAccessorsAndMutators() { DefaultKeyValue kv = makeDefaultKeyValue(); kv.setKey(key); assertTrue(kv.getKey() == key); kv.setValue(value); assertTrue(kv.getValue() == value); // check that null doesn't do anything funny kv.setKey(null); assertTrue(kv.getKey() == null); kv.setValue(null); assertTrue(kv.getValue() == null); }
public void testSelfReferenceHandling() { // test that #setKey and #setValue do not permit // the KVP to contain itself (and thus cause infinite recursion // in #hashCode and #toString) DefaultKeyValue kv = makeDefaultKeyValue(); try { kv.setKey(kv); fail("Should throw an IllegalArgumentException"); } catch (IllegalArgumentException iae) { // expected to happen... // check that the KVP's state has not changed assertTrue(kv.getKey() == null && kv.getValue() == null); } try { kv.setValue(kv); fail("Should throw an IllegalArgumentException"); } catch (IllegalArgumentException iae) { // expected to happen... // check that the KVP's state has not changed assertTrue(kv.getKey() == null && kv.getValue() == null); } }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}, * however subclasses may override this. * * @return a suitable hash code */ public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}, * however subclasses may override this. * * @return a suitable hash code */ public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}, * however subclasses may override this. * * @return a suitable hash code */ public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}, * however subclasses may override this. * * @return a suitable hash code */ public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}, * however subclasses may override this. * * @return a suitable hash code */ public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Returns true if the compared object is also a <code>DefaultKeyValue</code>, * and its key and value are equal to this object's key and value. * * @param obj the object to compare to * @return true if equal key and value */ public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof DefaultKeyValue == false) { return false; } DefaultKeyValue other = (DefaultKeyValue) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Returns true if the compared object is also a <code>DefaultKeyValue</code>, * and its key and value are equal to this object's key and value. * * @param obj the object to compare to * @return true if equal key and value */ public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof DefaultKeyValue == false) { return false; } DefaultKeyValue other = (DefaultKeyValue) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Returns true if the compared object is also a <code>DefaultKeyValue</code>, * and its key and value are equal to this object's key and value. * * @param obj the object to compare to * @return true if equal key and value */ public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof DefaultKeyValue == false) { return false; } DefaultKeyValue other = (DefaultKeyValue) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Returns true if the compared object is also a <code>DefaultKeyValue</code>, * and its key and value are equal to this object's key and value. * * @param obj the object to compare to * @return true if equal key and value */ public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof DefaultKeyValue == false) { return false; } DefaultKeyValue other = (DefaultKeyValue) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Returns true if the compared object is also a <code>DefaultKeyValue</code>, * and its key and value are equal to this object's key and value. * * @param obj the object to compare to * @return true if equal key and value */ public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof DefaultKeyValue == false) { return false; } DefaultKeyValue other = (DefaultKeyValue) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }