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 * A default instance of this class. Because it is safe to share {@code DisabledListDelimiterHandler} objects this 043 * instance can be used whenever such an object is needed. 044 */ 045 public static final ListDelimiterHandler INSTANCE = new DisabledListDelimiterHandler(); 046 047 /** 048 * Constructs a new instance. 049 */ 050 public DisabledListDelimiterHandler() { 051 // empty 052 } 053 054 /** 055 * {@inheritDoc} This implementation always throws an {@code UnsupportedOperationException} exception. 056 */ 057 @Override 058 public Object escapeList(final List<?> values, final ValueTransformer transformer) { 059 throw new UnsupportedOperationException("Escaping lists is not supported!"); 060 } 061 062 /** 063 * {@inheritDoc} This implementation returns the passed in string without any changes. 064 */ 065 @Override 066 protected String escapeString(final String s) { 067 return s; 068 } 069 070 /** 071 * {@inheritDoc} This implementation always returns a collection containing the passed in string as its single element. 072 * The string is not changed, the {@code trim} flag is ignored. (The {@code trim} flag refers to the components 073 * extracted from the string. Because no components are extracted nothing is trimmed.) 074 */ 075 @Override 076 protected Collection<String> splitString(final String s, final boolean trim) { 077 final Collection<String> result = new ArrayList<>(1); 078 result.add(s); 079 return result; 080 } 081}