View Javadoc

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