Skip to content

Commit

Permalink
Add JavaDoc for equals method
Browse files Browse the repository at this point in the history
Explain the conditions which imply equality for JsonObject and JsonArray.
In particular, point out that JsonObjects are considered equal only if
the members have the same order.

See #65
  • Loading branch information
ralfstx committed Jun 19, 2016
1 parent d34960d commit 0cda256
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,19 @@ public int hashCode() {
return values.hashCode();
}


/**
* Indicates whether a given object is "equal to" this JsonArray. An object is considered equal
* if it is also a <code>JsonArray</code> and both arrays contain the same list of values.
* <p>
* If two JsonArrays are equal, they will also produce the same JSON output.
* </p>
*
* @param object
* the object to be compared with this JsonArray
* @return <tt>true</tt> if the specified object is equal to this JsonArray, <code>false</code>
* otherwise
*/
@Override
public boolean equals(Object object) {
if (this == object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,18 +844,31 @@ public int hashCode() {
return result;
}

/**
* Indicates whether a given object is "equal to" this JsonObject. An object is considered equal
* if it is also a <code>JsonObject</code> and both objects contain the same members <em>in
* the same order</em>.
* <p>
* If two JsonObjects are equal, they will also produce the same JSON output.
* </p>
*
* @param object
* the object to be compared with this JsonObject
* @return <tt>true</tt> if the specified object is equal to this JsonObject, <code>false</code>
* otherwise
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (obj == null) {
if (object == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (getClass() != object.getClass()) {
return false;
}
Member other = (Member)obj;
Member other = (Member)object;
return name.equals(other.name) && value.equals(other.value);
}

Expand Down

0 comments on commit 0cda256

Please sign in to comment.