Source code
Description: source: package: org.apache.commons.configuration2.convert, class: DisabledListDelimiterHandler

    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *     https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.configuration2.convert;
    018
    019import java.util.ArrayList;
    020import java.util.Collection;
    021import java.util.List;
    022
    023/**
    024 * <p>
    025 * A specialized implementation of the {@code ListDelimiterHandler} interface which disables list splitting.
    026 * </p>
    027 * <p>
    028 * This class does not recognize any list delimiters; passed in strings are returned unchanged. Also the
    029 * {@code escape()} method is a dummy - there is no need for escaping delimiter characters as none are supported. Note
    030 * that the method for escaping a list throws an {@code UnsupportedOperationException}. If list delimiters are not
    031 * supported, there is no point in squashing multiple values into a single one.
    032 * </p>
    033 * <p>
    034 * Implementation note: An instance of this class can be shared between multiple configuration objects. It is state-less
    035 * and thread-safe.
    036 * </p>
    037 *
    038 * @since 2.0
    039 */
    040public class DisabledListDelimiterHandler extends AbstractListDelimiterHandler {
    041
    042    /**
    043     * A default instance of this class. Because it is safe to share {@code DisabledListDelimiterHandler} objects this
    044     * instance can be used whenever such an object is needed.
    045     */
    046    public static final ListDelimiterHandler INSTANCE = new DisabledListDelimiterHandler();
    047
    048    /**
    049     * Constructs a new instance.
    050     */
    051    public DisabledListDelimiterHandler() {
    052        // empty
    053    }
    054
    055    /**
    056     * {@inheritDoc} This implementation always throws an {@code UnsupportedOperationException} exception.
    057     */
    058    @Override
    059    public Object escapeList(final List<?> values, final ValueTransformer transformer) {
    060        throw new UnsupportedOperationException("Escaping lists is not supported.");
    061    }
    062
    063    /**
    064     * {@inheritDoc} This implementation returns the passed in string without any changes.
    065     */
    066    @Override
    067    protected String escapeString(final String s) {
    068        return s;
    069    }
    070
    071    /**
    072     * {@inheritDoc} This implementation always returns a collection containing the passed in string as its single element.
    073     * The string is not changed, the {@code trim} flag is ignored. (The {@code trim} flag refers to the components
    074     * extracted from the string. Because no components are extracted nothing is trimmed.)
    075     */
    076    @Override
    077    protected Collection<String> splitString(final String s, final boolean trim) {
    078        final Collection<String> result = new ArrayList<>(1);
    079        result.add(s);
    080        return result;
    081    }
    082}