ICU-2966 move TimeZone.zone down into JDKTimeZone
X-SVN-Rev: 13290
This commit is contained in:
parent
b0fd935f44
commit
d22c4776cc
@ -10,6 +10,7 @@
|
||||
*/
|
||||
package com.ibm.icu.impl;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
import com.ibm.icu.util.SimpleTimeZone;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -27,16 +28,50 @@ import java.util.Date;
|
||||
*/
|
||||
public class JDKTimeZone extends TimeZone {
|
||||
|
||||
/**
|
||||
* The java.util.TimeZone wrapped by this object. Must not be null.
|
||||
*/
|
||||
java.util.TimeZone zone;
|
||||
|
||||
/**
|
||||
* Given a java.util.TimeZone, wrap it in the appropriate adapter
|
||||
* subclass of com.ibm.icu.util.TimeZone and return the adapter.
|
||||
*/
|
||||
public static TimeZone wrap(java.util.TimeZone tz) {
|
||||
if (tz instanceof TimeZoneAdapter) {
|
||||
return ((TimeZoneAdapter) tz).unwrap();
|
||||
}
|
||||
if (tz instanceof java.util.SimpleTimeZone) {
|
||||
return new SimpleTimeZone((java.util.SimpleTimeZone) tz);
|
||||
}
|
||||
return new JDKTimeZone(tz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the java.util.TimeZone wrapped by this object.
|
||||
*/
|
||||
public java.util.TimeZone unwrap() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a JDKTimeZone given a java.util.TimeZone reference
|
||||
* which must not be null.
|
||||
* @param tz the time zone to wrap
|
||||
*/
|
||||
public JDKTimeZone(java.util.TimeZone tz) {
|
||||
super(tz);
|
||||
if (tz == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
protected JDKTimeZone(java.util.TimeZone tz) {
|
||||
zone = tz;
|
||||
super.setID(zone.getID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time zone ID. This does not change any other data in
|
||||
* the time zone object.
|
||||
* @param ID the new time zone ID.
|
||||
*/
|
||||
public void setID(String ID) {
|
||||
super.setID(ID);
|
||||
zone.setID(ID);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,7 +79,7 @@ public class JDKTimeZone extends TimeZone {
|
||||
*/
|
||||
public int getOffset(int era, int year, int month, int day,
|
||||
int dayOfWeek, int milliseconds) {
|
||||
return getJDKZone().getOffset(era, year, month, day,
|
||||
return unwrap().getOffset(era, year, month, day,
|
||||
dayOfWeek, milliseconds);
|
||||
}
|
||||
|
||||
@ -52,35 +87,55 @@ public class JDKTimeZone extends TimeZone {
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
public void setRawOffset(int offsetMillis) {
|
||||
getJDKZone().setRawOffset(offsetMillis);
|
||||
unwrap().setRawOffset(offsetMillis);
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
public int getRawOffset() {
|
||||
return getJDKZone().getRawOffset();
|
||||
return unwrap().getRawOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
public boolean useDaylightTime() {
|
||||
return getJDKZone().useDaylightTime();
|
||||
return unwrap().useDaylightTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
public boolean inDaylightTime(Date date) {
|
||||
return getJDKZone().inDaylightTime(date);
|
||||
return unwrap().inDaylightTime(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeZone API.
|
||||
*/
|
||||
public boolean hasSameRules(TimeZone other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
if (other instanceof JDKTimeZone) {
|
||||
return zone.hasSameRules(((JDKTimeZone) other).zone);
|
||||
}
|
||||
return super.hasSameRules(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Boilerplate API; calls through to wrapped object.
|
||||
*/
|
||||
public Object clone() {
|
||||
return new JDKTimeZone((java.util.TimeZone)zone.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Boilerplate API; calls through to wrapped object.
|
||||
*/
|
||||
public synchronized int hashCode() {
|
||||
return getJDKZone().hashCode();
|
||||
return unwrap().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +144,7 @@ public class JDKTimeZone extends TimeZone {
|
||||
public boolean equals(Object obj) {
|
||||
try {
|
||||
return obj != null &&
|
||||
getJDKZone().equals(((JDKTimeZone) obj).getJDKZone());
|
||||
unwrap().equals(((JDKTimeZone) obj).unwrap());
|
||||
} catch (ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
@ -100,7 +155,7 @@ public class JDKTimeZone extends TimeZone {
|
||||
* @return a string representation of this object.
|
||||
*/
|
||||
public String toString() {
|
||||
return "JDKTimeZone: " + getJDKZone().toString();
|
||||
return "JDKTimeZone: " + unwrap().toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,20 +31,35 @@ import java.util.Date;
|
||||
* @since ICU 2.8
|
||||
*/
|
||||
public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
|
||||
|
||||
/**
|
||||
* The contained com.ibm.icu.util.TimeZone object.
|
||||
* The contained com.ibm.icu.util.TimeZone object. Must not be null.
|
||||
* We delegate all methods to this object.
|
||||
*/
|
||||
private TimeZone zone;
|
||||
|
||||
/**
|
||||
* Given a java.util.TimeZone, wrap it in the appropriate adapter
|
||||
* subclass of com.ibm.icu.util.TimeZone and return the adapter.
|
||||
*/
|
||||
public static java.util.TimeZone wrap(com.ibm.icu.util.TimeZone tz) {
|
||||
if (tz instanceof JDKTimeZone) {
|
||||
return ((JDKTimeZone) tz).unwrap();
|
||||
}
|
||||
return new TimeZoneAdapter(tz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the java.util.TimeZone wrapped by this object.
|
||||
*/
|
||||
public com.ibm.icu.util.TimeZone unwrap() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an adapter for a com.ibm.icu.util.TimeZone object.
|
||||
*/
|
||||
public TimeZoneAdapter(TimeZone zone) {
|
||||
if (zone instanceof JDKTimeZone) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
private TimeZoneAdapter(TimeZone zone) {
|
||||
this.zone = zone;
|
||||
super.setID(zone.getID());
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public SimpleTimeZone(int rawOffset, String ID) {
|
||||
super(new java.util.SimpleTimeZone(rawOffset, ID));
|
||||
this(new java.util.SimpleTimeZone(rawOffset, ID));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,7 +100,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
public SimpleTimeZone(int rawOffset, String ID,
|
||||
int startMonth, int startDay, int startDayOfWeek, int startTime,
|
||||
int endMonth, int endDay, int endDayOfWeek, int endTime) {
|
||||
super(new java.util.SimpleTimeZone(rawOffset, ID, startMonth, startDay,
|
||||
this(new java.util.SimpleTimeZone(rawOffset, ID, startMonth, startDay,
|
||||
startDayOfWeek, startTime, endMonth,
|
||||
endDay, endDayOfWeek, endTime));
|
||||
}
|
||||
@ -117,7 +117,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
int startMonth, int startDay, int startDayOfWeek, int startTime,
|
||||
int endMonth, int endDay, int endDayOfWeek, int endTime,
|
||||
int dstSavings) {
|
||||
super(new java.util.SimpleTimeZone(rawOffset, ID, startMonth, startDay,
|
||||
this(new java.util.SimpleTimeZone(rawOffset, ID, startMonth, startDay,
|
||||
startDayOfWeek, startTime, endMonth,
|
||||
endDay, endDayOfWeek, endTime, dstSavings));
|
||||
}
|
||||
@ -129,7 +129,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public void setStartYear(int year) {
|
||||
getJDKSTZ().setStartYear(year);
|
||||
unwrapSTZ().setStartYear(year);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,7 +155,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
*/
|
||||
public void setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek,
|
||||
int time) {
|
||||
getJDKSTZ().setStartRule(month, dayOfWeekInMonth, dayOfWeek, time);
|
||||
unwrapSTZ().setStartRule(month, dayOfWeekInMonth, dayOfWeek, time);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,7 +171,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public void setStartRule(int month, int dayOfMonth, int time) {
|
||||
getJDKSTZ().setStartRule(month, dayOfMonth, time);
|
||||
unwrapSTZ().setStartRule(month, dayOfMonth, time);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,7 +192,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public void setStartRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after) {
|
||||
getJDKSTZ().setStartRule(month, dayOfMonth, dayOfWeek, time, after);
|
||||
unwrapSTZ().setStartRule(month, dayOfMonth, dayOfWeek, time, after);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,7 +217,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
*/
|
||||
public void setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek,
|
||||
int time) {
|
||||
getJDKSTZ().setEndRule(month, dayOfWeekInMonth, dayOfWeek, time);
|
||||
unwrapSTZ().setEndRule(month, dayOfWeekInMonth, dayOfWeek, time);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,7 +233,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public void setEndRule(int month, int dayOfMonth, int time) {
|
||||
getJDKSTZ().setEndRule(month, dayOfMonth, time);
|
||||
unwrapSTZ().setEndRule(month, dayOfMonth, time);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,7 +254,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public void setEndRule(int month, int dayOfMonth, int dayOfWeek, int time, boolean after) {
|
||||
getJDKSTZ().setEndRule(month, dayOfMonth, dayOfWeek, time, after);
|
||||
unwrapSTZ().setEndRule(month, dayOfMonth, dayOfWeek, time, after);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -265,7 +265,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public void setDSTSavings(int millisSavedDuringDST) {
|
||||
getJDKSTZ().setDSTSavings(millisSavedDuringDST);
|
||||
unwrapSTZ().setDSTSavings(millisSavedDuringDST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,22 +276,24 @@ public class SimpleTimeZone extends JDKTimeZone {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public int getDSTSavings() {
|
||||
return getJDKSTZ().getDSTSavings();
|
||||
return unwrapSTZ().getDSTSavings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a SimpleTimeZone that wraps the given
|
||||
* java.util.SimpleTimeZone.
|
||||
* java.util.SimpleTimeZone. Do not call; use the TimeZone
|
||||
* API.
|
||||
* @internal
|
||||
*/
|
||||
SimpleTimeZone(java.util.SimpleTimeZone tz) {
|
||||
public SimpleTimeZone(java.util.SimpleTimeZone tz) {
|
||||
super(tz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the java.util.SimpleTimeZone that this class wraps.
|
||||
*/
|
||||
java.util.SimpleTimeZone getJDKSTZ() {
|
||||
return (java.util.SimpleTimeZone) getJDKZone();
|
||||
java.util.SimpleTimeZone unwrapSTZ() {
|
||||
return (java.util.SimpleTimeZone) unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,9 +151,6 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.ID = ID;
|
||||
if (zone != null) {
|
||||
zone.setID(ID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -260,32 +257,6 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
||||
// Format a date in January. We use the value 10*ONE_DAY == Jan 11 1970
|
||||
// 0:00 GMT.
|
||||
return format.format(new Date(864000000L));
|
||||
|
||||
// Alternate implementation that uses the underlying JDK's display
|
||||
// name data. Alan
|
||||
//
|
||||
// // Use the wrapped zone, if there is one. Otherwise create a
|
||||
// // new SimpleTimeZone as a stand-in for this zone; the
|
||||
// // stand-in will have no DST, or DST during January, but the
|
||||
// // same ID and offset, and hence the same display name. We
|
||||
// // don't cache these because they're small and cheap to
|
||||
// // create.
|
||||
// java.util.TimeZone tz;
|
||||
// if (zone != null) {
|
||||
// tz = zone;
|
||||
// } else if (daylight && useDaylightTime()) {
|
||||
// int savings = 3600000; // one hour
|
||||
// try {
|
||||
// savings = ((SimpleTimeZone) this).getDSTSavings();
|
||||
// } catch (ClassCastException e) {}
|
||||
// tz = new java.util.SimpleTimeZone(getRawOffset(), getID(),
|
||||
// Calendar.JANUARY, 1, 0, 0,
|
||||
// Calendar.FEBRUARY, 1, 0, 0,
|
||||
// savings);
|
||||
// } else {
|
||||
// tz = new java.util.SimpleTimeZone(getRawOffset(), getID());
|
||||
// }
|
||||
// return tz.getDisplayName(daylight, style, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -319,7 +290,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public static synchronized TimeZone getTimeZone(String ID) {
|
||||
return wrap(java.util.TimeZone.getTimeZone(ID));
|
||||
return JDKTimeZone.wrap(java.util.TimeZone.getTimeZone(ID));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -413,7 +384,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
||||
*/
|
||||
public static synchronized TimeZone getDefault() {
|
||||
if (defaultZone == null) {
|
||||
defaultZone = wrap(java.util.TimeZone.getDefault());
|
||||
defaultZone = JDKTimeZone.wrap(java.util.TimeZone.getDefault());
|
||||
}
|
||||
return (TimeZone) defaultZone.clone();
|
||||
}
|
||||
@ -432,7 +403,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
||||
// can interoperate with com.ibm.icu.util classes.
|
||||
java.util.TimeZone jdkZone = null;
|
||||
if (tz != null) {
|
||||
jdkZone = (tz.zone != null) ? tz.zone : new TimeZoneAdapter(tz);
|
||||
jdkZone = TimeZoneAdapter.wrap(tz);
|
||||
}
|
||||
java.util.TimeZone.setDefault(jdkZone);
|
||||
}
|
||||
@ -447,13 +418,8 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public boolean hasSameRules(TimeZone other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
if (zone != null && other.zone != null) {
|
||||
return zone.hasSameRules(other.zone);
|
||||
}
|
||||
return getRawOffset() == other.getRawOffset() &&
|
||||
return other != null &&
|
||||
getRawOffset() == other.getRawOffset() &&
|
||||
useDaylightTime() == other.useDaylightTime();
|
||||
}
|
||||
|
||||
@ -462,9 +428,6 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public Object clone() {
|
||||
if (zone != null) {
|
||||
return wrap((java.util.TimeZone) zone.clone());
|
||||
}
|
||||
try {
|
||||
TimeZone other = (TimeZone) super.clone();
|
||||
other.ID = ID;
|
||||
@ -490,40 +453,6 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
||||
* The default time zone, or null if not set.
|
||||
*/
|
||||
private static TimeZone defaultZone = null;
|
||||
|
||||
/**
|
||||
* The java.util.TimeZone that is being wrapped by this object,
|
||||
* or null if none.
|
||||
*/
|
||||
private java.util.TimeZone zone;
|
||||
|
||||
/**
|
||||
* Returns the wrapped java.util.TimeZone.
|
||||
*/
|
||||
protected final java.util.TimeZone getJDKZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a java.util.TimeZone, wrap it in the appropriate adapter
|
||||
* subclass of com.ibm.icu.util.TimeZone and return the adapter.
|
||||
*/
|
||||
static TimeZone wrap(java.util.TimeZone tz) {
|
||||
// This is faster than instanceof
|
||||
try {
|
||||
return new SimpleTimeZone((java.util.SimpleTimeZone) tz);
|
||||
} catch (ClassCastException e) {
|
||||
return new JDKTimeZone(tz);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a time zone that wraps the given java.util.TimeZone.
|
||||
*/
|
||||
protected TimeZone(java.util.TimeZone tz) {
|
||||
zone = tz;
|
||||
ID = tz.getID();
|
||||
}
|
||||
}
|
||||
|
||||
//eof
|
||||
|
Loading…
Reference in New Issue
Block a user