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 java.io.Serializable;
20
21 import org.apache.commons.functor.BinaryProcedure;
22 import org.apache.commons.functor.Procedure;
23 import org.apache.commons.lang3.Validate;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public final class FullyBoundProcedure implements Procedure, Serializable {
42
43
44
45 private static final long serialVersionUID = -904891610081737737L;
46
47 private final BinaryProcedure<Object, Object> procedure;
48
49 private final Object left;
50
51 private final Object right;
52
53
54
55
56
57
58
59
60
61 @SuppressWarnings("unchecked")
62 public <L, R> FullyBoundProcedure(BinaryProcedure<? super L, ? super R> procedure, L left, R right) {
63 this.procedure =
64 (BinaryProcedure<Object, Object>) Validate.notNull(procedure,
65 "BinaryProcedure argument was null");
66 this.left = left;
67 this.right = right;
68 }
69
70
71
72
73 public void run() {
74 procedure.run(left, right);
75 }
76
77
78
79
80 @Override
81 public boolean equals(Object that) {
82 return that == this || (that instanceof FullyBoundProcedure && equals((FullyBoundProcedure) that));
83 }
84
85
86
87
88
89
90 public boolean equals(FullyBoundProcedure that) {
91 return null != that && procedure.equals(that.procedure)
92 && (null == left ? null == that.left : left.equals(that.left))
93 && (null == right ? null == that.right : right.equals(that.right));
94 }
95
96
97
98
99 @Override
100 public int hashCode() {
101 int hash = "FullyBoundProcedure".hashCode();
102 hash <<= 2;
103 hash ^= procedure.hashCode();
104 hash <<= 2;
105 if (null != left) {
106 hash ^= left.hashCode();
107 }
108 hash <<= 2;
109 if (null != right) {
110 hash ^= right.hashCode();
111 }
112 return hash;
113 }
114
115
116
117
118 @Override
119 public String toString() {
120 return "FullyBoundProcedure<" + procedure + "(" + left + ", " + right + ")>";
121 }
122
123
124
125
126
127
128
129
130
131
132 public static <L, R> FullyBoundProcedure bind(BinaryProcedure<? super L, ? super R> procedure, L left, R right) {
133 return null == procedure ? null : new FullyBoundProcedure(procedure, left, right);
134 }
135
136 }