/* * ----------------------------------------------------------------------- * Copyright © 2013-2015 Meno Hochschild, <http://www.menodata.de/> * ----------------------------------------------------------------------- * This file (OrdinalWeekdayElement.java) is part of project Time4J. * * Time4J is free software: You can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 2.1 of the License, or * (at your option) any later version. * * Time4J is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Time4J. If not, see <http://www.gnu.org/licenses/>. * ----------------------------------------------------------------------- */ package net.time4j; /** * <p>The element for the ordinal weekday in month. </p> * * <p>An instance can be obtained using the expression * {@link PlainDate#WEEKDAY_IN_MONTH}. This interface inherits from * {@code AdjustableElement} and offers additional operator for setting * the weekday in month. </p> * * @author Meno Hochschild */ /*[deutsch] * <p>Das Element für den x-ten Wochentag im Monat. </p> * * <p>Eine Instanz ist erhältlich über den Ausdruck * {@link PlainDate#WEEKDAY_IN_MONTH}. Dieses Interface bietet neben * den vom Interface {@code AdjustableElement} geerbten Methoden * weitere Spezialmethoden zum Setzen des Wochentags im Monat. </p> * * @author Meno Hochschild */ public interface OrdinalWeekdayElement extends AdjustableElement<Integer, PlainDate> { //~ Methoden ---------------------------------------------------------- /** * <p>Defines an operator which moves a date to the first given weekday * in month. </p> * * @param dayOfWeek first day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ /*[deutsch] * <p>Definiert einen Versteller, der ein Datum auf den ersten angegebenen * Wochentag eines Monats setzt. </p> * * @param dayOfWeek first day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ ElementOperator<PlainDate> setToFirst(Weekday dayOfWeek); /** * <p>Defines an operator which moves a date to the second given weekday * in month. </p> * * @param dayOfWeek second day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ /*[deutsch] * <p>Definiert einen Versteller, der ein Datum auf den zweiten angegebenen * Wochentag eines Monats setzt. </p> * * @param dayOfWeek second day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ ElementOperator<PlainDate> setToSecond(Weekday dayOfWeek); /** * <p>Defines an operator which moves a date to the third given weekday * in month. </p> * * @param dayOfWeek third day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ /*[deutsch] * <p>Definiert einen Versteller, der ein Datum auf den dritten angegebenen * Wochentag eines Monats setzt. </p> * * @param dayOfWeek third day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ ElementOperator<PlainDate> setToThird(Weekday dayOfWeek); /** * <p>Defines an operator which moves a date to the fourth given weekday * in month. </p> * * @param dayOfWeek fourth day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ /*[deutsch] * <p>Definiert einen Versteller, der ein Datum auf den vierten angegebenen * Wochentag eines Monats setzt. </p> * * @param dayOfWeek fourth day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ ElementOperator<PlainDate> setToFourth(Weekday dayOfWeek); /** * <p>Defines an operator which moves a date to the last given weekday * in month. </p> * * @param dayOfWeek last day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ /*[deutsch] * <p>Definiert einen Versteller, der ein Datum auf den letzten angegebenen * Wochentag eines Monats setzt. </p> * * @param dayOfWeek last day of week in month * @return operator directly applicable also on {@code PlainTimestamp} */ ElementOperator<PlainDate> setToLast(Weekday dayOfWeek); /** * <p>Defines an operator which moves a date to the given ordinal weekday * in month. </p> * * <p>If given ordinal number is {@code Integer.MAX_VALUE} then the last weekday in month * will be determined. Note that only the values 1-4 can give the guarantee that the current * month will not be changed. </p> * * @param ordinal ordinal number * @param dayOfWeek last day of week in month * @return operator directly applicable also on {@code PlainTimestamp} * @since 4.1 */ /*[deutsch] * <p>Definiert einen Versteller, der ein Datum auf den x-ten angegebenen * Wochentag eines Monats setzt. </p> * * <p>Wenn die angegebene Ordnungsnummer {@code Integer.MAX_VALUE} ist, wird der letzte * Wochentag des Monats bestimmt. Zu beachten, nur die Werte 1-4 können garantieren, * daß der aktuelle Monat gleich bleibt. </p> * * @param ordinal ordinal number * @param dayOfWeek last day of week in month * @return operator directly applicable also on {@code PlainTimestamp} * @since 4.1 */ default ElementOperator<PlainDate> setTo( int ordinal, Weekday dayOfWeek ) { switch (ordinal) { case 1: return this.setToFirst(dayOfWeek); case 2: return this.setToSecond(dayOfWeek); case 3: return this.setToThird(dayOfWeek); case 4: return this.setToFourth(dayOfWeek); case Integer.MAX_VALUE: return this.setToLast(dayOfWeek); default: throw new UnsupportedOperationException("Out of range: " + ordinal); } } }