Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/util/calendar/zi/ZoneRec.java
38855 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425import java.io.BufferedReader;26import java.io.FileReader;27import java.io.FileNotFoundException;28import java.io.IOException;29import java.util.ArrayList;30import java.util.HashMap;31import java.util.HashSet;32import java.util.List;33import java.util.Map;34import java.util.Set;35import java.util.StringTokenizer;3637/**38* ZoneRec hold information of time zone corresponding to each text39* line of the "Zone" part.40*41* @since 1.442*/43class ZoneRec {44private int gmtOffset;45private String ruleName;46private int directSave;47private Rule ruleRef;48private String format;49private boolean hasUntil;50private int untilYear;51private Month untilMonth;52private RuleDay untilDay;53private Time untilTime;54private long untilInMillis;55private String line;5657/**58* @return the "UNTIL" value in milliseconds59*/60Time getUntilTime() {61return untilTime;62}6364/**65* @return the GMT offset value in milliseconds66*/67int getGmtOffset() {68return gmtOffset;69}7071/**72* @return the rule name to which this zone record refers73*/74String getRuleName() {75return ruleName;76}7778/**79* @return the amount of saving time directly defined in the80* "RULES/SAVE" field.81*/82int getDirectSave() {83return directSave;84}8586/**87* @return true if this zone record has a reference to a rule88*/89boolean hasRuleReference() {90return ruleRef != null;91}9293/**94* Returns the "FORMAT" field string of this zone record. This95* @return the "FORMAT" field96*/97String getFormat() {98return format;99}100101/**102* @return the year in the "UNTIL" field103*/104int getUntilYear() {105return untilYear;106}107108/**109* Returns the "UNTIL" field value in milliseconds from Janurary110* 1, 1970 0:00 GMT.111* @param currentSave the amount of daylight saving in112* milliseconds that is used to adjust wall-clock time.113* @return the milliseconds value of the "UNTIL" field114*/115long getUntilTime(int currentSave) {116if (untilTime.isWall()) {117return untilInMillis - currentSave;118}119return untilInMillis;120}121122/**123* Returns the "UNTIL" time in milliseconds without adjusting GMT124* offsets or daylight saving.125* @return local "UNTIL" time in milliseconds126*/127long getLocalUntilTime() {128return Time.getLocalTime(untilYear,129untilMonth,130untilDay,131untilTime.getTime());132}133134/**135* Returns the "UNTIL" time in milliseconds with adjusting GMT offsets and daylight saving.136* @return the "UNTIL" time after the adjustment137*/138long getLocalUntilTime(int save, int gmtOffset) {139return Time.getLocalTime(untilYear,140untilMonth,141untilDay,142save,143gmtOffset,144untilTime);145}146147/**148* @return the text line of this zone record149*/150String getLine() {151return line;152}153154/**155* Sets the specified text line to this zone record156*/157void setLine(String line) {158this.line = line;159}160161/**162* @return true if this zone record has the "UNTIL" field163*/164boolean hasUntil() {165return this.hasUntil;166}167168/**169* Adjusts the "UNTIL" time to GMT offset if this zone record has170* it. <code>untilTime</code> is not adjusted to daylight saving171* in this method.172*/173void adjustTime() {174if (!hasUntil()) {175return;176}177if (untilTime.isSTD() || untilTime.isWall()) {178// adjust to gmt offset only here. adjust to real179// wall-clock time when tracking rules180untilInMillis -= gmtOffset;181}182}183184/**185* @return the reference to the Rule object186*/187Rule getRuleRef() {188return ruleRef;189}190191/**192* Resolves the reference to a Rule and adjusts its "UNTIL" time193* to GMT offset.194*/195void resolve(Zoneinfo zi) {196if (ruleName != null && (!"-".equals(ruleName))) {197ruleRef = zi.getRule(ruleName);198}199adjustTime();200}201202/**203* Parses a Zone text line that is described by a StringTokenizer.204* @param tokens represents tokens of a Zone text line205* @return the zone record produced by parsing the text206*/207static ZoneRec parse(StringTokenizer tokens) {208ZoneRec rec = new ZoneRec();209try {210rec.gmtOffset = (int) Time.parse(tokens.nextToken()).getTime();211String token = tokens.nextToken();212char c = token.charAt(0);213if (c >= '0' && c <= '9') {214rec.directSave = (int) Time.parse(token).getTime();215} else {216rec.ruleName = token;217}218rec.format = tokens.nextToken();219if (tokens.hasMoreTokens()) {220rec.hasUntil = true;221rec.untilYear = Integer.parseInt(tokens.nextToken());222if (tokens.hasMoreTokens()) {223rec.untilMonth = Month.parse(tokens.nextToken());224} else {225rec.untilMonth = Month.JANUARY;226}227if (tokens.hasMoreTokens()) {228rec.untilDay = RuleDay.parse(tokens.nextToken());229} else {230rec.untilDay = new RuleDay(1);231}232if (tokens.hasMoreTokens()) {233rec.untilTime = Time.parse(tokens.nextToken());234} else {235rec.untilTime = Time.parse("0:00");236}237rec.untilInMillis = rec.getLocalUntilTime();238}239} catch (Exception e) {240// TODO: error reporting241e.printStackTrace();242}243return rec;244}245246private static void panic(String msg) {247Main.panic(msg);248}249}250251252