下面列出了org.joda.time.Duration#parse ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@inheritDoc}
*
* @throws SuperCsvCellProcessorException
* if value is null or is not a String
*/
public Object execute(final Object value, final CsvContext context) {
validateInputNotNull(value, context);
if (!(value instanceof String)) {
throw new SuperCsvCellProcessorException(String.class, value,
context, this);
}
final Duration result;
try {
result = Duration.parse((String) value);
} catch (IllegalArgumentException e) {
throw new SuperCsvCellProcessorException(
"Failed to parse value as a Duration", context, this, e);
}
return next.execute(result, context);
}
@Override
protected SimpleTranslator<Duration, String> createTranslator() {
return new SimpleTranslator<Duration, String>() {
@Override
public Duration loadValue(String datastoreValue) {
return Duration.parse(datastoreValue);
}
@Override
public String saveValue(Duration pojoValue) {
return pojoValue.toString();
}};
}
@Override
public Duration parse(String text, Locale locale) throws ParseException {
return Duration.parse(text);
}
@Override
public Duration parse(String text, Locale locale) throws ParseException {
return Duration.parse(text);
}
@Override
public Duration parse(String text, Locale locale) throws ParseException {
return Duration.parse(text);
}
@Override
public Duration convert(String source) {
return Duration.parse(source);
}
@Override
public Duration parse(String text, Locale locale) throws ParseException {
return Duration.parse(text);
}
@Override
public Duration create(PipelineOptions options) {
Duration period =
Duration.parse(System.getProperty("windmill.harness_update_reporting_period", "PT10S"));
return period.isLongerThan(Duration.ZERO) ? period : Duration.standardSeconds(10);
}
@Override
public Duration create(PipelineOptions options) {
Duration period =
Duration.parse(System.getProperty("windmill.global_get_config_refresh_period", "PT120S"));
return period.isLongerThan(Duration.ZERO) ? period : Duration.standardMinutes(2);
}
public Duration apply(String v) {
return Duration.parse(v);
}
/**
* Gson invokes this call-back method during deserialization when it encounters a field of the
* specified type.
* <p>
* In the implementation of this call-back method, you should consider invoking
* {@link JsonDeserializationContext#deserialize(JsonElement, Type)} method to create objects
* for any non-trivial field of the returned object. However, you should never invoke it on the
* the same type passing {@code json} since that will cause an infinite loop (Gson will call your
* call-back method again).
* @param json The Json data being deserialized
* @param typeOfT The type of the Object to deserialize to
* @return a deserialized object of the specified type typeOfT which is a subclass of {@code T}
* @throws JsonParseException if json is not in the expected format of {@code typeOfT}
*/
@Override
public Duration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException
{
// Do not try to deserialize null or empty values
if (json.getAsString() == null || json.getAsString().isEmpty())
{
return null;
}
return Duration.parse(json.getAsString());
}