src/share/classes/java/text/CalendarBuilder.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 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


  74         field[MAX_FIELD + index] = value;
  75         if (index > maxFieldIndex && index < FIELD_COUNT) {
  76             maxFieldIndex = index;
  77         }
  78         return this;
  79     }
  80 
  81     CalendarBuilder addYear(int value) {
  82         field[MAX_FIELD + YEAR] += value;
  83         field[MAX_FIELD + WEEK_YEAR] += value;
  84         return this;
  85     }
  86 
  87     boolean isSet(int index) {
  88         if (index == ISO_DAY_OF_WEEK) {
  89             index = DAY_OF_WEEK;
  90         }
  91         return field[index] > UNSET;
  92     }
  93 









  94     Calendar establish(Calendar cal) {
  95         boolean weekDate = isSet(WEEK_YEAR)
  96                             && field[WEEK_YEAR] > field[YEAR];
  97         if (weekDate && !cal.isWeekDateSupported()) {
  98             // Use YEAR instead
  99             if (!isSet(YEAR)) {
 100                 set(YEAR, field[MAX_FIELD + WEEK_YEAR]);
 101             }
 102             weekDate = false;
 103         }
 104 
 105         cal.clear();
 106         // Set the fields from the min stamp to the max stamp so that
 107         // the field resolution works in the Calendar.
 108         for (int stamp = MINIMUM_USER_STAMP; stamp < nextStamp; stamp++) {
 109             for (int index = 0; index <= maxFieldIndex; index++) {
 110                 if (field[index] == stamp) {
 111                     cal.set(index, field[MAX_FIELD + index]);
 112                     break;
 113                 }


   1 /*
   2  * Copyright (c) 2010, 2013, 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


  74         field[MAX_FIELD + index] = value;
  75         if (index > maxFieldIndex && index < FIELD_COUNT) {
  76             maxFieldIndex = index;
  77         }
  78         return this;
  79     }
  80 
  81     CalendarBuilder addYear(int value) {
  82         field[MAX_FIELD + YEAR] += value;
  83         field[MAX_FIELD + WEEK_YEAR] += value;
  84         return this;
  85     }
  86 
  87     boolean isSet(int index) {
  88         if (index == ISO_DAY_OF_WEEK) {
  89             index = DAY_OF_WEEK;
  90         }
  91         return field[index] > UNSET;
  92     }
  93 
  94     CalendarBuilder clear(int index) {
  95         if (index == ISO_DAY_OF_WEEK) {
  96             index = DAY_OF_WEEK;
  97         }
  98         field[index] = UNSET;
  99         field[MAX_FIELD + index] = 0;
 100         return this;
 101     }
 102 
 103     Calendar establish(Calendar cal) {
 104         boolean weekDate = isSet(WEEK_YEAR)
 105                             && field[WEEK_YEAR] > field[YEAR];
 106         if (weekDate && !cal.isWeekDateSupported()) {
 107             // Use YEAR instead
 108             if (!isSet(YEAR)) {
 109                 set(YEAR, field[MAX_FIELD + WEEK_YEAR]);
 110             }
 111             weekDate = false;
 112         }
 113 
 114         cal.clear();
 115         // Set the fields from the min stamp to the max stamp so that
 116         // the field resolution works in the Calendar.
 117         for (int stamp = MINIMUM_USER_STAMP; stamp < nextStamp; stamp++) {
 118             for (int index = 0; index <= maxFieldIndex; index++) {
 119                 if (field[index] == stamp) {
 120                     cal.set(index, field[MAX_FIELD + index]);
 121                     break;
 122                 }