1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.functor.adapter;
18
19 import org.apache.commons.functor.NullaryFunction;
20 import org.apache.commons.functor.NullaryProcedure;
21 import org.apache.commons.lang3.Validate;
22
23
24
25
26
27
28
29
30
31
32
33 public final class NullaryProcedureNullaryFunction<T> implements NullaryFunction<T> {
34
35 private final NullaryProcedure procedure;
36
37
38
39
40
41 public NullaryProcedureNullaryFunction(NullaryProcedure procedure) {
42 this.procedure = Validate.notNull(procedure, "NullaryProcedure argument was null");
43 }
44
45
46
47
48 public T evaluate() {
49 procedure.run();
50 return null;
51 }
52
53
54
55
56 @Override
57 public boolean equals(Object obj) {
58 if (obj == this) {
59 return true;
60 }
61 if (!(obj instanceof NullaryProcedureNullaryFunction<?>)) {
62 return false;
63 }
64 NullaryProcedureNullaryFunction<?> that = (NullaryProcedureNullaryFunction<?>) obj;
65 return this.procedure.equals(that.procedure);
66 }
67
68
69
70
71 @Override
72 public int hashCode() {
73 int hash = "NullaryProcedureNullaryFunction".hashCode();
74 hash ^= procedure.hashCode();
75 return hash;
76 }
77
78
79
80
81 @Override
82 public String toString() {
83 return "NullaryProcedureNullaryFunction<" + procedure + ">";
84 }
85
86
87
88
89
90
91
92 public static <T> NullaryProcedureNullaryFunction<T> adapt(NullaryProcedure procedure) {
93 return null == procedure ? null : new NullaryProcedureNullaryFunction<T>(procedure);
94 }
95
96 }