File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\util\xstream\ImmutableSetConverter.java.html

1 package hudson.util.xstream;
2
3 import com.google.common.collect.ImmutableSet;
4 import com.thoughtworks.xstream.XStream;
5 import com.thoughtworks.xstream.converters.UnmarshallingContext;
6 import com.thoughtworks.xstream.converters.collections.CollectionConverter;
7 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
8 import com.thoughtworks.xstream.converters.reflection.SerializableConverter;
9 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
10 import com.thoughtworks.xstream.mapper.Mapper;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 /**
16 * @author Kohsuke Kawaguchi
17 */
18 public class ImmutableSetConverter extends CollectionConverter {
19 private final SerializableConverter sc;
20
21 public ImmutableSetConverter(XStream xs) {
22 this(xs.getMapper(),xs.getReflectionProvider());
23 }
24
25 public ImmutableSetConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
26 super(mapper);
27 sc = new SerializableConverter(mapper,reflectionProvider);
28 }
29
30 @Override
31 public boolean canConvert(Class type) {
32 return ImmutableSet.class.isAssignableFrom(type);
33 }
34
35 @Override
36 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
37 return ImmutableSet.copyOf((List) super.unmarshal(reader, context));
38 }
39
40 @Override
41 protected Object createCollection(Class type) {
42 return new ArrayList();
43 }
44 }
45