1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.functor.core.composite;
18
19 import org.apache.commons.functor.Predicate;
20 import org.apache.commons.functor.Procedure;
21 import org.apache.commons.lang3.Validate;
22
23 import java.io.Serializable;
24
25
26
27
28
29
30
31 public abstract class AbstractLoopProcedure implements Procedure, Serializable {
32
33
34
35 private static final long serialVersionUID = -5903381842630236070L;
36
37
38 private static final int HASH_SHIFT = 4;
39
40
41
42
43
44 private final Predicate condition;
45
46
47
48
49 private final Procedure action;
50
51
52
53
54
55
56 protected AbstractLoopProcedure(Predicate condition, Procedure action) {
57 this.condition = Validate.notNull(condition, "Predicate argument must not be null");
58 this.action = Validate.notNull(action, "Predicate argument must not be null");
59 }
60
61
62
63
64 @Override
65 public final boolean equals(Object object) {
66 if (object == this) {
67 return true;
68 }
69 if (!(object instanceof AbstractLoopProcedure)) {
70 return false;
71 }
72 AbstractLoopProcedure that = (AbstractLoopProcedure) object;
73 return (getCondition().equals(that.getCondition())
74 && (getAction().equals(that.getAction())));
75 }
76
77
78
79
80 @Override
81 public int hashCode() {
82 return hashCode("AbstractLoopProcedure".hashCode());
83 }
84
85
86
87
88 @Override
89 public String toString() {
90 return getClass().getName() + "<" + getCondition() + "," + getAction() + ">";
91 }
92
93
94
95
96
97
98 protected int hashCode(int hash) {
99 hash <<= HASH_SHIFT;
100 hash ^= getAction().hashCode();
101 hash <<= HASH_SHIFT;
102 hash ^= getCondition().hashCode();
103 return hash;
104 }
105
106
107
108
109
110 protected final Predicate getCondition() {
111 return condition;
112 }
113
114
115
116
117
118 protected final Procedure getAction() {
119 return action;
120 }
121
122 }