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.camel.util; 018 019/** 020 * A little helper class for converting a collection of values to a (usually comma separated) string. 021 * 022 * @deprecated use JDK {@link String#join(CharSequence, CharSequence...)} or {@link java.util.StringJoiner}. 023 */ 024@Deprecated 025public class CollectionStringBuffer { 026 private final StringBuilder buffer = new StringBuilder(); 027 private String separator; 028 private boolean first = true; 029 030 public CollectionStringBuffer() { 031 this(", "); 032 } 033 034 public CollectionStringBuffer(String separator) { 035 this.separator = separator; 036 } 037 038 @Override 039 public String toString() { 040 return buffer.toString(); 041 } 042 043 public void append(Object value) { 044 if (first) { 045 first = false; 046 } else { 047 buffer.append(separator); 048 } 049 buffer.append(value); 050 } 051 052 public String getSeparator() { 053 return separator; 054 } 055 056 public void setSeparator(String separator) { 057 this.separator = separator; 058 } 059 060 public boolean isEmpty() { 061 return first; 062 } 063}