private long getTimeDurationHelper(String name, String vStr, TimeUnit unit) { ParsedTimeDuration vUnit = ParsedTimeDuration.unitFor(vStr); if (null == vUnit) { LOG.warn("No unit for " + name + "(" + vStr + ") assuming " + unit); vUnit = ParsedTimeDuration.unitFor(unit); } else { vStr = vStr.substring(0, vStr.lastIndexOf(vUnit.suffix())); } return unit.convert(Long.parseLong(vStr), vUnit.unit()); }
/** * Set the value of <code>name</code> to the given time duration. This * is equivalent to <code>set(<name>, value + <time suffix>)</code>. * @param name Property name * @param value Time duration * @param unit Unit of time */ public void setTimeDuration(String name, long value, TimeUnit unit) { set(name, value + ParsedTimeDuration.unitFor(unit).suffix()); }
static ParsedTimeDuration unitFor(String s) { for (ParsedTimeDuration ptd : values()) { // iteration order is in decl order, so SECONDS matched last if (s.endsWith(ptd.suffix())) { return ptd; } } return null; } static ParsedTimeDuration unitFor(TimeUnit unit) {
/** * Return time duration in the given time unit. Valid units are encoded in * properties as suffixes: nanoseconds (ns), microseconds (us), milliseconds * (ms), seconds (s), minutes (m), hours (h), and days (d). * @param name Property name * @param defaultValue Value returned if no mapping exists. * @param unit Unit to convert the stored property, if it exists. * @throws NumberFormatException If the property stripped of its unit is not * a number */ public long getTimeDuration(String name, long defaultValue, TimeUnit unit) { String vStr = get(name); if (null == vStr) { return defaultValue; } vStr = vStr.trim(); ParsedTimeDuration vUnit = ParsedTimeDuration.unitFor(vStr); if (null == vUnit) { LOG.warn("No unit for " + name + "(" + vStr + ") assuming " + unit); vUnit = ParsedTimeDuration.unitFor(unit); } else { vStr = vStr.substring(0, vStr.lastIndexOf(vUnit.suffix())); } return unit.convert(Long.parseLong(vStr), vUnit.unit()); }
/** * Return time duration in the given time unit. Valid units are encoded in * properties as suffixes: nanoseconds (ns), microseconds (us), milliseconds * (ms), seconds (s), minutes (m), hours (h), and days (d). * @param name Property name * @param defaultValue Value returned if no mapping exists. * @param unit Unit to convert the stored property, if it exists. * @throws NumberFormatException If the property stripped of its unit is not * a number */ public long getTimeDuration(String name, long defaultValue, TimeUnit unit) { String vStr = get(name); if (null == vStr) { return defaultValue; } vStr = vStr.trim(); ParsedTimeDuration vUnit = ParsedTimeDuration.unitFor(vStr); if (null == vUnit) { LOG.warn("No unit for " + name + "(" + vStr + ") assuming " + unit); vUnit = ParsedTimeDuration.unitFor(unit); } else { vStr = vStr.substring(0, vStr.lastIndexOf(vUnit.suffix())); } return unit.convert(Long.parseLong(vStr), vUnit.unit()); }
static ParsedTimeDuration unitFor(String s) { for (ParsedTimeDuration ptd : values()) { // iteration order is in decl order, so SECONDS matched last if (s.endsWith(ptd.suffix())) { return ptd; } } return null; } static ParsedTimeDuration unitFor(TimeUnit unit) {
/** * Set the value of <code>name</code> to the given time duration. This * is equivalent to <code>set(<name>, value + <time suffix>)</code>. * @param name Property name * @param value Time duration * @param unit Unit of time */ public void setTimeDuration(String name, long value, TimeUnit unit) { set(name, value + ParsedTimeDuration.unitFor(unit).suffix()); }
static ParsedTimeDuration unitFor(String s) { for (ParsedTimeDuration ptd : values()) { // iteration order is in decl order, so SECONDS matched last if (s.endsWith(ptd.suffix())) { return ptd; } } return null; } static ParsedTimeDuration unitFor(TimeUnit unit) {
/** * Set the value of <code>name</code> to the given time duration. This * is equivalent to <code>set(<name>, value + <time suffix>)</code>. * @param name Property name * @param value Time duration * @param unit Unit of time */ public void setTimeDuration(String name, long value, TimeUnit unit) { set(name, value + ParsedTimeDuration.unitFor(unit).suffix()); }
static ParsedTimeDuration unitFor(String s) { for (ParsedTimeDuration ptd : values()) { // iteration order is in decl order, so SECONDS matched last if (s.endsWith(ptd.suffix())) { return ptd; } } return null; } static ParsedTimeDuration unitFor(TimeUnit unit) {
/** * Set the value of <code>name</code> to the given time duration. This * is equivalent to <code>set(<name>, value + <time suffix>)</code>. * @param name Property name * @param value Time duration * @param unit Unit of time */ public void setTimeDuration(String name, long value, TimeUnit unit) { set(name, value + ParsedTimeDuration.unitFor(unit).suffix()); }
/** * Set the value of <code>name</code> to the given time duration. This * is equivalent to <code>set(<name>, value + <time suffix>)</code>. * @param name Property name * @param value Time duration * @param unit Unit of time */ public void setTimeDuration(String name, long value, TimeUnit unit) { set(name, value + ParsedTimeDuration.unitFor(unit).suffix()); }
static ParsedTimeDuration unitFor(String s) { for (ParsedTimeDuration ptd : values()) { // iteration order is in decl order, so SECONDS matched last if (s.endsWith(ptd.suffix())) { return ptd; } } return null; } static ParsedTimeDuration unitFor(TimeUnit unit) {
private long getTimeDurationHelper(String name, String vStr, TimeUnit unit) { ParsedTimeDuration vUnit = ParsedTimeDuration.unitFor(vStr); if (null == vUnit) { LOG.warn("No unit for " + name + "(" + vStr + ") assuming " + unit); vUnit = ParsedTimeDuration.unitFor(unit); } else { vStr = vStr.substring(0, vStr.lastIndexOf(vUnit.suffix())); } return unit.convert(Long.parseLong(vStr), vUnit.unit()); }
/** * Return time duration in the given time unit. Valid units are encoded in * properties as suffixes: nanoseconds (ns), microseconds (us), milliseconds * (ms), seconds (s), minutes (m), hours (h), and days (d). * @param name Property name * @param vStr The string value with time unit suffix to be converted. * @param unit Unit to convert the stored property, if it exists. */ public long getTimeDurationHelper(String name, String vStr, TimeUnit unit) { vStr = vStr.trim(); vStr = StringUtils.toLowerCase(vStr); ParsedTimeDuration vUnit = ParsedTimeDuration.unitFor(vStr); if (null == vUnit) { logDeprecation("No unit for " + name + "(" + vStr + ") assuming " + unit); vUnit = ParsedTimeDuration.unitFor(unit); } else { vStr = vStr.substring(0, vStr.lastIndexOf(vUnit.suffix())); } long raw = Long.parseLong(vStr); long converted = unit.convert(raw, vUnit.unit()); if (vUnit.unit().convert(converted, unit) < raw) { logDeprecation("Possible loss of precision converting " + vStr + vUnit.suffix() + " to " + unit + " for " + name); } return converted; }
/** * Return time duration in the given time unit. Valid units are encoded in * properties as suffixes: nanoseconds (ns), microseconds (us), milliseconds * (ms), seconds (s), minutes (m), hours (h), and days (d). * @param name Property name * @param vStr The string value with time unit suffix to be converted. * @param unit Unit to convert the stored property, if it exists. */ public long getTimeDurationHelper(String name, String vStr, TimeUnit unit) { vStr = vStr.trim(); vStr = StringUtils.toLowerCase(vStr); ParsedTimeDuration vUnit = ParsedTimeDuration.unitFor(vStr); if (null == vUnit) { logDeprecation("No unit for " + name + "(" + vStr + ") assuming " + unit); vUnit = ParsedTimeDuration.unitFor(unit); } else { vStr = vStr.substring(0, vStr.lastIndexOf(vUnit.suffix())); } long raw = Long.parseLong(vStr); long converted = unit.convert(raw, vUnit.unit()); if (vUnit.unit().convert(converted, unit) < raw) { logDeprecation("Possible loss of precision converting " + vStr + vUnit.suffix() + " to " + unit + " for " + name); } return converted; }
/** * Set the value of <code>name</code> to the given time duration. This * is equivalent to <code>set(<name>, value + <time suffix>)</code>. * @param name Property name * @param value Time duration * @param unit Unit of time */ public void setTimeDuration(String name, long value, TimeUnit unit) { set(name, value + ParsedTimeDuration.unitFor(unit).suffix()); }
static ParsedTimeDuration unitFor(String s) { for (ParsedTimeDuration ptd : values()) { // iteration order is in decl order, so SECONDS matched last if (s.endsWith(ptd.suffix())) { return ptd; } } return null; } static ParsedTimeDuration unitFor(TimeUnit unit) {
/** * Set the value of <code>name</code> to the given time duration. This * is equivalent to <code>set(<name>, value + <time suffix>)</code>. * @param name Property name * @param value Time duration * @param unit Unit of time */ public void setTimeDuration(String name, long value, TimeUnit unit) { set(name, value + ParsedTimeDuration.unitFor(unit).suffix()); }
static ParsedTimeDuration unitFor(String s) { for (ParsedTimeDuration ptd : values()) { // iteration order is in decl order, so SECONDS matched last if (s.endsWith(ptd.suffix())) { return ptd; } } return null; } static ParsedTimeDuration unitFor(TimeUnit unit) {