/** * 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()); }
/** * 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 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()); }
/** * Make an instance of DefaultKeyValue with the default (null) key and value. * Subclasses should override this method to return a DefaultKeyValue * of the type being tested. */ protected DefaultKeyValue makeDefaultKeyValue() { return new DefaultKeyValue(null, null); }
@Override public List<KeyValue> getAllCommands() { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource(); return getCallsHandler().executeReadList("get_all_commands", (rs, rowNum) -> { DefaultKeyValue result = new DefaultKeyValue(); result.setKey(getGuidDefaultEmpty(rs, "command_id")); result.setValue(rs.getString("command_type")); return result; }, parameterSource); } }
/** * Make an instance of DefaultKeyValue with the specified key and value. * Subclasses should override this method to return a DefaultKeyValue * of the type being tested. */ protected DefaultKeyValue makeDefaultKeyValue(Object key, Object value) { return new DefaultKeyValue(key, value); }
/** * 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()); }
/** * Subclasses should override this method. * */ public void testConstructors() { // 1. test key-value constructor Map.Entry entry = new UnmodifiableMapEntry(key, value); assertSame(key, entry.getKey()); assertSame(value, entry.getValue()); // 2. test pair constructor KeyValue pair = new DefaultKeyValue(key, value); entry = new UnmodifiableMapEntry(pair); assertSame(key, entry.getKey()); assertSame(value, entry.getValue()); // 3. test copy constructor Map.Entry entry2 = new UnmodifiableMapEntry(entry); assertSame(key, entry2.getKey()); assertSame(value, entry2.getValue()); assertTrue(entry instanceof Unmodifiable); }
/** * 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 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); } }
/** * Subclasses should override this method. * */ public void testConstructors() { // 1. test key-value constructor Map.Entry entry = new DefaultMapEntry(key, value); assertSame(key, entry.getKey()); assertSame(value, entry.getValue()); // 2. test pair constructor KeyValue pair = new DefaultKeyValue(key, value); assertSame(key, pair.getKey()); assertSame(value, pair.getValue()); // 3. test copy constructor Map.Entry entry2 = new DefaultMapEntry(entry); assertSame(key, entry2.getKey()); assertSame(value, entry2.getValue()); // test that the objects are independent entry.setValue(null); assertSame(value, entry2.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())); }
new DefaultKeyValue("RED", "#FF0000"), new DefaultKeyValue("GREEN", "#00FF00"), new DefaultKeyValue("BLUE", "#0000FF") }); assertEquals(true, test.containsKey("RED"));
/** * 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()); }
public void putAll(Map mapToCopy) { modified = true; if (!localContexts.empty()) { ArrayStack entries = (ArrayStack)localContexts.peek(); for (Iterator keysIterator = mapToCopy.keySet().iterator(); keysIterator.hasNext();) { Object key = keysIterator.next(); entries.push(new DefaultKeyValue(key, mapToCopy.get(key))); } } singleValueMap.putAll(mapToCopy); multiValueMap.putAll(mapToCopy); }
/** * 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()); }
@Override public void onReceive(Task<Iterable<SearchResult>> e) { // TODO Auto-generated method stub try { System.out.println("RECEIVED NEW ITERATION: "); Iterable<SearchResult> results = e.get(); DefaultKeyValue keyValue = new DefaultKeyValue(e.getName(), results); appendResult(keyValue); /*for(SearchResult res : results ){ }*/ } catch (InterruptedException | ExecutionException e1) { // TODO Auto-generated catch block //e1.printStackTrace(); } buffer.append("Received Query: "+e.getName()); }
/** * 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()); }