java.time.temporal.TemporalQuery Java Examples

The following examples show how to use java.time.temporal.TemporalQuery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DateTimePrintContext.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a value using a query.
 *
 * @param query  the query to use, not null
 * @return the result, null if not found and optional is true
 * @throws DateTimeException if the type is not available and the section is not optional
 */
<R> R getValue(TemporalQuery<R> query) {
    R result = temporal.query(query);
    if (result == null && optional == 0) {
        throw new DateTimeException("Unable to extract value: " + temporal.getClass());
    }
    return result;
}
 
Example #2
Source File: AbstractDateTimeTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void basicTest_query() {
    for (TemporalAccessor sample : samples()) {
        assertEquals(sample.query(new TemporalQuery<String>() {
            @Override
            public String queryFrom(TemporalAccessor temporal) {
                return "foo";
            }
        }), "foo");
    }
}
 
Example #3
Source File: AbstractDateTimeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void basicTest_query() {
    for (TemporalAccessor sample : samples()) {
        assertEquals(sample.query(new TemporalQuery<String>() {
            @Override
            public String queryFrom(TemporalAccessor temporal) {
                return "foo";
            }
        }), "foo");
    }
}
 
Example #4
Source File: DateTimePrintContext.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a value using a query.
 *
 * @param query  the query to use, not null
 * @return the result, null if not found and optional is true
 * @throws DateTimeException if the type is not available and the section is not optional
 */
<R> R getValue(TemporalQuery<R> query) {
    R result = temporal.query(query);
    if (result == null && optional == 0) {
        throw new DateTimeException("Unable to extract value: " + temporal.getClass());
    }
    return result;
}
 
Example #5
Source File: DateTimePrintContext.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a value using a query.
 *
 * @param query  the query to use, not null
 * @return the result, null if not found and optional is true
 * @throws DateTimeException if the type is not available and the section is not optional
 */
<R> R getValue(TemporalQuery<R> query) {
    R result = temporal.query(query);
    if (result == null && optional == 0) {
        throw new DateTimeException("Unable to extract value: " + temporal.getClass());
    }
    return result;
}
 
Example #6
Source File: DateTransformer.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
@Override
public Temporal in(final String o) {
    TemporalQuery<?> temporalAccessor = TEMPORAL_QUERYS.get(targetClassName);

    if (temporalAccessor == null || dateTimeFormatter == null) {
        throw msg.notValidDateOrTimeType(targetClassName);
    }

    return (Temporal) dateTimeFormatter.parse(o.toString(), temporalAccessor);
}
 
Example #7
Source File: DateTransformer.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
private static Map<String, TemporalQuery<?>> createTemporalQuerys() {
    Map<String, TemporalQuery<?>> defaultFormatter = new HashMap<>();

    defaultFormatter.put(LocalDate.class.getName(), LocalDate::from);
    defaultFormatter.put(LocalTime.class.getName(), LocalTime::from);
    defaultFormatter.put(LocalDateTime.class.getName(), LocalDateTime::from);
    defaultFormatter.put(OffsetTime.class.getName(), OffsetTime::from);
    defaultFormatter.put(OffsetDateTime.class.getName(), OffsetDateTime::from);
    defaultFormatter.put(ZonedDateTime.class.getName(), ZonedDateTime::from);

    return defaultFormatter;
}
 
Example #8
Source File: TCKZoneOffset.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #9
Source File: TCKDateTimeFormatter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=IllegalArgumentException.class)
public void test_parseBest_String_zeroRules() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    test.parseBest("30", new TemporalQuery<?>[0]);
}
 
Example #10
Source File: TCKMonth.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #11
Source File: TCKMonth.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(temporal.query(query), expected);
}
 
Example #12
Source File: TCKMonthDay.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #13
Source File: TCKMonthDay.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(temporal.query(query), expected);
}
 
Example #14
Source File: TCKOffsetTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #15
Source File: TCKOffsetTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(temporal.query(query), expected);
}
 
Example #16
Source File: TCKZoneOffset.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(temporal.query(query), expected);
}
 
Example #17
Source File: TCKLocalDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(temporal.query(query), expected);
}
 
Example #18
Source File: TCKOffsetTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(temporal.query(query), expected);
}
 
Example #19
Source File: TCKOffsetDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(temporal.query(query), expected);
}
 
Example #20
Source File: TCKOffsetDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #21
Source File: TCKOffsetDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(temporal.query(query), expected);
}
 
Example #22
Source File: TCKMonth.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #23
Source File: TCKLocalDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #24
Source File: TCKOffsetDateTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #25
Source File: TCKYear.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(temporal.query(query), expected);
}
 
Example #26
Source File: TCKYearMonth.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #27
Source File: TCKZoneOffset.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}
 
Example #28
Source File: DateTimeFormatterBuilder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
ZoneIdPrinterParser(TemporalQuery<ZoneId> query, String description) {
    this.query = query;
    this.description = description;
}
 
Example #29
Source File: DateTimeFormatter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Constructor. */
public ClassicFormat(DateTimeFormatter formatter, TemporalQuery<?> parseType) {
    this.formatter = formatter;
    this.parseType = parseType;
}
 
Example #30
Source File: TCKInstant.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
    assertEquals(query.queryFrom(temporal), expected);
}