下面列出了怎么用java.time.temporal.TemporalQuery的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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;
}
@Test
public void basicTest_query() {
for (TemporalAccessor sample : samples()) {
assertEquals(sample.query(new TemporalQuery<String>() {
@Override
public String queryFrom(TemporalAccessor temporal) {
return "foo";
}
}), "foo");
}
}
@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);
}
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;
}
/**
* 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;
}
@Test
public void basicTest_query() {
for (TemporalAccessor sample : samples()) {
assertEquals(sample.query(new TemporalQuery<String>() {
@Override
public String queryFrom(TemporalAccessor temporal) {
return "foo";
}
}), "foo");
}
}
/**
* 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;
}
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(query.queryFrom(temporal), expected);
}
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(query.queryFrom(temporal), expected);
}
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(query.queryFrom(temporal), expected);
}
ZoneIdPrinterParser(TemporalQuery<ZoneId> query, String description) {
this.query = query;
this.description = description;
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}
/** Constructor. */
public ClassicFormat(DateTimeFormatter formatter, TemporalQuery<?> parseType) {
this.formatter = formatter;
this.parseType = parseType;
}
/** Constructor. */
public ClassicFormat(DateTimeFormatter formatter, TemporalQuery<?> parseType) {
this.formatter = formatter;
this.parseType = parseType;
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(query.queryFrom(temporal), expected);
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(query.queryFrom(temporal), expected);
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(query.queryFrom(temporal), expected);
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(query.queryFrom(temporal), expected);
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}
@Test(dataProvider="query")
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(query.queryFrom(temporal), expected);
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}
/** Constructor. */
public ClassicFormat(DateTimeFormatter formatter, TemporalQuery<?> parseType) {
this.formatter = formatter;
this.parseType = parseType;
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}
/** Constructor. */
public ClassicFormat(DateTimeFormatter formatter, TemporalQuery<?> parseType) {
this.formatter = formatter;
this.parseType = parseType;
}
@Test(dataProvider="query")
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
assertEquals(temporal.query(query), expected);
}