当前位置: 首页>>代码示例>>Java>>正文


Java TemporalField.resolve方法代码示例

本文整理汇总了Java中java.time.temporal.TemporalField.resolve方法的典型用法代码示例。如果您正苦于以下问题:Java TemporalField.resolve方法的具体用法?Java TemporalField.resolve怎么用?Java TemporalField.resolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.temporal.TemporalField的用法示例。


在下文中一共展示了TemporalField.resolve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveFields

import java.time.temporal.TemporalField; //导入方法依赖的package包/类
private void resolveFields() {
    // resolve ChronoField
    resolveInstantFields();
    resolveDateFields();
    resolveTimeFields();

    // if any other fields, handle them
    // any lenient date resolution should return epoch-day
    if (fieldValues.size() > 0) {
        int changedCount = 0;
        outer:
        while (changedCount < 50) {
            for (Map.Entry<TemporalField, Long> entry : fieldValues.entrySet()) {
                TemporalField targetField = entry.getKey();
                TemporalAccessor resolvedObject = targetField.resolve(fieldValues, this, resolverStyle);
                if (resolvedObject != null) {
                    if (resolvedObject instanceof ChronoZonedDateTime) {
                        ChronoZonedDateTime<?> czdt = (ChronoZonedDateTime<?>) resolvedObject;
                        if (zone == null) {
                            zone = czdt.getZone();
                        } else if (zone.equals(czdt.getZone()) == false) {
                            throw new DateTimeException("ChronoZonedDateTime must use the effective parsed zone: " + zone);
                        }
                        resolvedObject = czdt.toLocalDateTime();
                    }
                    if (resolvedObject instanceof ChronoLocalDateTime) {
                        ChronoLocalDateTime<?> cldt = (ChronoLocalDateTime<?>) resolvedObject;
                        updateCheckConflict(cldt.toLocalTime(), Period.ZERO);
                        updateCheckConflict(cldt.toLocalDate());
                        changedCount++;
                        continue outer;  // have to restart to avoid concurrent modification
                    }
                    if (resolvedObject instanceof ChronoLocalDate) {
                        updateCheckConflict((ChronoLocalDate) resolvedObject);
                        changedCount++;
                        continue outer;  // have to restart to avoid concurrent modification
                    }
                    if (resolvedObject instanceof LocalTime) {
                        updateCheckConflict((LocalTime) resolvedObject, Period.ZERO);
                        changedCount++;
                        continue outer;  // have to restart to avoid concurrent modification
                    }
                    throw new DateTimeException("Method resolve() can only return ChronoZonedDateTime, " +
                            "ChronoLocalDateTime, ChronoLocalDate or LocalTime");
                } else if (fieldValues.containsKey(targetField) == false) {
                    changedCount++;
                    continue outer;  // have to restart to avoid concurrent modification
                }
            }
            break;
        }
        if (changedCount == 50) {  // catch infinite loops
            throw new DateTimeException("One of the parsed fields has an incorrectly implemented resolve method");
        }
        // if something changed then have to redo ChronoField resolve
        if (changedCount > 0) {
            resolveInstantFields();
            resolveDateFields();
            resolveTimeFields();
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:63,代码来源:Parsed.java


注:本文中的java.time.temporal.TemporalField.resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。