Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Output |
|
| 3.3636363636363638;3.364 |
1 | /* Copyright © 2012 Matthew Champion | |
2 | All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions are met: | |
6 | * Redistributions of source code must retain the above copyright | |
7 | notice, this list of conditions and the following disclaimer. | |
8 | * Redistributions in binary form must reproduce the above copyright | |
9 | notice, this list of conditions and the following disclaimer in the | |
10 | documentation and/or other materials provided with the distribution. | |
11 | * Neither the name of mattunderscore.com nor the | |
12 | names of its contributors may be used to endorse or promote products | |
13 | derived from this software without specific prior written permission. | |
14 | ||
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
18 | DISCLAIMED. IN NO EVENT SHALL MATTHEW CHAMPION BE LIABLE FOR ANY | |
19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |
25 | ||
26 | package com.mattunderscore.filter.contentnegotiation.parser; | |
27 | ||
28 | /** | |
29 | * The result of the content negotiation matching a variant. | |
30 | * <P> | |
31 | * Used to configure responses. | |
32 | * | |
33 | * @author Matt Champion | |
34 | * @since 0.0.13 | |
35 | */ | |
36 | public class Output | |
37 | { | |
38 | ||
39 | private static final int HASH_SEED = 1; | |
40 | private static final int HASH_MULT = 7; | |
41 | ||
42 | protected String forward; | |
43 | protected Header header; | |
44 | protected Redirect redirect; | |
45 | protected Boolean fail; | |
46 | ||
47 | public Output() | |
48 | 116 | { |
49 | 116 | } |
50 | ||
51 | /** | |
52 | * Get the forward of the output. | |
53 | * @return The forward of the output | |
54 | * @since 0.0.13 | |
55 | */ | |
56 | public String getForward() | |
57 | { | |
58 | 18 | return this.forward; |
59 | } | |
60 | ||
61 | /** | |
62 | * Set the forward of the output. | |
63 | * @param value The forward of the output | |
64 | * @since 0.0.13 | |
65 | */ | |
66 | public void setForward(String value) | |
67 | { | |
68 | 24 | this.forward = value; |
69 | 24 | } |
70 | ||
71 | /** | |
72 | * Get the header of the output. | |
73 | * @return The header of the output | |
74 | * @since 0.0.13 | |
75 | */ | |
76 | public Header getHeader() | |
77 | { | |
78 | 12 | return header; |
79 | } | |
80 | ||
81 | /** | |
82 | * Set the header of the output. | |
83 | * @param value The header of the output | |
84 | * @since 0.0.13 | |
85 | */ | |
86 | public void setHeader(Header value) | |
87 | { | |
88 | 32 | this.header = value; |
89 | 32 | } |
90 | ||
91 | /** | |
92 | * Get the redirect of the output. | |
93 | * @return The redirect of the output | |
94 | * @since 0.0.13 | |
95 | */ | |
96 | public Redirect getRedirect() | |
97 | { | |
98 | 20 | return redirect; |
99 | } | |
100 | ||
101 | /** | |
102 | * Set the redirect of the output. | |
103 | * @param value The redirect of the output | |
104 | * @since 0.0.13 | |
105 | */ | |
106 | public void setRedirect(Redirect value) | |
107 | { | |
108 | 30 | this.redirect = value; |
109 | 30 | } |
110 | ||
111 | /** | |
112 | * Get the fail of the output. | |
113 | * @return The fail of the output | |
114 | * @since 0.0.13 | |
115 | */ | |
116 | public Boolean isFail() | |
117 | { | |
118 | 12 | return fail; |
119 | } | |
120 | ||
121 | /** | |
122 | * Set the fail of the output. | |
123 | * @param value The fail of the output | |
124 | * @since 0.0.13 | |
125 | */ | |
126 | public void setFail(Boolean value) | |
127 | { | |
128 | 34 | this.fail = value; |
129 | 34 | } |
130 | ||
131 | @Override | |
132 | public int hashCode() | |
133 | { | |
134 | 128 | int hash = HASH_SEED; |
135 | 128 | hash = (hash * HASH_MULT); |
136 | 128 | if (forward != null) |
137 | { | |
138 | 28 | hash += forward.hashCode(); |
139 | } | |
140 | else | |
141 | { | |
142 | 100 | hash += 1; |
143 | } | |
144 | 128 | hash = (hash * HASH_MULT); |
145 | 128 | if (header != null) |
146 | { | |
147 | 56 | hash += header.hashCode(); |
148 | } | |
149 | else | |
150 | { | |
151 | 72 | hash += 2; |
152 | } | |
153 | 128 | hash = (hash * HASH_MULT); |
154 | 128 | if (redirect != null) |
155 | { | |
156 | 16 | hash += redirect.hashCode(); |
157 | } | |
158 | else | |
159 | { | |
160 | 112 | hash += 3; |
161 | } | |
162 | 128 | hash = (hash * HASH_MULT); |
163 | 128 | if (fail != null) |
164 | { | |
165 | 16 | hash += fail.hashCode(); |
166 | } | |
167 | else | |
168 | { | |
169 | 112 | hash += 5; |
170 | } | |
171 | 128 | return hash; |
172 | } | |
173 | ||
174 | @Override | |
175 | public boolean equals(Object o) | |
176 | { | |
177 | 432 | if (o == null) |
178 | { | |
179 | 50 | return false; |
180 | } | |
181 | 382 | else if (o == this) |
182 | { | |
183 | 144 | return true; |
184 | } | |
185 | 238 | else if (o.getClass().equals(getClass())) |
186 | { | |
187 | 146 | final Output co = (Output)o; |
188 | 146 | boolean allEqual = true; |
189 | 146 | if (this.forward != null) |
190 | { | |
191 | 36 | if (co.forward != null) |
192 | { | |
193 | 12 | allEqual = allEqual && this.forward.equals(co.forward); |
194 | } | |
195 | else | |
196 | { | |
197 | 24 | allEqual = false; |
198 | } | |
199 | } | |
200 | 110 | else if (co.forward != null) |
201 | { | |
202 | 18 | allEqual = false; |
203 | } | |
204 | 146 | if (this.header != null) |
205 | { | |
206 | 50 | if (co.header != null) |
207 | { | |
208 | 30 | allEqual = allEqual && this.header.equals(co.header); |
209 | } | |
210 | else | |
211 | { | |
212 | 20 | allEqual = false; |
213 | } | |
214 | } | |
215 | 96 | else if (co.header != null) |
216 | { | |
217 | 40 | allEqual = false; |
218 | } | |
219 | 146 | if (this.redirect != null) |
220 | { | |
221 | 28 | if (co.redirect != null) |
222 | { | |
223 | 12 | allEqual = allEqual && this.redirect.equals(co.redirect); |
224 | } | |
225 | else | |
226 | { | |
227 | 16 | allEqual = false; |
228 | } | |
229 | } | |
230 | 118 | else if (co.redirect != null) |
231 | { | |
232 | 14 | allEqual = false; |
233 | } | |
234 | 146 | if (this.fail != null) |
235 | { | |
236 | 32 | if (co.fail != null) |
237 | { | |
238 | 8 | allEqual = allEqual && this.fail.equals(co.fail); |
239 | } | |
240 | else | |
241 | { | |
242 | 24 | allEqual = false; |
243 | } | |
244 | } | |
245 | 114 | else if (co.fail != null) |
246 | { | |
247 | 12 | allEqual = false; |
248 | } | |
249 | 146 | return allEqual; |
250 | } | |
251 | else | |
252 | { | |
253 | 92 | return false; |
254 | } | |
255 | } | |
256 | ||
257 | } |