List of usage examples for org.joda.time Duration parse
@FromString public static Duration parse(String str)
From source file:com.anrisoftware.mongoose.buildins.execbuildin.ExecBuildin.java
License:Open Source License
/** * Sets the timeout for the process.//from ww w . j a v a 2 s .c o m * * @param object * the {@link Duration} of the timeout; or the {@link Number} * timeout in milliseconds; or an {@link Object} that is parsed * as the duration. * * @throws CommandException * if any errors set the timeout watchdog. * * @throws IllegalArgumentException * if the parsed duration is not valid. */ public void setTimeout(Object object) throws CommandException { if (object instanceof Duration) { Duration timeout = (Duration) object; setWatchdog(new ExecuteWatchdog(timeout.getMillis())); } else if (object instanceof Number) { Number timeout = (Number) object; setWatchdog(new ExecuteWatchdog(timeout.longValue())); } else { Duration timeout = Duration.parse(object.toString()); setWatchdog(new ExecuteWatchdog(timeout.getMillis())); } }
From source file:com.anrisoftware.mongoose.environment.EnvironmentImpl.java
License:Open Source License
@Inject EnvironmentImpl(EnvironmentImplLogger logger, @Named("threads-properties") Properties threadsProperties, @Named("environment-properties") ContextProperties properties, PropertiesThreadsFactory threadsFactory, TextsResources textsResources, TemplatesResources templatesResources, LocaleHooks localeHooks) throws ParseException, ThreadsException { this.log = logger; this.threads = threadsFactory.create(threadsProperties, "script"); this.variables = new HashMap<String, Object>(); this.variablesSetters = new HashMap<String, VariableSetter>(); this.textsResources = textsResources; this.templatesResources = templatesResources; this.backgroundCommandsPolicy = properties.getTypedProperty(BACKGROUND_COMMANDS_POLICY_PROPERTY, POLICY_FORMAT);//from ww w .j av a 2 s .c o m this.backgroundCommandsTimeout = Duration .parse(properties.getProperty(BACKGROUND_COMMANDS_TIMEOUT_PROPERTY)); setExecutionMode(properties.<ExecutionMode>getTypedProperty(EXECUTION_MODE_PROPERTY, ExecutionMode.FORMAT)); setupLocaleHooks(localeHooks); setupVariables(); setupVariablesSetters(); }
From source file:com.duboisproject.rushhour.database.SdbInterface.java
License:Open Source License
protected static GameStatistics parseStats(Item item) { Map<String, String> attributes = mapify(item.getAttributes()); GameStatistics stats = new GameStatistics(); stats.levelId = Integer.parseInt(attributes.get(PLAYS_LEVEL)); stats.totalMoves = Integer.parseInt(attributes.get(PLAYS_TOTAL_MOVES)); stats.resetMoves = Integer.parseInt(attributes.get(PLAYS_RESET_MOVES)); stats.startTime = DateTime.parse(attributes.get(PLAYS_START)); stats.totalCompletionTime = Duration.parse(attributes.get(PLAYS_TOTAL_TIME)); stats.resetCompletionTime = Duration.parse(attributes.get(PLAYS_RESET_TIME)); return stats; }
From source file:com.fatboyindustrial.gsonjodatime.DurationConverter.java
License:Open Source License
/** * Gson invokes this call-back method during deserialization when it encounters a field of the * specified type./*from ww w . j a v a2 s . c o m*/ * <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()); }
From source file:com.predic8.membrane.core.interceptor.ratelimit.RateLimitInterceptor.java
License:Apache License
/** * @description Duration after the limit is reset in PTxS where x is the * time in seconds/*from www . ja va2s. co m*/ * @default PT3600S */ @MCAttribute public void setRequestLimitDuration(String rld) { setRequestLimitDuration(Duration.parse(rld)); }
From source file:de.arkraft.jenkins.JenkinsHelper.java
License:Apache License
public static GsonBuilder getGsonBuilder() { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(DateTime.class, new JsonDeserializer<DateTime>() { @Override//from w w w .j a v a 2 s . co m public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { // using the correct parser right away should save init time compared to new DateTime(<string>) return ISO_8601_WITH_MILLIS.parseDateTime(json.getAsString()); } }); builder.registerTypeAdapter(DateTime.class, new JsonSerializer<DateTime>() { @Override public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src.toString()); } }); builder.registerTypeAdapter(Duration.class, new JsonDeserializer() { @Override public Object deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { return Duration.parse("PT" + json.getAsString() + "S"); } }); builder.registerTypeAdapter(Action.class, new JsonDeserializer<Action>() { @Override public Action deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { JsonObject object = ((JsonObject) jsonElement); if (object.has("causes")) { JsonElement element = object.get("causes"); if (element.isJsonArray()) { return jsonDeserializationContext.deserialize(element, Causes.class); } } if (object.has("failCount")) { return jsonDeserializationContext.deserialize(object, CountAction.class); } return null; } }); builder.registerTypeAdapter(ChangeSet.class, new JsonDeserializer<ChangeSet>() { @Override public ChangeSet deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { ChangeSet changeSet = new ChangeSet(); JsonObject object = (JsonObject) jsonElement; if (object.has("items") && object.get("items").isJsonArray()) { for (JsonElement element : object.get("items").getAsJsonArray()) { ChangeSet.Change change = context.deserialize(element, ChangeSet.Change.class); changeSet.add(change); } } if (object.has("kind")) { changeSet.setKind(object.get("kind").getAsString()); } return changeSet; } }); builder.registerTypeAdapter(Duration.class, new JsonSerializer<Duration>() { @Override public JsonElement serialize(Duration duration, Type type, JsonSerializationContext jsonSerializationContext) { return new JsonPrimitive(duration.toString().replace("PT", "").replace("S", "")); } }); builder.registerTypeAdapter(EditType.class, new JsonDeserializer<EditType>() { @Override public EditType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { return EditType.byName(jsonElement.getAsString()); } }); builder.registerTypeAdapter(HealthIcon.class, new JsonDeserializer<HealthIcon>() { @Override public HealthIcon deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { return HealthIcon.fromName(jsonElement.toString()); } }); builder.registerTypeAdapter(Queue.class, new JsonDeserializer<Queue>() { @Override public Queue deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { Queue queue = new Queue(); JsonObject jsonObject = (JsonObject) jsonElement; if (jsonObject.has("items") && jsonObject.get("items").isJsonArray()) { for (JsonElement element : jsonObject.get("items").getAsJsonArray()) { Queue.Item build = context.deserialize(element, Queue.Item.class); queue.add(build); } } return queue; } }); builder.registerTypeAdapter(JobCollection.class, new JsonDeserializer<JobCollection>() { @Override public JobCollection deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JobCollection jobs = new JobCollection(); JsonObject object = (JsonObject) json; if (object.has("jobs") && object.get("jobs").isJsonArray()) { for (JsonElement element : object.get("jobs").getAsJsonArray()) { Job job = context.deserialize(element, Job.class); jobs.add(job); } } return jobs; } }); builder.registerTypeAdapter(BallColor.class, new JsonDeserializer<BallColor>() { @Override public BallColor deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext json) throws JsonParseException { return BallColor.valueOf(jsonElement.getAsString().toUpperCase()); } }); return builder; }
From source file:google.registry.model.translators.DurationTranslatorFactory.java
License:Open Source License
@Override protected SimpleTranslator<Duration, String> createTranslator() { return new SimpleTranslator<Duration, String>() { @Override/*from www.j a v a 2s . c o m*/ public Duration loadValue(String datastoreValue) { return Duration.parse(datastoreValue); } @Override public String saveValue(Duration pojoValue) { return pojoValue.toString(); } }; }
From source file:griffon.plugins.jodatime.editors.DurationPropertyEditor.java
License:Apache License
private void handleAsString(String str) { if (isBlank(str)) { super.setValueInternal(null); return;/*from w w w. jav a2 s. c o m*/ } try { super.setValueInternal(new Duration(Long.parseLong(str))); return; } catch (NumberFormatException nfe) { // ignore } try { super.setValueInternal(Duration.parse(str)); } catch (IllegalArgumentException e) { throw illegalValue(str, Duration.class, e); } }
From source file:it.d4nguard.rgrpg.util.dynacast.adapters.DurationAdapter.java
License:Open Source License
/** * {@inheritDoc} */ @Override public Duration adapt(String value) { return Duration.parse(String.format("PT%sS", value)); }
From source file:org.apache.abdera2.activities.io.gson.DurationAdapter.java
License:Apache License
protected Duration deserialize(String v) { return Duration.parse(v); }