ImmutableConfiguration.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.configuration2;

  18. import java.math.BigDecimal;
  19. import java.math.BigInteger;
  20. import java.time.Duration;
  21. import java.util.Collection;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import java.util.NoSuchElementException;
  25. import java.util.Objects;
  26. import java.util.Properties;

  27. import org.apache.commons.configuration2.convert.PropertyConverter;
  28. import org.apache.commons.configuration2.ex.ConversionException;

  29. /**
  30.  * <p>
  31.  * The main interface for accessing configuration data in a read-only fashion.
  32.  * </p>
  33.  * <p>
  34.  * The major part of the methods defined in this interface deals with accessing properties of various data types. There
  35.  * is a generic {@code getProperty()} method, which returns the value of the queried property in its raw data type.
  36.  * Other getter methods try to convert this raw data type into a specific data type. If this fails, a
  37.  * {@code ConversionException} will be thrown.
  38.  * </p>
  39.  * <p>
  40.  * For most of the property getter methods an overloaded version exists that allows to specify a default value, which
  41.  * will be returned if the queried property cannot be found in the configuration. The behavior of the methods that do
  42.  * not take a default value in case of a missing property is not defined by this interface and depends on a concrete
  43.  * implementation. E.g. the {@link AbstractConfiguration} class, which is the base class of most configuration
  44.  * implementations provided by this package, per default returns <strong>null</strong> if a property is not found, but provides
  45.  * the {@link AbstractConfiguration#setThrowExceptionOnMissing(boolean) setThrowExceptionOnMissing()} method, with which
  46.  * it can be configured to throw a {@code NoSuchElementException} exception in that case. (Note that getter methods for
  47.  * primitive types in {@code AbstractConfiguration} always throw an exception for missing properties because there is no
  48.  * way of overloading the return value.)
  49.  * </p>
  50.  *
  51.  * @since 2.0
  52.  */
  53. public interface ImmutableConfiguration {
  54.     /**
  55.      * Checks if the configuration contains the specified key.
  56.      *
  57.      * @param key the key whose presence in this configuration is to be tested
  58.      * @return {@code true} if the configuration contains a value for this key, {@code false} otherwise
  59.      */
  60.     boolean containsKey(String key);

  61.     /**
  62.      * Tests whether this configuration contains one or more matches to this value. This operation stops at first
  63.      * match but may be more expensive than the {@link #containsKey containsKey} method.
  64.      *
  65.      * @param value value whose presence in this configuration is to be tested
  66.      * @return {@code true} if this configuration maps one or more keys to the specified value, false otherwise.
  67.      * @since 2.11.0
  68.      */
  69.     default boolean containsValue(final Object value) {
  70.         final Iterator<String> keys = getKeys();
  71.         while (keys.hasNext()) {
  72.             if (Objects.equals(value, getProperty(keys.next()))) {
  73.                 return true;
  74.             }
  75.         }
  76.         return false;
  77.     }

  78.     /**
  79.      * Gets an object of the specified type associated with the given configuration key. If the key doesn't map to an
  80.      * existing object, the method returns null unless {@link AbstractConfiguration#isThrowExceptionOnMissing()} is set to
  81.      * {@code true}.
  82.      *
  83.      * @param <T> the target type of the value
  84.      * @param cls the target class of the value
  85.      * @param key the key of the value
  86.      * @return the value of the requested type for the key
  87.      * @throws java.util.NoSuchElementException if the key doesn't map to an existing object and
  88.      *         {@code throwExceptionOnMissing=true}
  89.      * @throws org.apache.commons.configuration2.ex.ConversionException if the value is not compatible with the requested
  90.      *         type
  91.      * @since 2.0
  92.      */
  93.     <T> T get(Class<T> cls, String key);

  94.     /**
  95.      * Gets an object of the specified type associated with the given configuration key using a default value. If the key
  96.      * doesn't map to an existing object, the default value is returned.
  97.      *
  98.      * @param <T> the target type of the value
  99.      * @param cls the target class of the value
  100.      * @param key the key of the value
  101.      * @param defaultValue the default value
  102.      * @return the value of the requested type for the key
  103.      * @throws org.apache.commons.configuration2.ex.ConversionException if the value is not compatible with the requested
  104.      *         type
  105.      *
  106.      * @since 2.0
  107.      */
  108.     <T> T get(Class<T> cls, String key, T defaultValue);

  109.     /**
  110.      * Gets an array of typed objects associated with the given configuration key. If the key doesn't map to an existing
  111.      * object, an empty list is returned.
  112.      *
  113.      * @param cls the type expected for the elements of the array
  114.      * @param key The configuration key.
  115.      * @return The associated array if the key is found, and the value compatible with the type specified.
  116.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not
  117.      *         compatible with a list of the specified class.
  118.      *
  119.      * @since 2.0
  120.      */
  121.     Object getArray(Class<?> cls, String key);

  122.     /**
  123.      * Gets an array of typed objects associated with the given configuration key. If the key doesn't map to an existing
  124.      * object, the default value is returned.
  125.      *
  126.      * @param cls the type expected for the elements of the array
  127.      * @param key the configuration key.
  128.      * @param defaultValue the default value
  129.      * @return The associated array if the key is found, and the value compatible with the type specified.
  130.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not
  131.      *         compatible with an array of the specified class.
  132.      * @throws IllegalArgumentException if the default value is not an array of the specified type
  133.      * @since 2.0
  134.      * @deprecated This method should not be used any more because its signature does not allow type-safe invocations; use
  135.      *             {@link #get(Class, String, Object)} instead which offers the same functionality; for instance, to query
  136.      *             for an array of ints use {@code int[] result = config.get(int[].class, "myArrayKey", someDefault);}.
  137.      */
  138.     @Deprecated
  139.     Object getArray(Class<?> cls, String key, Object defaultValue);

  140.     /**
  141.      * Gets a {@link BigDecimal} associated with the given configuration key.
  142.      *
  143.      * @param key The configuration key.
  144.      * @return The associated BigDecimal if key is found and has valid format
  145.      */
  146.     BigDecimal getBigDecimal(String key);

  147.     /**
  148.      * Gets a {@link BigDecimal} associated with the given configuration key. If the key doesn't map to an existing object,
  149.      * the default value is returned.
  150.      *
  151.      * @param key The configuration key.
  152.      * @param defaultValue The default value.
  153.      * @return The associated BigDecimal if key is found and has valid format, default value otherwise.
  154.      */
  155.     BigDecimal getBigDecimal(String key, BigDecimal defaultValue);

  156.     /**
  157.      * Gets a {@link BigInteger} associated with the given configuration key.
  158.      *
  159.      * @param key The configuration key.
  160.      * @return The associated BigInteger if key is found and has valid format
  161.      */
  162.     BigInteger getBigInteger(String key);

  163.     /**
  164.      * Gets a {@link BigInteger} associated with the given configuration key. If the key doesn't map to an existing object,
  165.      * the default value is returned.
  166.      *
  167.      * @param key The configuration key.
  168.      * @param defaultValue The default value.
  169.      * @return The associated BigInteger if key is found and has valid format, default value otherwise.
  170.      */
  171.     BigInteger getBigInteger(String key, BigInteger defaultValue);

  172.     /**
  173.      * Gets a boolean associated with the given configuration key.
  174.      *
  175.      * @param key The configuration key.
  176.      * @return The associated boolean.
  177.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  178.      *         Boolean.
  179.      */
  180.     boolean getBoolean(String key);

  181.     /**
  182.      * Gets a boolean associated with the given configuration key. If the key doesn't map to an existing object, the default
  183.      * value is returned.
  184.      *
  185.      * @param key The configuration key.
  186.      * @param defaultValue The default value.
  187.      * @return The associated boolean.
  188.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  189.      *         Boolean.
  190.      */
  191.     boolean getBoolean(String key, boolean defaultValue);

  192.     /**
  193.      * Gets a {@link Boolean} associated with the given configuration key.
  194.      *
  195.      * @param key The configuration key.
  196.      * @param defaultValue The default value.
  197.      * @return The associated boolean if key is found and has valid format, default value otherwise.
  198.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  199.      *         Boolean.
  200.      */
  201.     Boolean getBoolean(String key, Boolean defaultValue);

  202.     /**
  203.      * Gets a byte associated with the given configuration key.
  204.      *
  205.      * @param key The configuration key.
  206.      * @return The associated byte.
  207.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  208.      *         Byte.
  209.      */
  210.     byte getByte(String key);

  211.     /**
  212.      * Gets a byte associated with the given configuration key. If the key doesn't map to an existing object, the default
  213.      * value is returned.
  214.      *
  215.      * @param key The configuration key.
  216.      * @param defaultValue The default value.
  217.      * @return The associated byte.
  218.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  219.      *         Byte.
  220.      */
  221.     byte getByte(String key, byte defaultValue);

  222.     /**
  223.      * Gets a {@link Byte} associated with the given configuration key.
  224.      *
  225.      * @param key The configuration key.
  226.      * @param defaultValue The default value.
  227.      * @return The associated byte if key is found and has valid format, default value otherwise.
  228.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  229.      *         Byte.
  230.      */
  231.     Byte getByte(String key, Byte defaultValue);

  232.     /**
  233.      * Gets a collection of typed objects associated with the given configuration key. This method works like
  234.      * {@link #getCollection(Class, String, Collection, Collection)} passing in <strong>null</strong> as default value.
  235.      *
  236.      * @param <T> the element type of the result list
  237.      * @param cls the element class of the result list
  238.      * @param key the configuration key
  239.      * @param target the target collection (may be <strong>null</strong>)
  240.      * @return the collection to which data was added
  241.      * @throws org.apache.commons.configuration2.ex.ConversionException if the conversion is not possible
  242.      * @since 2.0
  243.      */
  244.     <T> Collection<T> getCollection(Class<T> cls, String key, Collection<T> target);

  245.     /**
  246.      * Gets a collection of typed objects associated with the given configuration key using the values in the specified
  247.      * default collection if the key does not map to an existing object. This method is similar to {@code getList()},
  248.      * however, it allows specifying a target collection. Results are added to this collection. This is useful if the data
  249.      * retrieved should be added to a specific kind of collection, for example a set to remove duplicates. The return value is as
  250.      * follows:
  251.      * <ul>
  252.      * <li>If the key does not map to an existing object and the default value is <strong>null</strong>, the method returns
  253.      * <strong>null</strong>.</li>
  254.      * <li>If the target collection is not <strong>null</strong> and data has been added (either from the resolved property value or
  255.      * from the default collection), the target collection is returned.</li>
  256.      * <li>If the target collection is <strong>null</strong> and data has been added (either from the resolved property value or from
  257.      * the default collection), return value is the target collection created by this method.</li>
  258.      * </ul>
  259.      *
  260.      * @param <T> the element type of the result list
  261.      * @param cls the element class of the result list
  262.      * @param key the configuration key
  263.      * @param target the target collection (may be <strong>null</strong>)
  264.      * @param defaultValue the default value (may be <strong>null</strong>)
  265.      * @return the collection to which data was added
  266.      * @throws org.apache.commons.configuration2.ex.ConversionException if the conversion is not possible
  267.      * @since 2.0
  268.      */
  269.     <T> Collection<T> getCollection(Class<T> cls, String key, Collection<T> target, Collection<T> defaultValue);

  270.     /**
  271.      * Gets a double associated with the given configuration key.
  272.      *
  273.      * @param key The configuration key.
  274.      * @return The associated double.
  275.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  276.      *         Double.
  277.      */
  278.     double getDouble(String key);

  279.     /**
  280.      * Gets a double associated with the given configuration key. If the key doesn't map to an existing object, the default
  281.      * value is returned.
  282.      *
  283.      * @param key The configuration key.
  284.      * @param defaultValue The default value.
  285.      * @return The associated double.
  286.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  287.      *         Double.
  288.      */
  289.     double getDouble(String key, double defaultValue);

  290.     /**
  291.      * Gets a {@link Double} associated with the given configuration key.
  292.      *
  293.      * @param key The configuration key.
  294.      * @param defaultValue The default value.
  295.      * @return The associated double if key is found and has valid format, default value otherwise.
  296.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  297.      *         Double.
  298.      */
  299.     Double getDouble(String key, Double defaultValue);

  300.     /**
  301.      * Gets a {@link Duration} associated with the given configuration key.
  302.      *
  303.      * @param key The configuration key.
  304.      * @return The associated Duration if key is found and has valid format, default value otherwise.
  305.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  306.      *         Duration.
  307.      * @since 2.8.0
  308.      */
  309.     default Duration getDuration(final String key) {
  310.         final String string = getString(key);
  311.         if (string == null) {
  312.             throw new NoSuchElementException(key);
  313.         }
  314.         return PropertyConverter.toDuration(string);
  315.     }

  316.     /**
  317.      * Gets a {@link Duration} associated with the given configuration key.
  318.      *
  319.      * @param key The configuration key.
  320.      * @param defaultValue The default value.
  321.      * @return The associated Duration if key is found and has valid format, default value otherwise.
  322.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  323.      *         Duration.
  324.      * @since 2.8.0
  325.      */
  326.     default Duration getDuration(final String key, final Duration defaultValue) {
  327.         final Object value = getProperty(key);
  328.         return value == null ? defaultValue : PropertyConverter.toDuration(value);
  329.     }

  330.     /**
  331.      * Gets the value of a string property that is stored in encoded form in this configuration using a default
  332.      * {@code ConfigurationDecoder}. This method works like the method with the same name, but it uses a default
  333.      * {@code ConfigurationDecoder} associated with this configuration. It depends on a specific implementation how this
  334.      * default decoder is obtained.
  335.      *
  336.      * @param key the configuration key
  337.      * @return the plain string value of the specified encoded property
  338.      */
  339.     String getEncodedString(String key);

  340.     /**
  341.      * Gets the value of a string property that is stored in encoded form in this configuration. This method obtains the
  342.      * value of the string property identified by the given key. This value is then passed to the provided
  343.      * {@code ConfigurationDecoder}. The value returned by the {@code ConfigurationDecoder} is passed to the caller. If the
  344.      * key is not associated with a value, the decoder is not invoked; depending on this configuration's settings either
  345.      * <strong>null</strong> is returned or an exception is thrown.
  346.      *
  347.      * @param key the configuration key
  348.      * @param decoder the {@code ConfigurationDecoder} (must not be <strong>null</strong>)
  349.      * @return the plain string value of the specified encoded property
  350.      * @throws IllegalArgumentException if a <strong>null</strong> decoder is passed
  351.      */
  352.     String getEncodedString(String key, ConfigurationDecoder decoder);

  353.     /**
  354.      * Gets an enum associated with the given configuration key.
  355.      *
  356.      * @param <T> The enum type whose constant is to be returned.
  357.      * @param enumType the {@code Class} object of the enum type from which to return a constant
  358.      * @param key The configuration key.
  359.      * @return The associated enum.
  360.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  361.      *         String.
  362.      * @since 2.8.0
  363.      */
  364.     default <T extends Enum<T>> T getEnum(final String key, final Class<T> enumType) {
  365.         try {
  366.             return Enum.valueOf(enumType, getString(key));
  367.         } catch (final IllegalArgumentException e) {
  368.             throw new ConversionException(e);
  369.         }
  370.     }

  371.     /**
  372.      * Gets the enum associated with the given configuration key. If the key doesn't map to an existing object, the default
  373.      * value is returned.
  374.      *
  375.      * @param <T> The enum type whose constant is to be returned.
  376.      * @param key The configuration key.
  377.      * @param enumType the {@code Class} object of the enum type from which to return a constant
  378.      * @param defaultValue The default value.
  379.      * @return The associated enum if key is found and has valid format, default value otherwise.
  380.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  381.      *         Enum.
  382.      * @since 2.8.0
  383.      */
  384.     default <T extends Enum<T>> T getEnum(final String key, final Class<T> enumType, final T defaultValue) {
  385.         final String strValue = getString(key, null);
  386.         if (strValue == null) {
  387.             return defaultValue;
  388.         }
  389.         try {
  390.             return Enum.valueOf(enumType, strValue);
  391.         } catch (final IllegalArgumentException e) {
  392.             throw new ConversionException(e);
  393.         }
  394.     }

  395.     /**
  396.      * Gets a float associated with the given configuration key.
  397.      *
  398.      * @param key The configuration key.
  399.      * @return The associated float.
  400.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  401.      *         Float.
  402.      */
  403.     float getFloat(String key);

  404.     /**
  405.      * Gets a float associated with the given configuration key. If the key doesn't map to an existing object, the default
  406.      * value is returned.
  407.      *
  408.      * @param key The configuration key.
  409.      * @param defaultValue The default value.
  410.      * @return The associated float.
  411.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  412.      *         Float.
  413.      */
  414.     float getFloat(String key, float defaultValue);

  415.     /**
  416.      * Gets a {@link Float} associated with the given configuration key. If the key doesn't map to an existing object, the
  417.      * default value is returned.
  418.      *
  419.      * @param key The configuration key.
  420.      * @param defaultValue The default value.
  421.      * @return The associated float if key is found and has valid format, default value otherwise.
  422.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  423.      *         Float.
  424.      */
  425.     Float getFloat(String key, Float defaultValue);

  426.     /**
  427.      * Gets a int associated with the given configuration key.
  428.      *
  429.      * @param key The configuration key.
  430.      * @return The associated int.
  431.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  432.      *         Integer.
  433.      */
  434.     int getInt(String key);

  435.     /**
  436.      * Gets a int associated with the given configuration key. If the key doesn't map to an existing object, the default
  437.      * value is returned.
  438.      *
  439.      * @param key The configuration key.
  440.      * @param defaultValue The default value.
  441.      * @return The associated int.
  442.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  443.      *         Integer.
  444.      */
  445.     int getInt(String key, int defaultValue);

  446.     /**
  447.      * Gets an {@link Integer} associated with the given configuration key. If the key doesn't map to an existing object,
  448.      * the default value is returned.
  449.      *
  450.      * @param key The configuration key.
  451.      * @param defaultValue The default value.
  452.      * @return The associated int if key is found and has valid format, default value otherwise.
  453.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  454.      *         Integer.
  455.      */
  456.     Integer getInteger(String key, Integer defaultValue);

  457.     /**
  458.      * Gets the list of the keys contained in the configuration. The returned iterator can be used to obtain all defined
  459.      * keys. It does not allow removing elements from this configuration via its {@code remove()} method. Note that the keys
  460.      * of this configuration are returned in a form, so that they can be directly evaluated; escaping of special characters
  461.      * (if necessary) has already been performed.
  462.      *
  463.      * @return An Iterator.
  464.      */
  465.     Iterator<String> getKeys();

  466.     /**
  467.      * Gets the list of the keys contained in the configuration that match the specified prefix. For instance, if the
  468.      * configuration contains the following keys:<br>
  469.      * {@code db.user, db.pwd, db.url, window.xpos, window.ypos},<br>
  470.      * an invocation of {@code getKeys("db");}<br>
  471.      * will return the keys below:<br>
  472.      * {@code db.user, db.pwd, db.url}.<br>
  473.      * Note that the prefix itself is included in the result set if there is a matching key. The exact behavior - how the
  474.      * prefix is actually interpreted - depends on a concrete implementation.
  475.      *
  476.      * @param prefix The prefix to test against.
  477.      * @return An Iterator of keys that match the prefix.
  478.      * @see #getKeys()
  479.      */
  480.     Iterator<String> getKeys(String prefix);

  481.     /**
  482.      * Gets the list of the keys contained in the configuration that match the specified prefix. For instance, if the
  483.      * configuration contains the following keys:<br>
  484.      * {@code db@user, db@pwd, db@url, window.xpos, window.ypos},<br>
  485.      * an invocation of {@code getKeys("db","@");}<br>
  486.      * will return the keys below:<br>
  487.      * {@code db@user, db@pwd, db@url}.<br>
  488.      * Note that the prefix itself is included in the result set if there is a matching key. The exact behavior - how the
  489.      * prefix is actually interpreted - depends on a concrete implementation.
  490.      *
  491.      * @param prefix The prefix to test against.
  492.      * @param delimiter The prefix delimiter.
  493.      * @return An Iterator of keys that match the prefix.
  494.      * @see #getKeys()
  495.      * @since 2.10.0
  496.      */
  497.     default Iterator<String> getKeys(final String prefix, final String delimiter) {
  498.         return null;
  499.     }

  500.     /**
  501.      * Gets a list of typed objects associated with the given configuration key returning a null if the key doesn't map to
  502.      * an existing object.
  503.      *
  504.      * @param <T> the type expected for the elements of the list
  505.      * @param cls the class expected for the elements of the list
  506.      * @param key The configuration key.
  507.      * @return The associated list if the key is found.
  508.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not
  509.      *         compatible with a list of the specified class.
  510.      *
  511.      * @since 2.0
  512.      */
  513.     <T> List<T> getList(Class<T> cls, String key);

  514.     /**
  515.      * Gets a list of typed objects associated with the given configuration key returning the specified default value if the
  516.      * key doesn't map to an existing object. This method recursively retrieves all values stored for the passed in key,
  517.      * i.e. if one of these values is again a complex object like an array or a collection (which may be the case for some
  518.      * concrete subclasses), all values are extracted and added to the resulting list - performing a type conversion if
  519.      * necessary.
  520.      *
  521.      * @param <T> the type expected for the elements of the list
  522.      * @param cls the class expected for the elements of the list
  523.      * @param key the configuration key.
  524.      * @param defaultValue the default value.
  525.      * @return The associated List.
  526.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not
  527.      *         compatible with a list of the specified class.
  528.      *
  529.      * @since 2.0
  530.      */
  531.     <T> List<T> getList(Class<T> cls, String key, List<T> defaultValue);

  532.     /**
  533.      * Gets a List of the values associated with the given configuration key. This method is different from the generic
  534.      * {@code getList()} method in that it does not recursively obtain all values stored for the specified property key.
  535.      * Rather, only the first level of the hierarchy is processed. So the resulting list may contain complex objects like
  536.      * arrays or collections - depending on the storage structure used by a concrete subclass. If the key doesn't map to an
  537.      * existing object, an empty List is returned.
  538.      *
  539.      * @param key The configuration key.
  540.      * @return The associated List.
  541.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  542.      *         List.
  543.      */
  544.     List<Object> getList(String key);

  545.     /**
  546.      * Gets a List of strings associated with the given configuration key. If the key doesn't map to an existing object, the
  547.      * default value is returned.
  548.      *
  549.      * @param key The configuration key.
  550.      * @param defaultValue The default value.
  551.      * @return The associated List of strings.
  552.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  553.      *         List.
  554.      * @see #getList(Class, String, List)
  555.      */
  556.     List<Object> getList(String key, List<?> defaultValue);

  557.     /**
  558.      * Gets a long associated with the given configuration key.
  559.      *
  560.      * @param key The configuration key.
  561.      * @return The associated long.
  562.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  563.      *         Long.
  564.      */
  565.     long getLong(String key);

  566.     /**
  567.      * Gets a long associated with the given configuration key. If the key doesn't map to an existing object, the default
  568.      * value is returned.
  569.      *
  570.      * @param key The configuration key.
  571.      * @param defaultValue The default value.
  572.      * @return The associated long.
  573.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  574.      *         Long.
  575.      */
  576.     long getLong(String key, long defaultValue);

  577.     /**
  578.      * Gets a {@link Long} associated with the given configuration key. If the key doesn't map to an existing object, the
  579.      * default value is returned.
  580.      *
  581.      * @param key The configuration key.
  582.      * @param defaultValue The default value.
  583.      * @return The associated long if key is found and has valid format, default value otherwise.
  584.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  585.      *         Long.
  586.      */
  587.     Long getLong(String key, Long defaultValue);

  588.     /**
  589.      * Gets a list of properties associated with the given configuration key. This method expects the given key to have an
  590.      * arbitrary number of String values, each of which is of the form {@code key=value}. These strings are split at the
  591.      * equals sign, and the key parts will become keys of the returned {@code Properties} object, the value parts become
  592.      * values.
  593.      *
  594.      * @param key The configuration key.
  595.      * @return The associated properties if key is found.
  596.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  597.      *         String/List.
  598.      * @throws IllegalArgumentException if one of the tokens is malformed (does not contain an equals sign).
  599.      */
  600.     Properties getProperties(String key);

  601.     /**
  602.      * Gets a property from the configuration. This is the most basic get method for retrieving values of properties. In a
  603.      * typical implementation of the {@code Configuration} interface the other get methods (that return specific data types)
  604.      * will internally make use of this method. On this level variable substitution is not yet performed. The returned
  605.      * object is an internal representation of the property value for the passed in key. It is owned by the
  606.      * {@code Configuration} object. So a caller should not modify this object. It cannot be guaranteed that this object
  607.      * will stay constant over time (i.e. further update operations on the configuration may change its internal state).
  608.      *
  609.      * @param key property to retrieve
  610.      * @return the value to which this configuration maps the specified key, or null if the configuration contains no
  611.      *         mapping for this key.
  612.      */
  613.     Object getProperty(String key);

  614.     /**
  615.      * Gets a short associated with the given configuration key.
  616.      *
  617.      * @param key The configuration key.
  618.      * @return The associated short.
  619.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  620.      *         Short.
  621.      */
  622.     short getShort(String key);

  623.     /**
  624.      * Gets a short associated with the given configuration key.
  625.      *
  626.      * @param key The configuration key.
  627.      * @param defaultValue The default value.
  628.      * @return The associated short.
  629.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  630.      *         Short.
  631.      */
  632.     short getShort(String key, short defaultValue);

  633.     /**
  634.      * Gets a {@link Short} associated with the given configuration key. If the key doesn't map to an existing object, the
  635.      * default value is returned.
  636.      *
  637.      * @param key The configuration key.
  638.      * @param defaultValue The default value.
  639.      * @return The associated short if key is found and has valid format, default value otherwise.
  640.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  641.      *         Short.
  642.      */
  643.     Short getShort(String key, Short defaultValue);

  644.     /**
  645.      * Gets a string associated with the given configuration key.
  646.      *
  647.      * @param key The configuration key.
  648.      * @return The associated string.
  649.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  650.      *         String.
  651.      */
  652.     String getString(String key);

  653.     /**
  654.      * Gets a string associated with the given configuration key. If the key doesn't map to an existing object, the default
  655.      * value is returned.
  656.      *
  657.      * @param key The configuration key.
  658.      * @param defaultValue The default value.
  659.      * @return The associated string if key is found and has valid format, default value otherwise.
  660.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  661.      *         String.
  662.      */
  663.     String getString(String key, String defaultValue);

  664.     /**
  665.      * Gets an array of strings associated with the given configuration key. If the key doesn't map to an existing object an
  666.      * empty array is returned
  667.      *
  668.      * @param key The configuration key.
  669.      * @return The associated string array if key is found.
  670.      * @throws org.apache.commons.configuration2.ex.ConversionException is thrown if the key maps to an object that is not a
  671.      *         String/List of Strings.
  672.      */
  673.     String[] getStringArray(String key);

  674.     /**
  675.      * Return a decorator immutable Configuration containing every key from the current Configuration that starts with the
  676.      * specified prefix. The prefix is removed from the keys in the subset. For example, if the configuration contains the
  677.      * following properties:
  678.      *
  679.      * <pre>
  680.      *    prefix.number = 1
  681.      *    prefix.string = Apache
  682.      *    prefixed.foo = bar
  683.      *    prefix = Jakarta
  684.      * </pre>
  685.      *
  686.      * the immutable Configuration returned by {@code subset("prefix")} will contain the properties:
  687.      *
  688.      * <pre>
  689.      *    number = 1
  690.      *    string = Apache
  691.      *    = Jakarta
  692.      * </pre>
  693.      *
  694.      * (The key for the value "Jakarta" is an empty string)
  695.      *
  696.      * @param prefix The prefix used to select the properties.
  697.      * @return a subset immutable configuration
  698.      */
  699.     ImmutableConfiguration immutableSubset(String prefix);

  700.     /**
  701.      * Checks if the configuration is empty.
  702.      *
  703.      * @return {@code true} if the configuration contains no property, {@code false} otherwise.
  704.      */
  705.     boolean isEmpty();

  706.     /**
  707.      * Returns the number of keys stored in this configuration. Note that a concrete implementation is not guaranteed to be
  708.      * efficient; for some implementations it may be expensive to determine the size. Especially, if you just want to check
  709.      * whether a configuration is empty, it is preferable to use the {@link #isEmpty()} method.
  710.      *
  711.      * @return the number of keys stored in this configuration
  712.      */
  713.     int size();

  714. }