]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/PrimitiveUtils.java
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.core
.execution
;
20 public class PrimitiveUtils
{
21 public final static String TYPE_STRING
= "string";
22 public final static String TYPE_INTEGER
= "integer";
23 public final static String TYPE_LONG
= "long";
24 public final static String TYPE_FLOAT
= "float";
25 public final static String TYPE_DOUBLE
= "double";
26 public final static String TYPE_BOOLEAN
= "boolean";
28 private PrimitiveUtils() {
32 /** @return the class or null if the provided type is not a primitive */
33 public static Class
<?
> typeAsClass(String type
) {
34 if (TYPE_STRING
.equals(type
))
36 else if (TYPE_INTEGER
.equals(type
))
38 else if (TYPE_LONG
.equals(type
))
40 else if (TYPE_FLOAT
.equals(type
))
42 else if (TYPE_DOUBLE
.equals(type
))
44 else if (TYPE_BOOLEAN
.equals(type
))
50 /** @return the type or null if the provided class is not a primitive */
51 public static String
classAsType(Class
<?
> clss
) {
52 if (String
.class.isAssignableFrom(clss
))
54 else if (Integer
.class.isAssignableFrom(clss
))
56 else if (Long
.class.isAssignableFrom(clss
))
58 else if (Float
.class.isAssignableFrom(clss
))
60 else if (Double
.class.isAssignableFrom(clss
))
62 else if (Boolean
.class.isAssignableFrom(clss
))
68 public static Object
convert(String type
, String str
) {
69 if (TYPE_STRING
.equals(type
)) {
71 } else if (TYPE_INTEGER
.equals(type
)) {
72 return (Integer
.parseInt(str
));
73 } else if (TYPE_LONG
.equals(type
)) {
74 return (Long
.parseLong(str
));
75 } else if (TYPE_FLOAT
.equals(type
)) {
76 return (Float
.parseFloat(str
));
77 } else if (TYPE_DOUBLE
.equals(type
)) {
78 return (Double
.parseDouble(str
));
79 } else if (TYPE_BOOLEAN
.equals(type
)) {
80 return (Boolean
.parseBoolean(str
));