org.apache.commons.configuration2.interpol.InterpolatorSpecification Maven / Gradle / Ivy
Show all versions of commons-configuration2 Show documentation
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.configuration2.interpol;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.function.Function;
/**
*
* A simple value class defining a {@link ConfigurationInterpolator}.
*
*
* Objects of this class can be used for creating new {@code ConfigurationInterpolator} instances; they contain all
* required properties. It is either possible to set a fully initialized {@code ConfigurationInterpolator} directly
* which can be used as is. Alternatively, some or all properties of an instance to be newly created can be set. These
* properties include
*
*
* - a map with {@code Lookup} objects associated with a specific prefix
* - a collection with default {@code Lookup} objects (without a prefix)
* - a parent {@code ConfigurationInterpolator}
* - a function used to convert interpolated values into strings
*
*
* When setting up a configuration it is possible to define the {@code ConfigurationInterpolator} in terms of this
* class. The configuration will then either use the {@code ConfigurationInterpolator} instance explicitly defined in
* the {@code InterpolatorSpecification} instance or create a new one.
*
*
* Instances are not created directly, but using the nested {@code Builder} class. They are then immutable.
*
*
* @since 2.0
*/
public final class InterpolatorSpecification {
/**
*
* A builder class for creating instances of {@code InterpolatorSpecification}.
*
*
* This class provides a fluent API for defining the various properties of an {@code InterpolatorSpecification} object.
* Note: This builder class is not thread-safe.
*
*/
public static class Builder {
/**
* Helper method for checking a lookup. Throws an exception if the lookup is null.
*
* @param lookup the lookup to be checked
* @throws IllegalArgumentException if the lookup is null
*/
private static void checkLookup(final Lookup lookup) {
if (lookup == null) {
throw new IllegalArgumentException("Lookup must not be null!");
}
}
/** A map with prefix lookups. */
private final Map prefixLookups;
/** A collection with default lookups. */
private final Collection defLookups;
/** The {@code ConfigurationInterpolator}. */
private ConfigurationInterpolator interpolator;
/** The parent {@code ConfigurationInterpolator}. */
private ConfigurationInterpolator parentInterpolator;
/** Function used to convert interpolated values to strings. */
private Function