Class InterpolatorSpecification.Builder
- java.lang.Object
-
- org.apache.commons.configuration2.interpol.InterpolatorSpecification.Builder
-
- Enclosing class:
- InterpolatorSpecification
public static class InterpolatorSpecification.Builder extends java.lang.Object
A builder class for creating instances of
InterpolatorSpecification
.This class provides a fluent API for defining the various properties of an
InterpolatorSpecification
object. Note: This builder class is not thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Collection<Lookup>
defLookups
A collection with default lookups.private ConfigurationInterpolator
interpolator
TheConfigurationInterpolator
.private ConfigurationInterpolator
parentInterpolator
The parentConfigurationInterpolator
.private java.util.Map<java.lang.String,Lookup>
prefixLookups
A map with prefix lookups.private java.util.function.Function<java.lang.Object,java.lang.String>
stringConverter
Function used to convert interpolated values to strings.
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkLookup(Lookup lookup)
Helper method for checking a lookup.InterpolatorSpecification
create()
Creates a newInterpolatorSpecification
instance with the properties set so far.void
reset()
Removes all data from this builder.InterpolatorSpecification.Builder
withDefaultLookup(Lookup lookup)
Adds the givenLookup
object to the list of default lookups.InterpolatorSpecification.Builder
withDefaultLookups(java.util.Collection<? extends Lookup> lookups)
Adds the content of the given collection to the default lookups managed by this builder.InterpolatorSpecification.Builder
withInterpolator(ConfigurationInterpolator ci)
Sets theConfigurationInterpolator
instance for theInterpolatorSpecification
.InterpolatorSpecification.Builder
withParentInterpolator(ConfigurationInterpolator parent)
Sets an optional parentConfigurationInterpolator
.InterpolatorSpecification.Builder
withPrefixLookup(java.lang.String prefix, Lookup lookup)
Adds aLookup
object for a given prefix.InterpolatorSpecification.Builder
withPrefixLookups(java.util.Map<java.lang.String,? extends Lookup> lookups)
Adds the content of the given map to the prefix lookups managed by this builder.InterpolatorSpecification.Builder
withStringConverter(java.util.function.Function<java.lang.Object,java.lang.String> fn)
Sets the function used to convert interpolated values to strings.
-
-
-
Field Detail
-
prefixLookups
private final java.util.Map<java.lang.String,Lookup> prefixLookups
A map with prefix lookups.
-
defLookups
private final java.util.Collection<Lookup> defLookups
A collection with default lookups.
-
interpolator
private ConfigurationInterpolator interpolator
TheConfigurationInterpolator
.
-
parentInterpolator
private ConfigurationInterpolator parentInterpolator
The parentConfigurationInterpolator
.
-
stringConverter
private java.util.function.Function<java.lang.Object,java.lang.String> stringConverter
Function used to convert interpolated values to strings.
-
-
Method Detail
-
checkLookup
private static void checkLookup(Lookup lookup)
Helper method for checking a lookup. Throws an exception if the lookup is null.- Parameters:
lookup
- the lookup to be checked- Throws:
java.lang.IllegalArgumentException
- if the lookup is null
-
create
public InterpolatorSpecification create()
Creates a newInterpolatorSpecification
instance with the properties set so far. After that this builder instance is reset so that it can be reused for creating further specification objects.- Returns:
- the newly created
InterpolatorSpecification
-
reset
public void reset()
Removes all data from this builder. Afterwards it can be used to define a brand newInterpolatorSpecification
object.
-
withDefaultLookup
public InterpolatorSpecification.Builder withDefaultLookup(Lookup lookup)
Adds the givenLookup
object to the list of default lookups.- Parameters:
lookup
- theLookup
(must not be null)- Returns:
- a reference to this builder for method chaining
- Throws:
java.lang.IllegalArgumentException
- if theLookup
is null
-
withDefaultLookups
public InterpolatorSpecification.Builder withDefaultLookups(java.util.Collection<? extends Lookup> lookups)
Adds the content of the given collection to the default lookups managed by this builder. The collection can be null, then this method has no effect.- Parameters:
lookups
- the collection with lookups to be added- Returns:
- a reference to this builder for method chaining
- Throws:
java.lang.IllegalArgumentException
- if the collection contains null entries
-
withInterpolator
public InterpolatorSpecification.Builder withInterpolator(ConfigurationInterpolator ci)
Sets theConfigurationInterpolator
instance for theInterpolatorSpecification
. This means that aConfigurationInterpolator
has been created and set up externally and can be used directly.- Parameters:
ci
- theConfigurationInterpolator
(can be null)- Returns:
- a reference to this builder for method chaining
-
withParentInterpolator
public InterpolatorSpecification.Builder withParentInterpolator(ConfigurationInterpolator parent)
Sets an optional parentConfigurationInterpolator
. If defined, this object is set as parent of a newly createdConfigurationInterpolator
instance.- Parameters:
parent
- the parentConfigurationInterpolator
(can be null)- Returns:
- a reference to this builder for method chaining
-
withPrefixLookup
public InterpolatorSpecification.Builder withPrefixLookup(java.lang.String prefix, Lookup lookup)
Adds aLookup
object for a given prefix.- Parameters:
prefix
- the prefix (must not be null)lookup
- theLookup
(must not be null)- Returns:
- a reference to this builder for method chaining
- Throws:
java.lang.IllegalArgumentException
- if a required parameter is missing
-
withPrefixLookups
public InterpolatorSpecification.Builder withPrefixLookups(java.util.Map<java.lang.String,? extends Lookup> lookups)
Adds the content of the given map to the prefix lookups managed by this builder. The map can be null, then this method has no effect.- Parameters:
lookups
- the map with prefix lookups to be added- Returns:
- a reference to this builder for method chaining
- Throws:
java.lang.IllegalArgumentException
- if the map contains null values
-
withStringConverter
public InterpolatorSpecification.Builder withStringConverter(java.util.function.Function<java.lang.Object,java.lang.String> fn)
Sets the function used to convert interpolated values to strings. Passnull
if the default conversion function is to be used.- Parameters:
fn
- function used to convert interpolated values to string ornull
if the default conversion function is to be used- Returns:
- a reference to this builder for method chaining
-
-