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


Java IllegalFieldValueException.prependMessage方法代码示例

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


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

示例1: computeMillis

import org.joda.time.IllegalFieldValueException; //导入方法依赖的package包/类
/**
 * Computes the parsed datetime by setting the saved fields.
 * This method is idempotent, but it is not thread-safe.
 *
 * @param resetFields false by default, but when true, unsaved field values are cleared
 * @param text optional text being parsed, to be included in any error message
 * @return milliseconds since 1970-01-01T00:00:00Z
 * @throws IllegalArgumentException if any field is out of range
 * @since 1.3
 */
public long computeMillis(boolean resetFields, String text) {
    SavedField[] savedFields = iSavedFields;
    int count = iSavedFieldsCount;
    if (iSavedFieldsShared) {
        iSavedFields = savedFields = (SavedField[])iSavedFields.clone();
        iSavedFieldsShared = false;
    }
    sort(savedFields, count);
    if (count > 0) {
        // alter base year for parsing if first field is month or day
        DurationField months = DurationFieldType.months().getField(iChrono);
        DurationField days = DurationFieldType.days().getField(iChrono);
        DurationField first = savedFields[0].iField.getDurationField();
        if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) {
            saveField(DateTimeFieldType.year(), iDefaultYear);
            return computeMillis(resetFields, text);
        }
    }

    long millis = iMillis;
    try {
        for (int i = 0; i < count; i++) {
            millis = savedFields[i].set(millis, resetFields);
        }
        if (resetFields) {
            for (int i = 0; i < count; i++) {
                millis = savedFields[i].set(millis, i == (count - 1));
            }
        }
    } catch (IllegalFieldValueException e) {
        if (text != null) {
            e.prependMessage("Cannot parse \"" + text + '"');
        }
        throw e;
    }
    
    if (iOffset != null) {
        millis -= iOffset;
    } else if (iZone != null) {
        int offset = iZone.getOffsetFromLocal(millis);
        millis -= offset;
        if (offset != iZone.getOffset(millis)) {
            String message =
                "Illegal instant due to time zone offset transition (" + iZone + ')';
            if (text != null) {
                message = "Cannot parse \"" + text + "\": " + message;
            }
            throw new IllegalArgumentException(message);
        }
    }
    
    return millis;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:64,代码来源:DateTimeParserBucket.java

示例2: computeMillis

import org.joda.time.IllegalFieldValueException; //导入方法依赖的package包/类
/**
 * Computes the parsed datetime by setting the saved fields.
 * This method is idempotent, but it is not thread-safe.
 *
 * @param resetFields false by default, but when true, unsaved field values are cleared
 * @param text optional text being parsed, to be included in any error message
 * @return milliseconds since 1970-01-01T00:00:00Z
 * @throws IllegalArgumentException if any field is out of range
 * @since 1.3
 */
public long computeMillis(boolean resetFields, String text) {
    SavedField[] savedFields = iSavedFields;
    int count = iSavedFieldsCount;
    if (iSavedFieldsShared) {
        iSavedFields = savedFields = (SavedField[])iSavedFields.clone();
        iSavedFieldsShared = false;
    }
    sort(savedFields, count);
    if (count > 0) {
        // alter base year for parsing if first field is month or day
        DurationField months = DurationFieldType.months().getField(iChrono);
        DurationField days = DurationFieldType.days().getField(iChrono);
        DurationField first = savedFields[0].iField.getDurationField();
        if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) {
            saveField(DateTimeFieldType.year(), iDefaultYear);
            return computeMillis(resetFields, text);
        }
    }

    long millis = iMillis;
    try {
        for (int i = 0; i < count; i++) {
            millis = savedFields[i].set(millis, resetFields);
        }
        if (resetFields) {
            for (int i = 0; i < count; i++) {
                millis = savedFields[i].set(millis, i == (count - 1));
            }
        }
    } catch (IllegalFieldValueException e) {
        if (text != null) {
            e.prependMessage("Cannot parse \"" + text + '"');
        }
        throw e;
    }
    
    if (iOffset != null) {
        millis -= iOffset;
    } else if (iZone != null) {
        int offset = iZone.getOffsetFromLocal(millis);
        millis -= offset;
        if (offset != iZone.getOffset(millis)) {
            String message = "Illegal instant due to time zone offset transition (" + iZone + ')';
            if (text != null) {
                message = "Cannot parse \"" + text + "\": " + message;
            }
            throw new IllegalInstantException(message);
        }
    }
    
    return millis;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:63,代码来源:DateTimeParserBucket.java


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