下面列出了怎么用org.joda.time.IllegalFieldValueException的API类实例代码及写法,或者点击链接到github查看源代码。
public long set(long millis, int value) {
FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue());
// start of generated patch
if(value<=iSkip){
if(value==iSkip){
throw new IllegalFieldValueException(DateTimeFieldType.year(),Integer.valueOf(value),null,null);
}
getMaximumValue();
}
// end of generated patch
/* start of original code
if (value <= iSkip) {
if (value == iSkip) {
throw new IllegalFieldValueException
(DateTimeFieldType.year(), Integer.valueOf(value), null, null);
}
value++;
}
end of original code*/
return super.set(millis, value);
}
private LocalDateTime decodeTime(byte[] rawContent) {
int hours = ByteUtil.asUINT8(rawContent[0]);
int minutes = ByteUtil.asUINT8(rawContent[1]);
int seconds = ByteUtil.asUINT8(rawContent[2]);
int year = (ByteUtil.asUINT8(rawContent[4]) & 0x3f) + 1984;
int month = ByteUtil.asUINT8(rawContent[5]);
int day = ByteUtil.asUINT8(rawContent[6]);
try {
LocalDateTime pumpTime = new LocalDateTime(year, month, day, hours, minutes, seconds);
return pumpTime;
} catch (IllegalFieldValueException e) {
LOG.error(
"decodeTime: Failed to parse pump time value: year=%d, month=%d, hours=%d, minutes=%d, seconds=%d",
year, month, day, hours, minutes, seconds);
return null;
}
}
@Override
public long set(long instant, int value) {
// Check for illegal values: this is not a lenient field
if (value < 1 || value > this.numMonthsInYear) {
throw new IllegalFieldValueException(this.getType(), value, 1, this.numMonthsInYear);
}
// What is the current month?
int monthOfYear = this.get(instant);
// How many months do we have to add to arrive at the new value
int monthsToAdd = value - monthOfYear;
// Now add the required number of months
return this.add(instant, monthsToAdd);
}
@Test(expected=IllegalFieldValueException.class)
public void testIssue233JodaTimeLimit() throws ParseException {
// https://github.com/aws/aws-sdk-java/issues/233
String s = DateUtils.iso8601DateFormat.print(Long.MAX_VALUE);
System.out.println("s: " + s);
try {
DateTime dt = DateUtils.iso8601DateFormat.parseDateTime(s);
fail("Unexpected success: " + dt);
} catch(IllegalFieldValueException ex) {
// expected
throw ex;
}
}
@Override
public void serialize(Long timestamp, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
// Joda may throw an exception if the timestamp is MAX_LONG so protect ourselves here.
try {
DateTime dateTime = new DateTime(timestamp).withZone(DateTimeZone.UTC);
jsonGenerator.writeObject(dateTime.toString(ISODateTimeFormat.dateTime()));
} catch (IllegalFieldValueException e) {
jsonGenerator.writeString("ERROR");
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(String fieldName,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(fieldName, Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(String fieldName,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(fieldName, Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(String fieldName,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(fieldName, Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(String fieldName,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(fieldName, Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(String fieldName,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(fieldName, Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(String fieldName,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(fieldName, Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
public long set(long instant, int value) {
if (instant >= iCutover) {
instant = iGregorianField.set(instant, value);
if (instant < iCutover) {
// Only adjust if gap fully crossed.
if (instant + iGapDuration < iCutover) {
instant = gregorianToJulian(instant);
}
// Verify that new value stuck.
if (get(instant) != value) {
throw new IllegalFieldValueException
(iGregorianField.getType(), Integer.valueOf(value), null, null);
}
}
} else {
instant = iJulianField.set(instant, value);
if (instant >= iCutover) {
// Only adjust if gap fully crossed.
if (instant - iGapDuration >= iCutover) {
instant = julianToGregorian(instant);
}
// Verify that new value stuck.
if (get(instant) != value) {
throw new IllegalFieldValueException
(iJulianField.getType(), Integer.valueOf(value), null, null);
}
}
}
return instant;
}
public long set(long instant, int value) {
if (instant >= iCutover) {
instant = iGregorianField.set(instant, value);
if (instant < iCutover) {
// Only adjust if gap fully crossed.
if (instant + iGapDuration < iCutover) {
instant = gregorianToJulian(instant);
}
// Verify that new value stuck.
if (get(instant) != value) {
throw new IllegalFieldValueException
(iGregorianField.getType(), Integer.valueOf(value), null, null);
}
}
} else {
instant = iJulianField.set(instant, value);
if (instant >= iCutover) {
// Only adjust if gap fully crossed.
if (instant - iGapDuration >= iCutover) {
instant = julianToGregorian(instant);
}
// Verify that new value stuck.
if (get(instant) != value) {
throw new IllegalFieldValueException
(iJulianField.getType(), Integer.valueOf(value), null, null);
}
}
}
return instant;
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(String fieldName,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(fieldName, Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(String fieldName,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(fieldName, Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
public long set(long instant, int value) {
if (instant >= iCutover) {
instant = iGregorianField.set(instant, value);
if (instant < iCutover) {
// Only adjust if gap fully crossed.
if (instant + iGapDuration < iCutover) {
instant = gregorianToJulian(instant);
}
// Verify that new value stuck.
if (get(instant) != value) {
throw new IllegalFieldValueException
(iGregorianField.getType(), Integer.valueOf(value), null, null);
}
}
} else {
instant = iJulianField.set(instant, value);
if (instant >= iCutover) {
// Only adjust if gap fully crossed.
if (instant - iGapDuration >= iCutover) {
instant = julianToGregorian(instant);
}
// Verify that new value stuck.
if (get(instant) != value) {
throw new IllegalFieldValueException
(iJulianField.getType(), Integer.valueOf(value), null, null);
}
}
}
return instant;
}
public long set(long instant, int value) {
if (instant >= iCutover) {
instant = iGregorianField.set(instant, value);
if (instant < iCutover) {
// Only adjust if gap fully crossed.
if (instant + iGapDuration < iCutover) {
instant = gregorianToJulian(instant);
}
// Verify that new value stuck.
if (get(instant) != value) {
throw new IllegalFieldValueException
(iGregorianField.getType(), Integer.valueOf(value), null, null);
}
}
} else {
instant = iJulianField.set(instant, value);
if (instant >= iCutover) {
// Only adjust if gap fully crossed.
if (instant - iGapDuration >= iCutover) {
instant = julianToGregorian(instant);
}
// Verify that new value stuck.
if (get(instant) != value) {
throw new IllegalFieldValueException
(iJulianField.getType(), Integer.valueOf(value), null, null);
}
}
}
return instant;
}
public long set(long instant, int value) {
long localInstant = iZone.convertUTCToLocal(instant);
localInstant = iField.set(localInstant, value);
long result = iZone.convertLocalToUTC(localInstant, false, instant);
if (get(result) != value) {
throw new IllegalFieldValueException(iField.getType(), new Integer(value),
"Illegal instant due to time zone offset transition: " +
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").print(new Instant(localInstant)) +
" (" + iZone.getID() + ")");
}
return result;
}
public long set(long instant, int value) {
long localInstant = iZone.convertUTCToLocal(instant);
localInstant = iField.set(localInstant, value);
long result = iZone.convertLocalToUTC(localInstant, false);
if (get(result) != value) {
throw new IllegalFieldValueException(iField.getType(), new Integer(value),
"Illegal instant due to time zone offset transition: " +
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").print(new Instant(localInstant)) +
" (" + iZone.getID() + ")");
}
return result;
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(String fieldName,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(fieldName, Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
public long set(long millis, int value) {
FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue());
if (value <= iSkip) {
if (value == iSkip) {
throw new IllegalFieldValueException
(DateTimeFieldType.year(), Integer.valueOf(value), null, null);
}
value++;
}
return super.set(millis, value);
}