@Test public void equalsHashCode() { /* Empty objects. */ LocExtension a = new LocExtension(); LocExtension b = new LocExtension(); checkEquals(a, b); /* Tz. */ a.setTz("a1"); checkNotEquals(a, b); b.setTz("b1"); checkNotEquals(a, b); b.setTz("a1"); checkEquals(a, b); } }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, TZ, getTz()); }
LocExtension loc = new LocExtension(); loc.read(object.getJSONObject(LOC)); setLoc(loc);
@Test public void compareDifferentType() { TestUtils.compareSelfNullClass(new LocExtension()); }
@Override public void read(JSONObject object) { setTz(object.optString(TZ, null)); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Extensions that = (Extensions) o; if (metadata != null ? !metadata.equals(that.metadata) : that.metadata != null) return false; if (protocol != null ? !protocol.equals(that.protocol) : that.protocol != null) return false; if (user != null ? !user.equals(that.user) : that.user != null) return false; if (device != null ? !device.equals(that.device) : that.device != null) return false; if (os != null ? !os.equals(that.os) : that.os != null) return false; if (app != null ? !app.equals(that.app) : that.app != null) return false; if (net != null ? !net.equals(that.net) : that.net != null) return false; if (sdk != null ? !sdk.equals(that.sdk) : that.sdk != null) return false; return loc != null ? loc.equals(that.loc) : that.loc == null; }
@Override public int hashCode() { int result = metadata != null ? metadata.hashCode() : 0; result = 31 * result + (protocol != null ? protocol.hashCode() : 0); result = 31 * result + (user != null ? user.hashCode() : 0); result = 31 * result + (device != null ? device.hashCode() : 0); result = 31 * result + (os != null ? os.hashCode() : 0); result = 31 * result + (app != null ? app.hashCode() : 0); result = 31 * result + (net != null ? net.hashCode() : 0); result = 31 * result + (sdk != null ? sdk.hashCode() : 0); result = 31 * result + (loc != null ? loc.hashCode() : 0); return result; } }
getLoc().write(writer); writer.endObject();
ext.setLoc(new LocExtension()); a.setExt(ext); checkNotEquals(a, b);
dest.getExt().setLoc(new LocExtension()); String timezoneOffset = String.format(Locale.US, "%s%02d:%02d", device.getTimeZoneOffset() >= 0 ? "+" : "-", Math.abs(device.getTimeZoneOffset() / 60), Math.abs(device.getTimeZoneOffset() % 60)); dest.getExt().getLoc().setTz(timezoneOffset);
assertEquals("appcenter.android-1.5.0", commonSchemaLog.getExt().getSdk().getLibVer()); assertNotNull(commonSchemaLog.getExt().getLoc()); assertEquals(commonSchemaTimeZoneOffset, commonSchemaLog.getExt().getLoc().getTz()); assertEquals(Collections.singleton(transmissionTarget), commonSchemaLog.getTransmissionTargetTokens()); assertNotNull(commonSchemaLog.getExt().getDevice());
LocExtension loc = new LocExtension(); loc.setTz("+02:00"); a.setLoc(loc); checkNotEquals(a, b); b.setLoc(new LocExtension()); checkNotEquals(a, b); b.setLoc(a.getLoc());
log.getExt().setLoc(new LocExtension()); checkSerialization(serializer, log); log.getExt().getLoc().setTz("-08:00"); checkSerialization(serializer, log);