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 * http://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 026 * which disables list splitting. 027 * </p> 028 * <p> 029 * This class does not recognize any list delimiters; passed in strings are 030 * returned unchanged. Also the {@code escape()} method is a dummy - there is no 031 * need for escaping delimiter characters as none are supported. Note that the 032 * method for escaping a list throws an {@code UnsupportedOperationException}. 033 * If list delimiters are not supported, there is no point in squashing multiple 034 * values into a single one. 035 * </p> 036 * <p> 037 * Implementation note: An instance of this class can be shared between multiple 038 * configuration objects. It is state-less and thread-safe. 039 * </p> 040 * 041 * @version $Id: DisabledListDelimiterHandler.java 1842194 2018-09-27 22:24:23Z ggregory $ 042 * @since 2.0 043 */ 044public class DisabledListDelimiterHandler extends AbstractListDelimiterHandler 045{ 046 /** 047 * A default instance of this class. Because it is safe to share 048 * {@code DisabledListDelimiterHandler} objects this instance can be used 049 * whenever such an object is needed. 050 */ 051 public static final ListDelimiterHandler INSTANCE = 052 new DisabledListDelimiterHandler(); 053 054 /** 055 * {@inheritDoc} This implementation always throws an 056 * {@code UnsupportedOperationException} exception. 057 */ 058 @Override 059 public Object escapeList(final List<?> values, final ValueTransformer transformer) 060 { 061 throw new UnsupportedOperationException( 062 "Escaping lists is not supported!"); 063 } 064 065 /** 066 * {@inheritDoc} This implementation always returns a collection containing 067 * the passed in string as its single element. The string is not changed, 068 * the {@code trim} flag is ignored. (The {@code trim} flag refers to the 069 * components extracted from the string. Because no components are extracted 070 * nothing is trimmed.) 071 */ 072 @Override 073 protected Collection<String> splitString(final String s, final boolean trim) 074 { 075 final Collection<String> result = new ArrayList<>(1); 076 result.add(s); 077 return result; 078 } 079 080 /** 081 * {@inheritDoc} This implementation returns the passed in string without 082 * any changes. 083 */ 084 @Override 085 protected String escapeString(final String s) 086 { 087 return s; 088 } 089}