Class StringSetting
- All Implemented Interfaces:
Supplier<String>,OptionalSupplier<String>
Setting for string values that provides convenience methods for type conversion.
This class extends Setting with type-specific conversion methods such as asInteger(),
asBoolean(), asCharset(), etc.
-
Constructor Summary
ConstructorsConstructorDescriptionStringSetting(Settings settings, Supplier<String> supplier) Creates a new StringSetting from a Settings instance and a Supplier. -
Method Summary
Modifier and TypeMethodDescriptionConverts the string value to a Boolean.Converts the string value to a Charset.asDouble()Converts the string value to a Double.asFile()Converts the string value to a File.asFloat()Converts the string value to a Float.Converts the string value to an Integer.asLong()Converts the string value to a Long.asPath()Converts the string value to a Path.<T> Setting<T>Converts the string value to the specified type using the Settings type conversion functions.asURI()Converts the string value to a URI.If a value is present, and the value matches the given predicate, returns a StringSetting describing the value, otherwise returns an empty StringSetting.If a value is present, applies the provided mapping function to it and returns a StringSetting describing the result.Methods inherited from class org.apache.juneau.commons.settings.Setting
asOptional, getSettings, mapMethods inherited from class org.apache.juneau.commons.function.ResettableSupplier
copy, get, isSupplied, reset, setMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.juneau.commons.function.OptionalSupplier
flatMap, ifPresent, ifPresentOrElse, isEmpty, isPresent, orElse, orElseGet, orElseThrow, toOptional
-
Constructor Details
-
StringSetting
Creates a new StringSetting from a Settings instance and a Supplier.- Parameters:
settings- The Settings instance that created this setting. Must not benull .supplier- The supplier that provides the string value. Must not benull .
-
-
Method Details
-
mapString
If a value is present, applies the provided mapping function to it and returns a StringSetting describing the result.This method is specifically for String-to-String mappings. For mappings to other types, use the inherited
Setting.map(Function)method.The returned StringSetting maintains its own cache, independent of this supplier. Resetting the mapped supplier does not affect this supplier, and vice versa.
- Parameters:
mapper- A mapping function to apply to the value, if present. Must not benull .- Returns:
- A StringSetting describing the result of applying a mapping function to the value of this StringSetting, if a value is present, otherwise an empty StringSetting.
-
filter
If a value is present, and the value matches the given predicate, returns a StringSetting describing the value, otherwise returns an empty StringSetting.The returned StringSetting maintains its own cache, independent of this supplier. Resetting the filtered supplier does not affect this supplier, and vice versa.
- Specified by:
filterin interfaceOptionalSupplier<String>- Overrides:
filterin classSetting<String>- Parameters:
predicate- A predicate to apply to the value, if present. Must not benull .- Returns:
- A StringSetting describing the value of this StringSetting if a value is present and the value matches the given predicate, otherwise an empty StringSetting.
-
asInteger
Converts the string value to an Integer.The property value is parsed using
Integer.valueOf(String). If the property is not found or cannot be parsed as an integer, returnsOptional.empty().- Returns:
- The property value as an Integer, or
Optional.empty()if not found or not a valid integer.
-
asLong
Converts the string value to a Long.The property value is parsed using
Long.valueOf(String). If the property is not found or cannot be parsed as a long, returnsOptional.empty().- Returns:
- The property value as a Long, or
Optional.empty()if not found or not a valid long.
-
asBoolean
Converts the string value to a Boolean.The property value is parsed using
Boolean.parseBoolean(String), which returnstrue if the value is (case-insensitive) "true", otherwisefalse . Note that this method will returnOptional.of(false) for any non-empty value that is not "true", andOptional.empty()only if the property is not set.- Returns:
- The property value as a Boolean, or
Optional.empty()if not found.
-
asDouble
Converts the string value to a Double.The property value is parsed using
Double.valueOf(String). If the property is not found or cannot be parsed as a double, returnsOptional.empty().- Returns:
- The property value as a Double, or
Optional.empty()if not found or not a valid double.
-
asFloat
Converts the string value to a Float.The property value is parsed using
Float.valueOf(String). If the property is not found or cannot be parsed as a float, returnsOptional.empty().- Returns:
- The property value as a Float, or
Optional.empty()if not found or not a valid float.
-
asFile
Converts the string value to a File.The property value is converted to a
Fileusing theFile(String)constructor. If the property is not found, returnsOptional.empty(). Note that this method does not validate that the file path is valid or that the file exists.- Returns:
- The property value as a File, or
Optional.empty()if not found.
-
asPath
Converts the string value to a Path.The property value is converted to a
PathusingPaths.get(String, String...). If the property is not found or the path string is invalid, returnsOptional.empty().- Returns:
- The property value as a Path, or
Optional.empty()if not found or not a valid path.
-
asURI
Converts the string value to a URI.The property value is converted to a
URIusingURI.create(String). If the property is not found or the URI string is invalid, returnsOptional.empty().- Returns:
- The property value as a URI, or
Optional.empty()if not found or not a valid URI.
-
asCharset
Converts the string value to a Charset.The property value is converted to a
CharsetusingCharset.forName(String). If the property is not found or the charset name is not supported, returnsOptional.empty().- Returns:
- The property value as a Charset, or
Optional.empty()if not found or not a valid charset.
-
asType
Converts the string value to the specified type using the Settings type conversion functions.The property value is converted using
Settings.toType(String, Class). If the property is not found or cannot be converted to the specified type, returnsOptional.empty().- Type Parameters:
T- The target type.- Parameters:
c- The target class. Must not benull .- Returns:
- The property value as the specified type, or
Optional.empty()if not found or not a valid conversion.
-