Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* The double is created by parsing the string config value and converting between the time unit declared in the
* string config value and the time unit of the enclosing Config class instance. The value returned will also include
* the non-integer fraction of the time, if any, that results from converting between time units.
* See {@link OptionalValueParser#asTime()} for a variant that only returns a whole number of time units.
*
* String config values representing times can be given either:
*
*
in the form "{@code ,
* Valid time units are those defined by {@link TimeUnit}
*
* @throws NullPointerException if {@link Config#getTimeUnit()} has not been set.
* @throws IllegalStateException if the config value does not satisfy one of the formats given above.
* @throws IllegalArgumentException if the time unit in the config value does not match one of the values specified by {@link TimeUnit}.
* @throws NumberFormatException if the numerical part of the config value given cannot be parsed by {@link Double#parseDouble(String)}.
*/
public OptionalDouble asFractionalTime() {
return parser.map(p -> OptionalDouble.of(p.asFractionalTime())).orElse(OptionalDouble.empty());
}
/**
* @return {@link OptionalLong#empty()} if the config value is an empty String, otherwise returns an {@link OptionalLong}
* containing a long representing a time in the unit returned by {@link Config#getTimeUnit()}.
*
* The long is created by parsing the string config value and converting between the time unit declared in the
* string config value and the time unit of the enclosing Config class instance. The value returned will be rounded to the nearest
* whole number of units.
*
* String config values representing times can be given either:
*
*
in the form "{@code ,}" or "{@code :}". E.g. "5.65,SECONDS" or "1:HOURS"
*
as a double, in which case it will be assumed that the value is being specified with a time unit of seconds. I.e. this is equivalent to doing "{@code ,SECONDS}"
*
* Valid time units are those defined by {@link TimeUnit}
*
* @throws NullPointerException if {@link Config#getTimeUnit()} has not been set.
* @throws IllegalStateException if the config value does not satisfy one of the formats given above.
* @throws IllegalArgumentException if the time unit in the config value does not match one of the values specified by {@link TimeUnit}.
* @throws NumberFormatException if the numerical part of the config value given cannot be parsed by {@link Double#parseDouble(String)}.
*/
public OptionalLong asTime() {
return parser.map(p -> OptionalLong.of(p.asTime())).orElse(OptionalLong.empty());
}
/**
* @return {@link Optional#empty()} if the config value is an empty String, otherwise returns an {@link Optional}
* containing the string config value parsed as a {@link Duration} rounded to the nearest nanosecond.
*
* Duration config values can be given either:
* - As a double on its own, in which case it will be assumed that the value is being specified in seconds
* - In the form {@code ,} or {@code :}.
*
* @throws IllegalStateException if the config value does not satisfy one of the formats given above.
* @throws IllegalArgumentException if the time unit in the config value does not match an enum value.
* @throws NumberFormatException if the value given cannot be parsed as a double.
*/
public Optional asDuration() {
return parser.map(StrictValueParser::asDuration);
}
/**
* @return {@link Optional#empty()} if the config value is an empty String, otherwise returns an {@link Optional}
* containing the string config value parsed as a length using the declared application length unit.
*
* Length config values can be given either
* - as a double, in which case Config will assume that the value is being specified in meters.
* - in the form {@code ,} or {@code :}.
*
* @throws NullPointerException if the application length unit has not been set.
* @throws IllegalStateException if the config value does not satisfy one of the formats given above.
* @throws IllegalArgumentException if the length unit in the config value does not match an enum value.
* @throws NumberFormatException if the value given cannot be parsed as a double.
*/
public OptionalDouble asLength() {
return parser.map(p -> OptionalDouble.of(p.asLength())).orElse(OptionalDouble.empty());
}
/**
* @return {@link Optional#empty()} if the config value is an empty String, otherwise returns an {@link Optional}
* containing the string config value parsed as a speed using the declared application time and length
* units.
*
* Speed config values can be given either
* - as a double, in which case Config will assume that the value is being specified in meters per second
* - in the form {@code ,,} or {@code ::}
*
* @throws NullPointerException if the application time or length units have not been set
* @throws IllegalStateException if the config value does not satisfy one of the formats given above
* @throws IllegalArgumentException if the time or length units in the config value do not match an enum value
* @throws NumberFormatException if the value given cannot be parsed as a double
*/
public OptionalDouble asSpeed() {
return parser.map(p -> OptionalDouble.of(p.asSpeed())).orElse(OptionalDouble.empty());
}
/**
* @return {@link Optional#empty()} if the config value is an empty String, otherwise returns an {@link Optional}
* containing the string config value parsed as an acceleration using the declared application time and
* length units.
*
* Acceleration config values can be given either
* - as a double, in which case Config will assume that the value is being specified in meters per second squared
* - in the form {@code ,,} or {@code ::}
*
* @throws NullPointerException if the application time or length units have not been set
* @throws IllegalStateException if the config value does not satisfy one of the formats given above
* @throws IllegalArgumentException if the time or length units in the config value do not match an enum value
* @throws NumberFormatException if the value given cannot be parsed as a double
*/
public OptionalDouble asAcceleration() {
return parser.map(p -> OptionalDouble.of(p.asAcceleration())).orElse(OptionalDouble.empty());
}
/**
* @return {@link Optional#empty()} if the config value is an empty String, otherwise returns an {@link Optional}
* containing the string config value parsed as a jerk using the declared application time and length
* units.
*
* Jerk config values can be given either
* - as a double, in which case Config will assume that the value is being specified in meters per second cubed
* - in the form {@code ,,} or {@code ::}
*
* @throws NullPointerException if the application time or length units have not been set
* @throws IllegalStateException if the config value does not satisfy one of the formats given above
* @throws IllegalArgumentException if the time or length units in the config value do not match an enum value
* @throws NumberFormatException if the value given cannot be parsed as a double
*/
public OptionalDouble asJerk() {
return parser.map(p -> OptionalDouble.of(p.asJerk())).orElse(OptionalDouble.empty());
}
/**
* @return a {@link OptionalListValueParser} operating on the String config value.
*/
public OptionalListValueParser asList() {
return new OptionalListValueParser(parser.map(StrictValueParser::asList));
}
/**
* @return a {@link OptionalSetValueParser} operating on the String config value.
*/
public OptionalSetValueParser asSet() {
return new OptionalSetValueParser(parser.map(StrictValueParser::asSet));
}
/**
* @return a {@link OptionalMapValueParser} operating on the String config value.
*/
public OptionalMapValueParser asMap() {
return new OptionalMapValueParser(parser.map(StrictValueParser::asMap));
}
/**
* @return a {@link OptionalMapValueParser} operating on the String config value.
*/
public OptionalSetMultimapValueParser asSetMultimap() {
return new OptionalSetMultimapValueParser(parser.map(StrictValueParser::asSetMultimap));
}
/**
* @return {@link Optional#empty()} if the config value is an empty String, otherwise returns an {@link Optional}
* containing the the result of the the provided custom parser applied to the config value.
*/
public Optional withCustomParser(Function parser) {
return this.parser.map(p -> p.withCustomParser(parser));
}
/**
* @deprecated to help avoid calling this when {@link OptionalValueParser#asString()} is desired
*/
@Deprecated
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("value", asString().orElse(""))
.toString();
}
}