1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.util.functor;
17
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Set;
21
22 import org.seasar.tuigwaa.view.DataViewUtils;
23
24 import com.isenshi.util.functor.BinaryFunction;
25 import com.isenshi.util.functor.UnaryFunction;
26
27 public class ArrayViewerFunction implements UnaryFunction {
28
29 private BinaryFunction binaryFunction;
30
31 public ArrayViewerFunction(BinaryFunction unaryFunction) {
32 this.binaryFunction = unaryFunction;
33 }
34
35 public Object evaluate(Object data) {
36 Set set = (Set) data;
37 if (set == null || set.size() == 0) {
38 return "";
39 }
40
41 boolean firstFlag = true;
42
43 List list = DataViewUtils.sortById(set);
44
45 StringBuffer buf = new StringBuffer();
46 for (Iterator i = list.iterator(); i.hasNext();) {
47 if (firstFlag) {
48 firstFlag = false;
49 } else {
50 buf.append(" , ");
51 }
52 Object obj = i.next();
53 if (binaryFunction != null) {
54 obj = binaryFunction.evaluate(obj, null);
55 }
56 buf.append(obj);
57 }
58 return buf.toString();
59 }
60 }