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 */
017 package org.apache.camel.util;
018
019 /**
020 * A little helper class for converting a collection of values to a (usually comma separated) string.
021 *
022 * @version $Revision: 751221 $
023 */
024 public class CollectionStringBuffer {
025 private final StringBuffer buffer = new StringBuffer();
026 private String separator;
027 private boolean first = true;
028
029 public CollectionStringBuffer() {
030 this(", ");
031 }
032
033 public CollectionStringBuffer(String separator) {
034 this.separator = separator;
035 }
036
037 @Override
038 public String toString() {
039 return buffer.toString();
040 }
041
042 public void append(Object value) {
043 if (first) {
044 first = false;
045 } else {
046 buffer.append(separator);
047 }
048 buffer.append(value);
049 }
050
051 public String getSeparator() {
052 return separator;
053 }
054
055 public void setSeparator(String separator) {
056 this.separator = separator;
057 }
058 }