@Immutable
public final class ValueConverter
extends Object
This is a utility class to help with the conversion of values. It contains only static methods and constant attributes.
| Modifier and Type | Field and Description |
|---|---|
static int |
ONE_MEBIBYTE
One mebibyte (SI).
|
| Modifier and Type | Method and Description |
|---|---|
static String |
canonicalizePath(String path)
Canonicalize a path.
|
static Optional<String> |
canonicalizeString(Optional<String> text)
Canonicalizes a text string.
|
static boolean |
convertToBoolean(String type,
String name,
Optional<String> valueToConvert,
boolean defaultValue)
Converts a named boolean value, providing a default.
|
static Optional<Boolean> |
convertToBoolean(String type,
String name,
Optional<String> valueToConvert,
Optional<Boolean> defaultValue)
Converts a named boolean value, providing a default.
|
static double |
convertToDouble(String type,
String name,
Optional<String> valueToConvert,
double defaultValue)
Converts a named double value, providing a default.
|
static Optional<Double> |
convertToDouble(String type,
String name,
Optional<String> valueToConvert,
Optional<Double> defaultValue)
Converts a named double value, providing a default.
|
static int |
convertToInt(String type,
String name,
Optional<String> valueToConvert,
int defaultValue)
Converts a named int value, providing a default.
|
static Optional<Integer> |
convertToInteger(String type,
String name,
Optional<String> valueToConvert,
Optional<Integer> defaultValue)
Converts a named int value, providing a default.
|
static long |
convertToLong(String type,
String name,
Optional<String> valueToConvert,
long defaultValue)
Converts a named long value, providing a default.
|
static Optional<Long> |
convertToLong(String type,
String name,
Optional<String> valueToConvert,
Optional<Long> defaultValue)
Converts a named long value, providing a default.
|
static boolean |
isCanonical(Optional<String> text)
Asks if a text has a canonical form.
|
static boolean |
isFalse(String value)
Asks if a value matches the 'false' pattern.
|
static boolean |
isTrue(String value)
Asks if a value matches the 'true' pattern.
|
static long |
roundToMebibytes(long bytes)
Rounds bytes to mebibytes.
|
static String[] |
splitFields(String fields)
Split fields separated by comma or spaces.
|
static String[] |
splitFields(String fields,
int max)
Split fields separated by comma or spaces.
|
static Integer |
toInteger(boolean value)
Converts a boolean to an Integer object.
|
static Pattern |
wildToPattern(String wild)
Converts a String allowed to contain wild characters to a Pattern.
|
public static final int ONE_MEBIBYTE
@Nonnull
@CheckReturnValue
public static String canonicalizePath(@Nonnull
String path)
throws IOException
Makes the path canonical. On Windows, replaces the back slashes with forward slashes.
path - The path.IOException - On failure.@Nonnull
@CheckReturnValue
public static Optional<String> canonicalizeString(@Nonnull
Optional<String> text)
Uses Unicode canonical decomposition followed by canonical composition to ensure a consistent text representation.
text - The optional text string.@CheckReturnValue
public static boolean convertToBoolean(@Nonnull
String type,
@Nonnull
String name,
@Nonnull
Optional<String> valueToConvert,
boolean defaultValue)
type - The type of value (for logging purpose).name - The name of the value (for logging purpose).valueToConvert - The value to convert (may be empty).defaultValue - The default value.@Nonnull
@CheckReturnValue
public static Optional<Boolean> convertToBoolean(@Nonnull
String type,
@Nonnull
String name,
@Nonnull
Optional<String> valueToConvert,
@Nonnull
Optional<Boolean> defaultValue)
The following values will be interpreted as true (ignoring case):
The following values will be interpreted as false (ignoring case):
If the value is null or does not match one of the recognized values, the default will be returned.
type - The type of value (for logging purpose).name - The name of the value (for logging purpose).valueToConvert - The value to convert (may be empty).defaultValue - The default value (may be empty).@CheckReturnValue
public static double convertToDouble(@Nonnull
String type,
@Nonnull
String name,
@Nonnull
Optional<String> valueToConvert,
double defaultValue)
If the value is null, empty or unrecognized, the default will be returned.
type - The type of value (for logging purpose).name - The name of the value (for logging purpose).valueToConvert - The value to convert (may be empty).defaultValue - The default value.@Nonnull
@CheckReturnValue
public static Optional<Double> convertToDouble(@Nonnull
String type,
@Nonnull
String name,
@Nonnull
Optional<String> valueToConvert,
@Nonnull
Optional<Double> defaultValue)
If the value is null, empty or unrecognized, the default will be returned.
type - The type of value (for logging purpose).name - The name of the value (for logging purpose).valueToConvert - The value to convert (may be empty).defaultValue - The default value (may be empty).@CheckReturnValue
public static int convertToInt(@Nonnull
String type,
@Nonnull
String name,
@Nonnull
Optional<String> valueToConvert,
int defaultValue)
If the value is null, empty or unrecognized, the default will be returned.
type - The type of value (for logging purpose).name - The name of the value (for logging purpose).valueToConvert - The value to convert (may be null).defaultValue - The default value.@Nonnull
@CheckReturnValue
public static Optional<Integer> convertToInteger(@Nonnull
String type,
@Nonnull
String name,
@Nonnull
Optional<String> valueToConvert,
@Nonnull
Optional<Integer> defaultValue)
If the value is null, empty or unrecognized, the default will be returned.
type - The type of value (for logging purpose).name - The name of the value (for logging purpose).valueToConvert - The value to convert (may be empty).defaultValue - The default value (may be empty).@CheckReturnValue
public static long convertToLong(@Nonnull
String type,
@Nonnull
String name,
@Nonnull
Optional<String> valueToConvert,
long defaultValue)
If the value is null, empty or unrecognized, the default will be returned.
type - The type of value (for logging purpose).name - The name of the value (for logging purpose).valueToConvert - The value to convert (may be empty).defaultValue - The default value.@CheckReturnValue
public static Optional<Long> convertToLong(@Nonnull
String type,
@Nonnull
String name,
@Nonnull
Optional<String> valueToConvert,
@Nonnull
Optional<Long> defaultValue)
If the value is empty or unrecognized, the default will be returned.
type - The type of value (for logging purpose).name - The name of the value (for logging purpose).valueToConvert - The value to convert (may be empty).defaultValue - The default value (may be empty).@CheckReturnValue
public static boolean isCanonical(@Nonnull
Optional<String> text)
text - The text.@CheckReturnValue
public static boolean isFalse(@Nonnull
String value)
value - The value.@CheckReturnValue
public static boolean isTrue(@Nonnull
String value)
value - The value.@CheckReturnValue public static long roundToMebibytes(long bytes)
bytes - A bytes count.@Nonnull
@CheckReturnValue
public static String[] splitFields(@Nonnull
String fields)
fields - The fields.@Nonnull
@CheckReturnValue
public static String[] splitFields(@Nonnull
String fields,
int max)
fields - The fields.max - The maximum number of fields to separate.@Nonnull @CheckReturnValue public static Integer toInteger(boolean value)
value - The boolean value.@Nonnull
@CheckReturnValue
public static Pattern wildToPattern(@Nonnull
String wild)
wild - The 'wild' test.Copyright © 2003-2019 Serge Brisson. All Rights Reserved.