1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.functor.core.algorithm;
18
19 import java.io.Serializable;
20
21 import org.apache.commons.functor.Predicate;
22 import org.apache.commons.functor.Procedure;
23
24
25
26
27
28
29 abstract class PredicatedLoop implements Procedure, Serializable {
30
31
32
33 private static final long serialVersionUID = 3221684231735316893L;
34 private final Procedure body;
35 private final Predicate test;
36
37
38
39
40
41
42 protected PredicatedLoop(Procedure body, Predicate test) {
43 this.body = body;
44 this.test = test;
45 }
46
47
48
49
50
51 protected Procedure getBody() {
52 return body;
53 }
54
55
56
57
58
59 protected Predicate getTest() {
60 return test;
61 }
62
63
64
65
66 public boolean equals(Object obj) {
67 if (obj == this) {
68 return true;
69 }
70 if (obj == null || !obj.getClass().equals(getClass())) {
71 return false;
72 }
73 PredicatedLoop other = (PredicatedLoop) obj;
74 return other.body.equals(body) && other.test.equals(test);
75 }
76
77
78
79
80 public int hashCode() {
81 String classname = getClass().getName();
82 int dot = classname.lastIndexOf('.');
83 int result = classname.substring(dot + 1).hashCode();
84 result <<= 2;
85 result ^= body.hashCode();
86 result <<= 2;
87 result ^= test.hashCode();
88 return result;
89 }
90 }