Queries this year using the specified query.
A custom temporal query example.
package com.logicbig.example.year;
import java.time.Year;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalQuery;
public class QueryExample2 {
public static void main(String... args) {
Year y = Year.of(1900);
Boolean b = y.query(firstWorldWarPeriodQuery);
System.out.println(b);
Year y2 = Year.of(1915);
Boolean b2 = y2.query(firstWorldWarPeriodQuery);
System.out.println(b2);
}
private static final TemporalQuery<Boolean> firstWorldWarPeriodQuery = temporal -> {
if (temporal.isSupported(ChronoField.YEAR)) {
long l = temporal.getLong(ChronoField.YEAR);
return l > 1914 && l < 1918;
}
return false;
};
}
Output
false
true