Package org.dellroad.stuff.string
Class NamedArgumentFormatter
java.lang.Object
org.dellroad.stuff.string.NamedArgumentFormatter
Interpreter for printf-style formatting strings that identifies arguments using names rather than indicies.
Works just like Formatter
but arguments are specified using names instead of numbers.
A mapping from argument name to argument value must be provided during the format operation.
- Since:
- 1.0.64
-
Field Summary
Modifier and TypeFieldDescriptionThe list of argument names in the order they are used.Mapping from argument name to argument list index.protected final String
The modified format string containing indexes instead of argument names.protected final String
The original format string provided to the constructor. -
Constructor Summary
-
Method Summary
-
Field Details
-
fieldList
The list of argument names in the order they are used. This is the inverse mapping offieldMap
. -
fieldMap
Mapping from argument name to argument list index. This is the inverse mapping offieldList
. -
originalFormat
The original format string provided to the constructor. -
indexedFormat
The modified format string containing indexes instead of argument names.
-
-
Constructor Details
-
NamedArgumentFormatter
Constructor.- Parameters:
format
- format string containing argument names instead of indicies
-
-
Method Details
-
format
Format the string using the given arguments.- Parameters:
argMap
- mapping from argument name to argument value- Returns:
- formatted string
- Throws:
IllegalFormatException
- if the format provided to the constructor contained illegal syntaxIllegalFormatException
- if an argument value is incompatible or missing (and null would be invalid)
-
getFormat
Get the original format string provided to the constructor.- Returns:
- original format string
-
getArgumentNames
Get the argument names found in the configured format string.- Returns:
- argument names as a unmodifiable set
-