Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
CollectiveTypeStrategy |
|
| 2.0;2 |
1 | /* |
|
2 | * Copyright 2005 The Apache Software Foundation. |
|
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 | package org.apache.commons.betwixt.strategy; |
|
17 | ||
18 | import java.util.Collection; |
|
19 | import java.util.Enumeration; |
|
20 | import java.util.Iterator; |
|
21 | import java.util.Map; |
|
22 | ||
23 | /** |
|
24 | * Specifies which types should be regarded as collective |
|
25 | */ |
|
26 | 2040 | public abstract class CollectiveTypeStrategy { |
27 | ||
28 | /** |
|
29 | * Default collective type strategy |
|
30 | */ |
|
31 | 1020 | public static final CollectiveTypeStrategy DEFAULT = new Default(); |
32 | ||
33 | /** |
|
34 | * Is this a loop type class? |
|
35 | * @since 0.7 |
|
36 | * @param type is this <code>Class</code> a loop type? |
|
37 | * @return true if the type is a loop type, or if type is null |
|
38 | */ |
|
39 | public abstract boolean isCollective(Class type); |
|
40 | ||
41 | /** |
|
42 | * Default collective type strategy |
|
43 | */ |
|
44 | 1020 | public static class Default extends CollectiveTypeStrategy { |
45 | ||
46 | /** |
|
47 | * Basic implementation returns true for all the standard java |
|
48 | * collective types and their subclasses. |
|
49 | */ |
|
50 | public boolean isCollective(Class type) { |
|
51 | // consider: should this be factored into a pluggable strategy? |
|
52 | // check for NPEs |
|
53 | 22148 | if (type == null) { |
54 | 4769 | return false; |
55 | } |
|
56 | 24222 | return type.isArray() |
57 | 16352 | || Map.class.isAssignableFrom( type ) |
58 | 15858 | || Collection.class.isAssignableFrom( type ) |
59 | 12369 | || Enumeration.class.isAssignableFrom( type ) |
60 | 12265 | || Iterator.class.isAssignableFrom( type ) |
61 | 10679 | || Map.Entry.class.isAssignableFrom( type ) ; |
62 | ||
63 | } |
|
64 | ||
65 | } |
|
66 | } |