net.time4j.engine.ChronoCondition Maven / Gradle / Ivy
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2016 Meno Hochschild,
* -----------------------------------------------------------------------
* This file (ChronoCondition.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 .
* -----------------------------------------------------------------------
*/
package net.time4j.engine;
import java.util.function.Predicate;
/**
* Represents a temporal condition.
*
* Common examples are queries for Friday the thirteenth or if a date
* matches a holiday or a weekend. This interface is very similar to the
* type {@code ChronoQuery} but allows more clarity and does
* not throw any exception.
*
* @author Meno Hochschild
* @see ChronoEntity#matches(ChronoCondition)
*/
/*[deutsch]
* Repräsentiert eine zeitliche Bedingung.
*
* Die gängigsten Beispiele wären etwa Freitag, der 13. oder
* die Frage, ob ein Feiertag oder ein Wochenende vorliegen. Dieses Interface
* ist im Prinzip sehr ähnlich zu {@code ChronoQuery}, erlaubt
* aber eine bessere sprachliche Klarheit und wirft keine Ausnahme.
*
* @author Meno Hochschild
* @see ChronoEntity#matches(ChronoCondition)
*/
@FunctionalInterface
public interface ChronoCondition
extends Predicate {
//~ Methoden ----------------------------------------------------------
/**
* Decides if given context matches this condition.
*
* Due to better readability it is recommended to use following
* equivalent approach instead of this method::
*
*
* import static net.time4j.Weekday.SATURDAY;
* import static net.time4j.Month.JANUARY;
*
* PlainDate date = PlainDate.of(2014, JANUARY, 25);
* System.out.println(SATURDAY.test(date)); // direct use
* System.out.println(date.matches(SATURDAY)); // recommended callback
*
*
* @param context context as base of testing this condition
* @return {@code true} if given time context matches this condition
* else {@code false}
*/
/*[deutsch]
* Entscheidet, ob der angegebene Zeitwertkontext diese Bedingung
* erfüllt.
*
* Aus Gründen der Lesbarkeit ist es meistens besser, statt dieser
* Methode vielmehr folgenden äquivalenten Ausdruck zu verwenden:
*
*
* import static net.time4j.Weekday.SATURDAY;
* import static net.time4j.Month.JANUARY;
*
* PlainDate date = PlainDate.of(2014, JANUARY, 25);
* System.out.println(SATURDAY.test(date)); // direkte Benutzung
* System.out.println(date.matches(SATURDAY)); // empfohlenes Callback
*
*
* @param context context as base of testing this condition
* @return {@code true} if given time context matches this condition
* else {@code false}
*/
@Override
boolean test(T context);
}