1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.strategy;
18
19 import java.util.Collection;
20 import java.util.Enumeration;
21 import java.util.Iterator;
22 import java.util.Map;
23
24 /***
25 * Specifies which types should be regarded as collective
26 * @since 0.8
27 */
28 public abstract class CollectiveTypeStrategy {
29
30 /***
31 * Default collective type strategy
32 */
33 public static final CollectiveTypeStrategy DEFAULT = new Default();
34
35 /***
36 * Is this a loop type class?
37 * @since 0.7
38 * @param type is this <code>Class</code> a loop type?
39 * @return true if the type is a loop type, or if type is null
40 */
41 public abstract boolean isCollective(Class type);
42
43 /***
44 * Default collective type strategy
45 */
46 public static class Default extends CollectiveTypeStrategy {
47
48 /***
49 * Basic implementation returns true for all the standard java
50 * collective types and their subclasses.
51 */
52 public boolean isCollective(Class type) {
53
54
55 if (type == null) {
56 return false;
57 }
58 return type.isArray()
59 || Map.class.isAssignableFrom( type )
60 || Collection.class.isAssignableFrom( type )
61 || Enumeration.class.isAssignableFrom( type )
62 || Iterator.class.isAssignableFrom( type )
63 || Map.Entry.class.isAssignableFrom( type ) ;
64
65 }
66
67 }
68 }