Path: blob/master/test/jdk/java/util/Calendar/CalendarTestScripts/GregorianAdapter.java
41152 views
/*1* Copyright (c) 2007, 2018, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.GregorianCalendar;24import java.util.Locale;25import java.util.TimeZone;2627public class GregorianAdapter extends GregorianCalendar {28static final int ALL_FIELDS = (1 << FIELD_COUNT) - 1;2930public GregorianAdapter() {31super();32}3334public GregorianAdapter(TimeZone tz) {35super(tz);36}3738public GregorianAdapter(Locale loc) {39super(loc);40}4142public GregorianAdapter(TimeZone tz, Locale loc) {43super(tz, loc);44}4546public void computeTime() {47super.computeTime();48}4950public void computeFields() {51super.computeFields();52}5354public void complete() {55super.complete();56}5758StringBuffer msg = new StringBuffer();5960void initTest() {61msg = new StringBuffer();62}6364String getMessage() {65String s = msg.toString();66msg = new StringBuffer();67return " " + s;68}6970void setMessage(String msg) {71this.msg = new StringBuffer(msg);72}7374void appendMessage(String msg) {75this.msg.append(msg);76}7778boolean getStatus() {79return msg.length() == 0;80}8182int getSetStateFields() {83int mask = 0;84for (int i = 0; i < FIELD_COUNT; i++) {85if (isSet(i)) {86mask |= 1 << i;87}88}89return mask;90}9192int[] getFields() {93int[] fds = new int[fields.length];94System.arraycopy(fields, 0, fds, 0, fds.length);95return fds;96}9798boolean checkInternalDate(int year, int month, int dayOfMonth) {99initTest();100checkInternalField(YEAR, year);101checkInternalField(MONTH, month);102checkInternalField(DAY_OF_MONTH, dayOfMonth);103return getStatus();104}105106boolean checkInternalDate(int year, int month, int dayOfMonth, int dayOfWeek) {107initTest();108checkInternalField(YEAR, year);109checkInternalField(MONTH, month);110checkInternalField(DAY_OF_MONTH, dayOfMonth);111checkInternalField(DAY_OF_WEEK, dayOfWeek);112return getStatus();113}114115boolean checkInternalField(int field, int expectedValue) {116int val;117if ((val = internalGet(field)) != expectedValue) {118appendMessage("internalGet(" + CalendarAdapter.FIELD_NAMES[field] + "): got " + val +119", expected " + expectedValue + "; ");120return false;121}122return true;123}124}125126127