JSON :
"ABCD": [
{
"xyz": 3,
"abc": 4,
"date": {
"start": 1462341600000,
"stop": 1462513680000
}
}
...similar sub parts
]
Datatype defined : I have tried to define a corresponding datatype for the json as follows [Ignoring other field as of now] :
public class Test {
TestDate testDate = new TestDate();
private Long start = testDate.startTime;
private Long stop = testDate.expiryTime;
public class TestDate {
private Long startTime;
private Long expiryTime;
// getter and setter implemented here
}
}
Now, what I am confused with is how to override the equals
method to suffice the check for start and stop parameters of the JSON.
Case 1 : Comparing the variables start
and stop
declared inside the Test class and assigned with TestDate corresponding parameters. As in :
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Test test = (Test) o;
// Below is what I am concerned about
if (stop != null ? !stop.equals(test.stop) : test.stop != null) return false;
if (start != null ? !start.equals(test.start) : test.start != null) return false;
}
OR
Case 2 : Simply use the object testDate
created within the Test class for comparison. As in :
if (testDate != null ? !testDate.equals(test.testDate) : test.testDate != null) return false;
Doubts :
- Does the Case 2 even suffice the Case 1?
- If not, whats the difference?
- If yes, which one of these is a better practice?
Looking for more stats to why use Case 2 over Case 1 in terms on code complexities and re-usability.