@Test public void equalsTest() { JsonHash jsonHash1 = new JsonHash(); JsonHash jsonHash2 = new JsonHash(); assertThat(jsonHash1.equals(jsonHash2), is(true)); jsonHash1.put("str", "hoge"); assertThat(jsonHash1.equals(jsonHash2), is(false)); jsonHash2.put("str", "hoge"); assertThat(jsonHash1.equals(jsonHash2), is(true)); }
@Override public boolean equals(Object obj) { if (obj instanceof JsonHash) { JsonHash hash = (JsonHash) obj; int size = size(); if (size != hash.size()) { return false; } Set<String> set = keySet(); for (String key : set) { if (!hash.containsKey(key)) { return false; } else if (!stateMap.get(key).equals(hash.stateMap.get(key))) { return false; } else if (get(key) == null && hash.get(key) != null) { return false; } else if (get(key) == null && hash.get(key) == null) { continue; } else if (!get(key).equals(hash.get(key))) { return false; } } return true; } else { return false; } }
JsonHash extends LinkedHashMap<String, Object> { @Override public boolean equals(Object obj) { if (obj instanceof JsonHash) { JsonHash hash = (JsonHash) obj; int size = size(); if (size != hash.size()) { return false; } Set<String> set = keySet(); for (String key : set) { if (!hash.containsKey(key)) { return false; } else if (!stateMap.get(key).equals(hash.stateMap.get(key))) { return false; } else if (get(key) == null && hash.get(key) != null) { return false; } else if (get(key) == null && hash.get(key) == null) { continue; } else if (!get(key).equals(hash.get(key))) { return false; } } return true; } else { return false; } } }
JsonHash extends LinkedHashMap<String, Object> { @Override public boolean equals(Object obj) { if (obj instanceof JsonHash) { JsonHash hash = (JsonHash) obj; int size = size(); if (size != hash.size()) { return false; } Set<String> set = keySet(); for (String key : set) { if (!hash.containsKey(key)) { return false; } else if (!stateMap.get(key).equals(hash.stateMap.get(key))) { return false; } else if (get(key) == null && hash.get(key) != null) { return false; } else if (get(key) == null && hash.get(key) == null) { continue; } else if (!get(key).equals(hash.get(key))) { return false; } } return true; } else { return false; } }  }
JsonHash extends LinkedHashMap<String, Object> { @Override public boolean equals(Object obj) { if (obj instanceof JsonHash) { JsonHash hash = (JsonHash) obj; int size = size(); if (size != hash.size()) { return false; } Set<String> set = keySet(); for (String key : set) { if (!hash.containsKey(key)) { return false; } else if (!stateMap.get(key).equals(hash.stateMap.get(key))) { return false; } else if (get(key) == null && hash.get(key) != null) { return false; } else if (get(key) == null && hash.get(key) == null) { continue; } else if (!get(key).equals(hash.get(key))) { return false; } } return true; } else { return false; } }  static JsonHash fromString(String json); static JsonHash fromParser(JsonPullParser parser); void toJson(Writer writer); @Override void clear(); @Override Object clone(); @Deprecated State getState(String key); Type getType(String key); Boolean getBooleanOrNull(String key); String getStringOrNull(String key); Long getLongOrNull(String key); Double getDoubleOrNull(String key); JsonHash getJsonHashOrNull(String key); JsonArray getJsonArrayOrNull(String key); @Deprecated Object put(String key, Object value, State state); Object put(String key, Object value, Type type); Object put(String key, String value); Object put(String key, Boolean value); Object put(String key, Double value); Object put(String key, Float value); Object put(String key, Byte value); Object put(String key, Short value); Object put(String key, Integer value); Object put(String key, Long value); Object put(String key, JsonArray value); Object put(String key, JsonHash value); @Override Object put(String key, Object value); @Override void putAll(Map<? extends String, ? extends Object> map); @Override Object remove(Object obj); @Override boolean equals(Object obj); @Override String toString(); }
JsonHash extends LinkedHashMap<String, Object> { @Override public boolean equals(Object obj) { if (obj instanceof JsonHash) { JsonHash hash = (JsonHash) obj; int size = size(); if (size != hash.size()) { return false; } Set<String> set = keySet(); for (String key : set) { if (!hash.containsKey(key)) { return false; } else if (!stateMap.get(key).equals(hash.stateMap.get(key))) { return false; } else if (get(key) == null && hash.get(key) != null) { return false; } else if (get(key) == null && hash.get(key) == null) { continue; } else if (!get(key).equals(hash.get(key))) { return false; } } return true; } else { return false; } }  static JsonHash fromString(String json); static JsonHash fromParser(JsonPullParser parser); void toJson(Writer writer); @Override void clear(); @Override Object clone(); @Deprecated State getState(String key); Type getType(String key); Boolean getBooleanOrNull(String key); String getStringOrNull(String key); Long getLongOrNull(String key); Double getDoubleOrNull(String key); JsonHash getJsonHashOrNull(String key); JsonArray getJsonArrayOrNull(String key); @Deprecated Object put(String key, Object value, State state); Object put(String key, Object value, Type type); Object put(String key, String value); Object put(String key, Boolean value); Object put(String key, Double value); Object put(String key, Float value); Object put(String key, Byte value); Object put(String key, Short value); Object put(String key, Integer value); Object put(String key, Long value); Object put(String key, JsonArray value); Object put(String key, JsonHash value); @Override Object put(String key, Object value); @Override void putAll(Map<? extends String, ? extends Object> map); @Override Object remove(Object obj); @Override boolean equals(Object obj); @Override String toString();  }