]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/impl/TimeZoneAdapter.java
Added flags.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / impl / TimeZoneAdapter.java
1 /*
2  **********************************************************************
3  * Copyright (c) 2003-2010, International Business Machines
4  * Corporation and others.  All Rights Reserved.
5  **********************************************************************
6  * Author: Alan Liu
7  * Created: October 2 2003
8  * Since: ICU 2.8
9  **********************************************************************
10  */
11
12 package com.ibm.icu.impl;
13 import java.util.Date;
14
15 import com.ibm.icu.util.TimeZone;
16
17 /**
18  * <code>TimeZoneAdapter</code> wraps a com.ibm.icu.util.TimeZone
19  * subclass and inherits from java.util.TimeZone.
20  * Without this class, we would need to 'port' java.util.Date to
21  * com.ibm.icu.util as well, so that Date could interoperate properly
22  * with the com.ibm.icu.util TimeZone and Calendar classes.  With this
23  * class, we can use java.util.Date together with com.ibm.icu.util
24  * classes.
25  *
26  * @see com.ibm.icu.util.TimeZone#setDefault
27  * @author Alan Liu
28  * @since ICU 2.8
29  */
30 public class TimeZoneAdapter extends java.util.TimeZone {
31  
32     // Generated by serialver from JDK 1.4.1_01
33     static final long serialVersionUID = -2040072218820018557L;
34     
35     /**
36      * The contained com.ibm.icu.util.TimeZone object.  Must not be null.
37      * We delegate all methods to this object.
38      */
39     private TimeZone zone;
40     
41     /**
42      * Given a java.util.TimeZone, wrap it in the appropriate adapter
43      * subclass of com.ibm.icu.util.TimeZone and return the adapter.
44      */
45     public static java.util.TimeZone wrap(com.ibm.icu.util.TimeZone tz) {
46         return new TimeZoneAdapter(tz);
47     }
48
49     /**
50      * Return the java.util.TimeZone wrapped by this object.
51      */
52     public com.ibm.icu.util.TimeZone unwrap() {
53         return zone;
54     }
55
56     /**
57      * Constructs an adapter for a com.ibm.icu.util.TimeZone object.
58      */
59     public TimeZoneAdapter(TimeZone zone) {
60         this.zone = zone;
61         super.setID(zone.getID());
62     }
63
64     /**
65      * TimeZone API; calls through to wrapped time zone.
66      */
67     public void setID(String ID) {
68         super.setID(ID);
69         zone.setID(ID);
70     }    
71
72     /**
73      * TimeZone API; calls through to wrapped time zone.
74      */
75     public boolean hasSameRules(java.util.TimeZone other) {
76         return other instanceof TimeZoneAdapter &&
77             zone.hasSameRules(((TimeZoneAdapter)other).zone);
78     }
79
80     /**
81      * TimeZone API; calls through to wrapped time zone.
82      */
83     public int getOffset(int era, int year, int month, int day, int dayOfWeek,
84                          int millis) {
85         return zone.getOffset(era, year, month, day, dayOfWeek, millis);
86     }
87
88     /**
89      * TimeZone API; calls through to wrapped time zone.
90      */
91     public int getRawOffset() {
92         return zone.getRawOffset();
93     }
94
95     /**
96      * TimeZone API; calls through to wrapped time zone.
97      */
98     public void setRawOffset(int offsetMillis) {
99         zone.setRawOffset(offsetMillis);
100     }
101
102     /**
103      * TimeZone API; calls through to wrapped time zone.
104      */
105     public boolean useDaylightTime() {
106         return zone.useDaylightTime();
107     }
108
109     /**
110      * TimeZone API; calls through to wrapped time zone.
111      */
112     public boolean inDaylightTime(Date date) {
113         return zone.inDaylightTime(date);
114     }
115
116     /**
117      * Boilerplate API; calls through to wrapped object.
118      */
119     public Object clone() {
120         return new TimeZoneAdapter((TimeZone)zone.clone());
121     }
122
123     /**
124      * Boilerplate API; calls through to wrapped object.
125      */
126     public synchronized int hashCode() {
127         return zone.hashCode();
128     }
129
130     /**
131      * Boilerplate API; calls through to wrapped object.
132      */
133     public boolean equals(Object obj) {
134         if (obj instanceof TimeZoneAdapter) {
135             obj = ((TimeZoneAdapter) obj).zone;
136         }
137         return zone.equals(obj);
138     }
139
140     /**
141      * Returns a string representation of this object.
142      * @return  a string representation of this object.
143      */
144     public String toString() {
145         return "TimeZoneAdapter: " + zone.toString();
146     }
147 }