View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.json.config;
8   
9   import org.mule.api.annotations.ContainsTransformerMethods;
10  import org.mule.api.annotations.Transformer;
11  
12  /**
13   * Provides transformer for converting from primitive class types and Strings.
14   */
15  @ContainsTransformerMethods
16  public class PrimitveTransformers
17  {
18  
19      @Transformer
20      public Boolean convertStringToBoolean(String s)
21      {
22          return "TRUE".equalsIgnoreCase(s);
23      }
24  
25      @Transformer
26      public String convertBooleanToString(Boolean b)
27      {
28          return b.toString();
29      }
30  
31      @Transformer
32      public Integer convertDoubleToInteger(Double d)
33      {
34          return d.intValue();
35      }
36  
37      @Transformer
38      public Double convertIntegerToDouble(Integer i)
39      {
40          return i.doubleValue();
41      }
42  
43      @Transformer
44      public Long convertDoubleToLong(Double d)
45      {
46          return d.longValue();
47      }
48  
49      @Transformer
50      public Double convertLongToDouble(Long l)
51      {
52          return l.doubleValue();
53      }
54  
55      @Transformer
56      public Float convertDoubleToFloat(Double d)
57      {
58          return d.floatValue();
59      }
60  
61      @Transformer
62      public Double convertFloatToDouble(Float f)
63      {
64          return f.doubleValue();
65      }
66  
67  
68      @Transformer
69      public Long convertFloatToLong(Float f)
70      {
71          return f.longValue();
72      }
73  
74      @Transformer
75      public Float convertLongToFloat(Long l)
76      {
77          return l.floatValue();
78      }
79  
80      @Transformer
81      public Integer convertFloatToInteger(Float f)
82      {
83          return f.intValue();
84      }
85  
86      @Transformer
87      public Float convertIntegerToFloat(Integer i)
88      {
89          return i.floatValue();
90      }
91  
92      @Transformer
93      public Integer convertStringToInteger(String s)
94      {
95          return Integer.valueOf(s);
96      }
97  
98      @Transformer
99      public Long convertStringToLong(String s)
100     {
101         return Long.valueOf(s);
102     }
103 
104     @Transformer
105     public Float convertStringToFloat(String s)
106     {
107         return Float.valueOf(s);
108     }
109 
110     @Transformer
111     public Double convertStringToDouble(String s)
112     {
113         return Double.valueOf(s);
114     }
115 }