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
22 import java.io.Serializable;
23
24
25
26
27
28
29
30
31
32 public abstract class AbstractLoopProcedure implements Procedure, Serializable {
33
34
35
36 private static final long serialVersionUID = -5903381842630236070L;
37
38
39 private static final int HASH_SHIFT = 4;
40
41 private final Predicate condition;
42 private final Procedure action;
43
44
45
46
47
48
49 protected AbstractLoopProcedure(Predicate condition, Procedure action) {
50 this.condition = condition;
51 this.action = action;
52 }
53
54
55
56
57 public final boolean equals(Object object) {
58 if (object == this) {
59 return true;
60 }
61 if (!(object instanceof AbstractLoopProcedure)) {
62 return false;
63 }
64 AbstractLoopProcedure that = (AbstractLoopProcedure) object;
65 return (null == getCondition() ? null == that.getCondition() : getCondition().equals(that.getCondition()))
66 && (null == getAction() ? null == that.getAction() : getAction().equals(that.getAction()));
67 }
68
69
70
71
72 public int hashCode() {
73 return hashCode("AbstractLoopProcedure".hashCode());
74 }
75
76
77
78
79 public String toString() {
80 return getClass().getName() + "<" + getCondition() + "," + getAction() + ">";
81 }
82
83
84
85
86
87
88 protected int hashCode(int hash) {
89 hash <<= HASH_SHIFT;
90 if (null != getAction()) {
91 hash ^= getAction().hashCode();
92 }
93 hash <<= HASH_SHIFT;
94 if (null != getCondition()) {
95 hash ^= getCondition().hashCode();
96 }
97 return hash;
98 }
99
100
101
102
103
104 protected final Predicate getCondition() {
105 return condition;
106 }
107
108
109
110
111
112 protected final Procedure getAction() {
113 return action;
114 }
115
116 }