|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
StatusData | Line # 34 | 25 | 0% | 12 | 4 | 91.3% |
0.9130435
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(10) | |||
Result | |||
0.65217394
|
org.perfectjpattern.core.behavioral.observer.data.TestStatusData.testHashcode org.perfectjpattern.core.behavioral.observer.data.TestStatusData.testHashcode | 1 PASS | |
0.6086956
|
org.perfectjpattern.core.behavioral.observer.data.TestProgressData.testHashcode org.perfectjpattern.core.behavioral.observer.data.TestProgressData.testHashcode | 1 PASS | |
0.5217391
|
org.perfectjpattern.core.behavioral.observer.data.TestStatusData.testValueOf org.perfectjpattern.core.behavioral.observer.data.TestStatusData.testValueOf | 1 PASS | |
0.5217391
|
org.perfectjpattern.core.behavioral.observer.data.TestStatusData.testEquals org.perfectjpattern.core.behavioral.observer.data.TestStatusData.testEquals | 1 PASS | |
0.47826087
|
org.perfectjpattern.core.behavioral.observer.data.TestProgressData.testValueOf org.perfectjpattern.core.behavioral.observer.data.TestProgressData.testValueOf | 1 PASS | |
0.47826087
|
org.perfectjpattern.core.behavioral.observer.data.TestProgressData.testEquals org.perfectjpattern.core.behavioral.observer.data.TestProgressData.testEquals | 1 PASS | |
0.39130434
|
org.perfectjpattern.core.behavioral.observer.TestSubject.testProgressObserver org.perfectjpattern.core.behavioral.observer.TestSubject.testProgressObserver | 1 PASS | |
0.13043478
|
org.perfectjpattern.core.behavioral.observer.data.TestStatusData.testToString org.perfectjpattern.core.behavioral.observer.data.TestStatusData.testToString | 1 PASS | |
0.13043478
|
org.perfectjpattern.core.behavioral.observer.data.TestProgressData.testToString org.perfectjpattern.core.behavioral.observer.data.TestProgressData.testToString | 1 PASS | |
0.08695652
|
org.perfectjpattern.core.behavioral.observer.TestAsynchronousSubject.testAsynchronousNotification org.perfectjpattern.core.behavioral.observer.TestAsynchronousSubject.testAsynchronousNotification | 1 PASS | |
1 | //---------------------------------------------------------------------- | |
2 | // | |
3 | // PerfectJPattern: "Design patterns are good but components are better!" | |
4 | // StatusData.java Copyright (c) 2009 Giovanni Azua Garcia | |
5 | // bravegag@hotmail.com | |
6 | // | |
7 | // This program is free software; you can redistribute it and/or | |
8 | // modify it under the terms of the GNU General Public License | |
9 | // as published by the Free Software Foundation; either version 3 | |
10 | // of the License, or (at your option) any later version. | |
11 | // | |
12 | // This program is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | // | |
17 | // You should have received a copy of the GNU General Public License | |
18 | // along with this program; if not, see <http://www.gnu.org/licenses/>. | |
19 | // | |
20 | //---------------------------------------------------------------------- | |
21 | package org.perfectjpattern.core.behavioral.observer.data; | |
22 | ||
23 | import org.apache.commons.lang.*; | |
24 | import org.perfectjpattern.core.api.behavioral.observer.data.*; | |
25 | ||
26 | /** | |
27 | * Immutable Observer event data intended to be used in notifying status | |
28 | * information. | |
29 | * | |
30 | * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> | |
31 | * @version $Revision: 1.0 $ $Date: Jun 17, 2007 2:20:44 PM $ | |
32 | */ | |
33 | public | |
34 | class StatusData | |
35 | implements IEventData | |
36 | { | |
37 | //------------------------------------------------------------------------ | |
38 | // public | |
39 | //------------------------------------------------------------------------ | |
40 | /** | |
41 | * Constructor that creates a StatusData instance from a Status and message. | |
42 | * | |
43 | * @param aStatus Status of the task | |
44 | * @param aMessage Description of the current theStatus | |
45 | * @throws IllegalArgumentException "'aStatus' must not be null" | |
46 | * @throws IllegalArgumentException "'aMessage' must not be null" | |
47 | */ | |
48 | 42 | public |
49 | StatusData(Status aStatus, String aMessage) | |
50 | { | |
51 | 42 | Validate.notNull(aStatus, "'aStatus' must not be null"); |
52 | 42 | Validate.notNull(aMessage, "'aMessage' must not be null"); |
53 | ||
54 | 42 | theStatus = aStatus; |
55 | 42 | theMessage = aMessage; |
56 | } | |
57 | ||
58 | //------------------------------------------------------------------------ | |
59 | /** | |
60 | * Copy constructor. | |
61 | * | |
62 | * @param aStatusData Existing StatusData | |
63 | * @throws IllegalArgumentException "'aStatus' must not be null" | |
64 | * @throws IllegalArgumentException "'aMessage' must not be null" | |
65 | */ | |
66 | 1 | public |
67 | StatusData(StatusData aStatusData) | |
68 | { | |
69 | 1 | this(aStatusData.getStatus(), aStatusData.getMessage()); |
70 | } | |
71 | ||
72 | //------------------------------------------------------------------------ | |
73 | /** | |
74 | * Returns message associated with this StatusData. Offers a user-friendly | |
75 | * description of the status. | |
76 | * | |
77 | * @return Message associated with this StatusData. Offers a user-friendly | |
78 | * description of the status. | |
79 | */ | |
80 | 4 | public String |
81 | getMessage() | |
82 | { | |
83 | 4 | return theMessage; |
84 | } | |
85 | ||
86 | //------------------------------------------------------------------------ | |
87 | /** | |
88 | * Returns the Status value associated with this StatusData from the set of | |
89 | * predefined possible values {@link Status}. | |
90 | * | |
91 | * @return Status value associated with this StatusData from the set of | |
92 | * predefined possible values {@link Status}. | |
93 | */ | |
94 | 94 | public Status |
95 | getStatus() | |
96 | { | |
97 | 94 | return theStatus; |
98 | } | |
99 | ||
100 | //------------------------------------------------------------------------ | |
101 | /** | |
102 | * {@inheritDoc} | |
103 | */ | |
104 | 21 | @Override |
105 | public boolean | |
106 | equals(Object anObject) | |
107 | { | |
108 | 21 | if (this == anObject) |
109 | { | |
110 | 4 | return true; |
111 | } | |
112 | ||
113 | 17 | if (anObject == null) |
114 | { | |
115 | 1 | return false; |
116 | } | |
117 | ||
118 | 16 | if (getClass() != anObject.getClass()) |
119 | { | |
120 | 2 | return false; |
121 | } | |
122 | ||
123 | 14 | final StatusData myAnother = (StatusData) anObject; |
124 | 14 | if (!theMessage.equals(myAnother.theMessage)) |
125 | { | |
126 | 4 | return false; |
127 | } | |
128 | ||
129 | 10 | if (!theStatus.equals(myAnother.theStatus)) |
130 | { | |
131 | 0 | return false; |
132 | } | |
133 | ||
134 | 10 | return true; |
135 | } | |
136 | ||
137 | ||
138 | //------------------------------------------------------------------------ | |
139 | /** | |
140 | * {@inheritDoc} | |
141 | */ | |
142 | 12 | @Override |
143 | public int | |
144 | hashCode() | |
145 | { | |
146 | 12 | final int myPrime = 31; |
147 | 12 | int myResult = 1; |
148 | 12 | myResult = myPrime * myResult + ((theMessage == null) ? 0 : |
149 | theMessage.hashCode()); | |
150 | 12 | myResult = myPrime * myResult + ((theStatus == null) ? 0 : |
151 | theStatus.hashCode()); | |
152 | ||
153 | 12 | return myResult; |
154 | } | |
155 | ||
156 | //------------------------------------------------------------------------ | |
157 | /** | |
158 | * {@inheritDoc} | |
159 | */ | |
160 | 2 | @Override |
161 | public String | |
162 | toString() | |
163 | { | |
164 | 2 | return "StatusData(Status='" + getStatus().toString() + |
165 | "', Message='" + getMessage() + "')"; | |
166 | } | |
167 | ||
168 | //------------------------------------------------------------------------ | |
169 | // members | |
170 | //------------------------------------------------------------------------ | |
171 | /** | |
172 | * Status information. | |
173 | */ | |
174 | private final Status theStatus; | |
175 | ||
176 | /** | |
177 | * Descriptive information on the task status | |
178 | */ | |
179 | private final String theMessage; | |
180 | ||
181 | /** | |
182 | * Reusable <code>StatusData</code> instance corresponding to a | |
183 | * <b>Started</b> event. | |
184 | */ | |
185 | public static final StatusData STARTED = new StatusData(Status.STARTED, | |
186 | "Task has started."); | |
187 | ||
188 | /** | |
189 | * Reusable <code>StatusData</code> instance corresponding to a | |
190 | * <b>Failed</b> event. | |
191 | */ | |
192 | public static final StatusData FAILED = new StatusData(Status.FAILED, | |
193 | "Task has failed"); | |
194 | ||
195 | /** | |
196 | * Reusable <code>StatusData</code> instance corresponding to a | |
197 | * <b>Completed</b> state. | |
198 | */ | |
199 | public static final StatusData COMPLETED = new StatusData(Status.COMPLETED, | |
200 | "Task has completed."); | |
201 | } |
|