Clover icon

sunshower-base

  1. Project Clover database Fri Apr 6 2018 03:41:27 UTC
  2. Package io.sunshower.common.rs

File ClassParameterProviderFactory.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
50% of files have more coverage

Code metrics

6
15
7
4
71
58
11
0.73
2.14
1.75
1.57

Classes

Class Line # Actions
ClassParameterProviderFactory 13 7 4
0.00%
ClassParameterProviderFactory.MultihashConverter 29 2 2
0.00%
ClassParameterProviderFactory.UUIDParameterConverter 42 2 2
0.00%
ClassParameterProviderFactory.ClassParameterConverter 55 4 3
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package io.sunshower.common.rs;
2   
3    import io.sunshower.common.crypto.Multihash;
4    import java.lang.annotation.Annotation;
5    import java.lang.reflect.Type;
6    import java.util.UUID;
7    import javax.ws.rs.ext.ParamConverter;
8    import javax.ws.rs.ext.ParamConverterProvider;
9    import javax.ws.rs.ext.Provider;
10   
11    @Provider
12    @SuppressWarnings("unchecked")
 
13    public class ClassParameterProviderFactory implements ParamConverterProvider {
14   
 
15  0 toggle @Override
16    public <T> ParamConverter<T> getConverter(
17    Class<T> rawType, Type genericType, Annotation[] annotations) {
18   
19  0 if (rawType == Class.class) {
20  0 return (ParamConverter<T>) new ClassParameterConverter();
21  0 } else if (rawType == UUID.class) {
22  0 return (ParamConverter<T>) new UUIDParameterConverter();
23  0 } else if (rawType == Multihash.class) {
24  0 return (ParamConverter<T>) new MultihashConverter();
25    }
26  0 return null;
27    }
28   
 
29    private static class MultihashConverter implements ParamConverter<Multihash> {
30   
 
31  0 toggle @Override
32    public Multihash fromString(String value) {
33  0 return Multihash.fromBase58(value);
34    }
35   
 
36  0 toggle @Override
37    public String toString(Multihash value) {
38  0 return value.toBase58();
39    }
40    }
41   
 
42    private static class UUIDParameterConverter implements ParamConverter<UUID> {
43   
 
44  0 toggle @Override
45    public UUID fromString(String value) {
46  0 return UUID.fromString(value);
47    }
48   
 
49  0 toggle @Override
50    public String toString(UUID value) {
51  0 return value.toString();
52    }
53    }
54   
 
55    private static class ClassParameterConverter implements ParamConverter<Class<?>> {
56   
 
57  0 toggle @Override
58    public Class<?> fromString(String value) {
59  0 try {
60  0 return Class.forName(value);
61    } catch (ClassNotFoundException e) {
62  0 return null;
63    }
64    }
65   
 
66  0 toggle @Override
67    public String toString(Class<?> value) {
68  0 return value.getName();
69    }
70    }
71    }