/** * 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 */ @Override 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 */ @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof DefaultKeyValue == false) { return false; } final DefaultKeyValue<?, ?> other = (DefaultKeyValue<?, ?>) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }
/** * Creates a Sort query based on the fields.<br/> * Key of the map is the field <b>False=Desc,True=asc</b> * for the field, Respect order of the keys * * @param fields Keys are fields, true if asc, false desc * @return Sorted Json string with the query. */ protected String createSortQuery(final List<DefaultKeyValue<String, Boolean>> fields) { StringBuilder builder = new StringBuilder("{"); Iterator<DefaultKeyValue<String, Boolean>> iter = fields.iterator(); while (iter.hasNext()) { DefaultKeyValue<String, Boolean> field = iter.next(); builder.append("\""); builder.append(field.getKey()); builder.append("\""); builder.append(":"); if (field.getValue()) { builder.append(1); } else { builder.append(-1); } if (iter.hasNext()) { builder.append(","); } } builder.append("}"); return builder.toString(); }