1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.isenshi.util.functor;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.ListIterator;
22
23 public class CompositeUnaryFunction implements Serializable, UnaryFunction {
24
25 /***
26 *
27 */
28 private static final long serialVersionUID = 1L;
29
30 private List list = new ArrayList();
31
32 public CompositeUnaryFunction() {
33 }
34
35 public CompositeUnaryFunction(UnaryFunction f) {
36 of(f);
37 }
38
39 public CompositeUnaryFunction(UnaryFunction f, UnaryFunction g) {
40 of(f);
41 of(g);
42 }
43
44
45
46 public CompositeUnaryFunction of(UnaryFunction f) {
47 list.add(f);
48 return this;
49 }
50
51
52
53 public Object evaluate(Object obj) {
54 Object result = obj;
55 for (ListIterator iter = list.listIterator(list.size()); iter
56 .hasPrevious();) {
57 result = ((UnaryFunction) iter.previous()).evaluate(result);
58 }
59 return result;
60 }
61
62 }