/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * * @author Uwe Schmidt * * Konversion aller Elemente eines Containers in einen String * */ //-------------------- public class ToString extends Accumulate { private StringBuffer result; private String separator,last; private boolean empty; //-------------------- // first : Anfangs-String (oeffnente Klammer) // separator : Trennzeichen zwischen Elementen // last : Ende-String (schliessende Klammer) // ToString("[", ",", "]") --> Listen in Prolog Syntax // ToString("(", " ", ")") --> Listen in Lisp Syntax public ToString( String first, String separator, String last ) { result = new StringBuffer(first); this.separator = separator; this.last = last; empty = true; } //-------------------- public void process(Object element) { if ( ! empty ) { result.append(separator); } result.append(element.toString()); empty = false; } //-------------------- public Object getResult() { result.append(last); // Resultat ist ein String return result.toString(); } }