< prev index next >

src/java.base/share/classes/java/util/Calendar.java

Print this page




1155          * @see Calendar#set(int, int)
1156          */
1157         public Builder set(int field, int value) {
1158             // Note: WEEK_YEAR can't be set with this method.
1159             if (field < 0 || field >= FIELD_COUNT) {
1160                 throw new IllegalArgumentException("field is invalid");
1161             }
1162             if (isInstantSet()) {
1163                 throw new IllegalStateException("instant has been set");
1164             }
1165             allocateFields();
1166             internalSet(field, value);
1167             return this;
1168         }
1169 
1170         /**
1171          * Sets field parameters to their values given by
1172          * {@code fieldValuePairs} that are pairs of a field and its value.
1173          * For example,
1174          * <pre>
1175          *   setFeilds(Calendar.YEAR, 2013,
1176          *             Calendar.MONTH, Calendar.DECEMBER,
1177          *             Calendar.DAY_OF_MONTH, 23);</pre>
1178          * is equivalent to the sequence of the following
1179          * {@link #set(int, int) set} calls:
1180          * <pre>
1181          *   set(Calendar.YEAR, 2013)
1182          *   .set(Calendar.MONTH, Calendar.DECEMBER)
1183          *   .set(Calendar.DAY_OF_MONTH, 23);</pre>
1184          *
1185          * @param fieldValuePairs field-value pairs
1186          * @return this {@code Calendar.Builder}
1187          * @throws NullPointerException if {@code fieldValuePairs} is {@code null}
1188          * @throws IllegalArgumentException if any of fields are invalid,
1189          *             or if {@code fieldValuePairs.length} is an odd number.
1190          * @throws IllegalStateException    if the instant value has been set,
1191          *             or if fields have been set too many (approximately
1192          *             {@link Integer#MAX_VALUE}) times.
1193          */
1194         public Builder setFields(int... fieldValuePairs) {
1195             int len = fieldValuePairs.length;


1281          *
1282          * @param weekYear   the week year
1283          * @param weekOfYear the week number based on {@code weekYear}
1284          * @param dayOfWeek  the day of week value: one of the constants
1285          *     for the {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} field:
1286          *     {@link Calendar#SUNDAY SUNDAY}, ..., {@link Calendar#SATURDAY SATURDAY}.
1287          * @return this {@code Calendar.Builder}
1288          * @see Calendar#setWeekDate(int, int, int)
1289          * @see Calendar#isWeekDateSupported()
1290          */
1291         public Builder setWeekDate(int weekYear, int weekOfYear, int dayOfWeek) {
1292             allocateFields();
1293             internalSet(WEEK_YEAR, weekYear);
1294             internalSet(WEEK_OF_YEAR, weekOfYear);
1295             internalSet(DAY_OF_WEEK, dayOfWeek);
1296             return this;
1297         }
1298 
1299         /**
1300          * Sets the time zone parameter to the given {@code zone}. If no time
1301          * zone parameter is given to this {@code Caledar.Builder}, the
1302          * {@linkplain TimeZone#getDefault() default
1303          * <code>TimeZone</code>} will be used in the {@link #build() build}
1304          * method.
1305          *
1306          * @param zone the {@link TimeZone}
1307          * @return this {@code Calendar.Builder}
1308          * @throws NullPointerException if {@code zone} is {@code null}
1309          * @see Calendar#setTimeZone(TimeZone)
1310          */
1311         public Builder setTimeZone(TimeZone zone) {
1312             if (zone == null) {
1313                 throw new NullPointerException();
1314             }
1315             this.zone = zone;
1316             return this;
1317         }
1318 
1319         /**
1320          * Sets the lenient mode parameter to the value given by {@code lenient}.
1321          * If no lenient parameter is given to this {@code Calendar.Builder},




1155          * @see Calendar#set(int, int)
1156          */
1157         public Builder set(int field, int value) {
1158             // Note: WEEK_YEAR can't be set with this method.
1159             if (field < 0 || field >= FIELD_COUNT) {
1160                 throw new IllegalArgumentException("field is invalid");
1161             }
1162             if (isInstantSet()) {
1163                 throw new IllegalStateException("instant has been set");
1164             }
1165             allocateFields();
1166             internalSet(field, value);
1167             return this;
1168         }
1169 
1170         /**
1171          * Sets field parameters to their values given by
1172          * {@code fieldValuePairs} that are pairs of a field and its value.
1173          * For example,
1174          * <pre>
1175          *   setFields(Calendar.YEAR, 2013,
1176          *             Calendar.MONTH, Calendar.DECEMBER,
1177          *             Calendar.DAY_OF_MONTH, 23);</pre>
1178          * is equivalent to the sequence of the following
1179          * {@link #set(int, int) set} calls:
1180          * <pre>
1181          *   set(Calendar.YEAR, 2013)
1182          *   .set(Calendar.MONTH, Calendar.DECEMBER)
1183          *   .set(Calendar.DAY_OF_MONTH, 23);</pre>
1184          *
1185          * @param fieldValuePairs field-value pairs
1186          * @return this {@code Calendar.Builder}
1187          * @throws NullPointerException if {@code fieldValuePairs} is {@code null}
1188          * @throws IllegalArgumentException if any of fields are invalid,
1189          *             or if {@code fieldValuePairs.length} is an odd number.
1190          * @throws IllegalStateException    if the instant value has been set,
1191          *             or if fields have been set too many (approximately
1192          *             {@link Integer#MAX_VALUE}) times.
1193          */
1194         public Builder setFields(int... fieldValuePairs) {
1195             int len = fieldValuePairs.length;


1281          *
1282          * @param weekYear   the week year
1283          * @param weekOfYear the week number based on {@code weekYear}
1284          * @param dayOfWeek  the day of week value: one of the constants
1285          *     for the {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} field:
1286          *     {@link Calendar#SUNDAY SUNDAY}, ..., {@link Calendar#SATURDAY SATURDAY}.
1287          * @return this {@code Calendar.Builder}
1288          * @see Calendar#setWeekDate(int, int, int)
1289          * @see Calendar#isWeekDateSupported()
1290          */
1291         public Builder setWeekDate(int weekYear, int weekOfYear, int dayOfWeek) {
1292             allocateFields();
1293             internalSet(WEEK_YEAR, weekYear);
1294             internalSet(WEEK_OF_YEAR, weekOfYear);
1295             internalSet(DAY_OF_WEEK, dayOfWeek);
1296             return this;
1297         }
1298 
1299         /**
1300          * Sets the time zone parameter to the given {@code zone}. If no time
1301          * zone parameter is given to this {@code Calendar.Builder}, the
1302          * {@linkplain TimeZone#getDefault() default
1303          * <code>TimeZone</code>} will be used in the {@link #build() build}
1304          * method.
1305          *
1306          * @param zone the {@link TimeZone}
1307          * @return this {@code Calendar.Builder}
1308          * @throws NullPointerException if {@code zone} is {@code null}
1309          * @see Calendar#setTimeZone(TimeZone)
1310          */
1311         public Builder setTimeZone(TimeZone zone) {
1312             if (zone == null) {
1313                 throw new NullPointerException();
1314             }
1315             this.zone = zone;
1316             return this;
1317         }
1318 
1319         /**
1320          * Sets the lenient mode parameter to the value given by {@code lenient}.
1321          * If no lenient parameter is given to this {@code Calendar.Builder},


< prev index next >