Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Status |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2003-2008 the original author or authors. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | * | |
16 | * You are receiving this code free of charge, which represents many hours of | |
17 | * effort from other individuals and corporations. As a responsible member | |
18 | * of the community, you are asked (but not required) to donate any | |
19 | * enhancements or improvements back to the community under a similar open | |
20 | * source license. Thank you. -TMN | |
21 | */ | |
22 | package groovyx.net.http; | |
23 | ||
24 | 4 | public enum Status { |
25 | 1 | SUCCESS ( 100, 399 ), |
26 | 1 | FAILURE ( 400, 999 ); |
27 | ||
28 | private final int min, max; | |
29 | ||
30 | @Override public String toString() { | |
31 | 14 | return super.toString().toLowerCase(); |
32 | } | |
33 | ||
34 | public boolean matches( int code ) { | |
35 | 3 | return min <= code && code <= max; |
36 | } | |
37 | ||
38 | public static Status find( int code ) { | |
39 | 3 | for ( Status s : Status.values() ) |
40 | 3 | if ( s.matches( code ) ) return s; |
41 | 0 | throw new IllegalArgumentException( "Unknown status: " + code ); |
42 | } | |
43 | ||
44 | 2 | private Status( int min, int max ) { |
45 | 2 | this.min = min; this.max = max; |
46 | 2 | } |
47 | } |