ICU-13517 Updated TimeZoneAdapter#equals implementation to return false if the given object is not a TimeZoneAdapter.

X-SVN-Rev: 41419
This commit is contained in:
Yoshito Umaoka 2018-05-20 23:53:41 +00:00
parent ab59a3896c
commit ca9ecef96e
2 changed files with 21 additions and 3 deletions

View File

@ -143,10 +143,14 @@ public class TimeZoneAdapter extends java.util.TimeZone {
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof TimeZoneAdapter) {
obj = ((TimeZoneAdapter) obj).zone;
if (this == obj) {
return true;
}
return zone.equals(obj);
if (obj instanceof TimeZoneAdapter) {
TimeZone anotherZone = ((TimeZoneAdapter) obj).zone;
return zone.equals(anotherZone);
}
return false;
}
/**

View File

@ -27,6 +27,7 @@ import org.junit.runners.JUnit4;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.impl.ICUData;
import com.ibm.icu.impl.TimeZoneAdapter;
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.util.BasicTimeZone;
import com.ibm.icu.util.Calendar;
@ -2308,6 +2309,19 @@ public class TimeZoneTest extends TestFmwk
data[2], id);
}
}
@Test
public void TestTimeZoneAdapterEquals() {
String idChicago = "America/Chicago";
TimeZone icuChicago = TimeZone.getTimeZone(idChicago);
TimeZone icuChicago2 = TimeZone.getTimeZone(idChicago);
java.util.TimeZone icuChicagoWrapped = TimeZoneAdapter.wrap(icuChicago);
java.util.TimeZone icuChicagoWrapped2 = TimeZoneAdapter.wrap(icuChicago2);
assertFalse("Compare TimeZone and TimeZoneAdapter", icuChicago.equals(icuChicagoWrapped));
assertFalse("Compare TimeZoneAdapter with TimeZone", icuChicagoWrapped.equals(icuChicago));
assertTrue("Compare two TimeZoneAdapters", icuChicagoWrapped.equals(icuChicagoWrapped2));
}
}
//eof