1 package com.fasterxml.jackson.databind.type;
2
3 import java.lang.reflect.TypeVariable;
4
5 import com.fasterxml.jackson.databind.JavaType;
6
7 /**
8  * Type that represents Java Collection types (Lists, Sets).
9  */

10 public final class CollectionType
11     extends CollectionLikeType
12 {
13     private static final long serialVersionUID = 1L;
14
15     /*
16     /**********************************************************
17     /* Life-cycle
18     /**********************************************************
19      */

20
21     private CollectionType(Class<?> collT, TypeBindings bindings,
22             JavaType superClass, JavaType[] superInts, JavaType elemT,
23             Object valueHandler, Object typeHandler, boolean asStatic)
24     {
25         super(collT, bindings, superClass, superInts, elemT, valueHandler, typeHandler, asStatic);
26     }
27
28     /**
29      * @since 2.7
30      */

31     protected CollectionType(TypeBase base, JavaType elemT) {
32         super(base, elemT);
33     }
34
35     /**
36      * @since 2.7
37      */

38     public static CollectionType construct(Class<?> rawType, TypeBindings bindings,
39             JavaType superClass, JavaType[] superInts, JavaType elemT) {
40         return new CollectionType(rawType, bindings, superClass, superInts, elemT,
41                 nullnullfalse);
42     }
43
44     /**
45      * @deprecated Since 2.7, remove from 2.9
46      */

47     @Deprecated // since 2.7
48     public static CollectionType construct(Class<?> rawType, JavaType elemT) {
49         // First: may need to fabricate TypeBindings (needed for refining into
50         // concrete collection types, as per [databind#1102])
51         TypeVariable<?>[] vars = rawType.getTypeParameters();
52         TypeBindings bindings;
53         if ((vars == null) || (vars.length != 1)) {
54             bindings = TypeBindings.emptyBindings();
55         } else {
56             bindings = TypeBindings.create(rawType, elemT);
57         }
58         return new CollectionType(rawType, bindings,
59                 // !!! TODO: Wrong, does have supertypes, but:
60                 _bogusSuperClass(rawType), null, elemT,
61                 nullnullfalse);
62     }
63
64     @Deprecated // since 2.7
65     @Override
66     protected JavaType _narrow(Class<?> subclass) {
67         return new CollectionType(subclass, _bindings,
68                 _superClass, _superInterfaces, _elementType, nullnull, _asStatic);
69     }
70
71     @Override
72     public JavaType withContentType(JavaType contentType) {
73         if (_elementType == contentType) {
74             return this;
75         }
76         return new CollectionType(_class, _bindings, _superClass, _superInterfaces,
77                 contentType, _valueHandler, _typeHandler, _asStatic);
78     }
79     
80     @Override
81     public CollectionType withTypeHandler(Object h) {
82         return new CollectionType(_class, _bindings,
83                 _superClass, _superInterfaces, _elementType, _valueHandler, h, _asStatic);
84     }
85
86     @Override
87     public CollectionType withContentTypeHandler(Object h)
88     {
89         return new CollectionType(_class, _bindings,
90                 _superClass, _superInterfaces, _elementType.withTypeHandler(h),
91                 _valueHandler, _typeHandler, _asStatic);
92     }
93
94     @Override
95     public CollectionType withValueHandler(Object h) {
96         return new CollectionType(_class, _bindings,
97                 _superClass, _superInterfaces, _elementType, h, _typeHandler, _asStatic);
98     }
99
100     @Override
101     public  CollectionType withContentValueHandler(Object h) {
102         return new CollectionType(_class, _bindings,
103                 _superClass, _superInterfaces, _elementType.withValueHandler(h),
104                 _valueHandler, _typeHandler, _asStatic);
105     }
106
107     @Override
108     public CollectionType withStaticTyping() {
109         if (_asStatic) {
110             return this;
111         }
112         return new CollectionType(_class, _bindings,
113                 _superClass, _superInterfaces, _elementType.withStaticTyping(),
114                 _valueHandler, _typeHandler, true);
115     }
116
117     @Override
118     public JavaType refine(Class<?> rawType, TypeBindings bindings,
119             JavaType superClass, JavaType[] superInterfaces) {
120         return new CollectionType(rawType, bindings,
121                 superClass, superInterfaces, _elementType,
122                 _valueHandler, _typeHandler, _asStatic);
123     }
124
125     /*
126     /**********************************************************
127     /* Standard methods
128     /**********************************************************
129      */

130
131     @Override
132     public String toString()
133     {
134         return "[collection type; class "+_class.getName()+", contains "+_elementType+"]";
135     }
136 }
137