Last change
on this file was
193,
checked in by Maciej Komosinski, 10 years ago
|
Set svn:eol-style native for all textual files
|
-
Property svn:eol-style set to
native
|
File size:
940 bytes
|
Line | |
---|
1 | package com.framsticks.util.lang; |
---|
2 | |
---|
3 | import java.util.Iterator; |
---|
4 | |
---|
5 | // import org.apache.commons.collections.Closure; |
---|
6 | |
---|
7 | public class Delimeted<T> { |
---|
8 | |
---|
9 | protected final String delimeter; |
---|
10 | protected final String empty; |
---|
11 | protected StringBuilder builder = null; |
---|
12 | |
---|
13 | /** |
---|
14 | * @param delimeter |
---|
15 | */ |
---|
16 | public Delimeted(String delimeter, String empty) { |
---|
17 | this.delimeter = delimeter; |
---|
18 | this.empty = empty; |
---|
19 | } |
---|
20 | |
---|
21 | public final Delimeted<T> append(T object) { |
---|
22 | if (builder != null) { |
---|
23 | builder.append(delimeter); |
---|
24 | } else { |
---|
25 | builder = new StringBuilder(); |
---|
26 | } |
---|
27 | builder.append(object); |
---|
28 | return this; |
---|
29 | } |
---|
30 | |
---|
31 | public final Delimeted<T> append(Iterator<T> i) { |
---|
32 | while (i.hasNext()) { |
---|
33 | append(i.next()); |
---|
34 | } |
---|
35 | return this; |
---|
36 | } |
---|
37 | |
---|
38 | public final String build() { |
---|
39 | return (builder != null ? builder.toString() : empty); |
---|
40 | } |
---|
41 | |
---|
42 | @Override |
---|
43 | public String toString() { |
---|
44 | return build(); |
---|
45 | } |
---|
46 | |
---|
47 | // @Override |
---|
48 | // public void execute(Object input) { |
---|
49 | // append(input); |
---|
50 | // } |
---|
51 | |
---|
52 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.