1 /*
2 * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
3309
3310 /**
3311 * Creates and returns a copy of this object.
3312 *
3313 * @return a copy of this object.
3314 */
3315 @Override
3316 public Object clone()
3317 {
3318 try {
3319 Calendar other = (Calendar) super.clone();
3320
3321 other.fields = new int[FIELD_COUNT];
3322 other.isSet = new boolean[FIELD_COUNT];
3323 other.stamp = new int[FIELD_COUNT];
3324 for (int i = 0; i < FIELD_COUNT; i++) {
3325 other.fields[i] = fields[i];
3326 other.stamp[i] = stamp[i];
3327 other.isSet[i] = isSet[i];
3328 }
3329 other.zone = (TimeZone) zone.clone();
3330 return other;
3331 }
3332 catch (CloneNotSupportedException e) {
3333 // this shouldn't happen, since we are Cloneable
3334 throw new InternalError(e);
3335 }
3336 }
3337
3338 private static final String[] FIELD_NAME = {
3339 "ERA", "YEAR", "MONTH", "WEEK_OF_YEAR", "WEEK_OF_MONTH", "DAY_OF_MONTH",
3340 "DAY_OF_YEAR", "DAY_OF_WEEK", "DAY_OF_WEEK_IN_MONTH", "AM_PM", "HOUR",
3341 "HOUR_OF_DAY", "MINUTE", "SECOND", "MILLISECOND", "ZONE_OFFSET",
3342 "DST_OFFSET"
3343 };
3344
3345 /**
3346 * Returns the name of the specified calendar field.
3347 *
3348 * @param field the calendar field
3349 * @return the calendar field name
|
1 /*
2 * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
3309
3310 /**
3311 * Creates and returns a copy of this object.
3312 *
3313 * @return a copy of this object.
3314 */
3315 @Override
3316 public Object clone()
3317 {
3318 try {
3319 Calendar other = (Calendar) super.clone();
3320
3321 other.fields = new int[FIELD_COUNT];
3322 other.isSet = new boolean[FIELD_COUNT];
3323 other.stamp = new int[FIELD_COUNT];
3324 for (int i = 0; i < FIELD_COUNT; i++) {
3325 other.fields[i] = fields[i];
3326 other.stamp[i] = stamp[i];
3327 other.isSet[i] = isSet[i];
3328 }
3329 if (!sharedZone) {
3330 other.zone = (TimeZone) zone.clone();
3331 }
3332 return other;
3333 }
3334 catch (CloneNotSupportedException e) {
3335 // this shouldn't happen, since we are Cloneable
3336 throw new InternalError(e);
3337 }
3338 }
3339
3340 private static final String[] FIELD_NAME = {
3341 "ERA", "YEAR", "MONTH", "WEEK_OF_YEAR", "WEEK_OF_MONTH", "DAY_OF_MONTH",
3342 "DAY_OF_YEAR", "DAY_OF_WEEK", "DAY_OF_WEEK_IN_MONTH", "AM_PM", "HOUR",
3343 "HOUR_OF_DAY", "MINUTE", "SECOND", "MILLISECOND", "ZONE_OFFSET",
3344 "DST_OFFSET"
3345 };
3346
3347 /**
3348 * Returns the name of the specified calendar field.
3349 *
3350 * @param field the calendar field
3351 * @return the calendar field name
|