
jetbrick.template.runtime.buildin.JetMethods Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jetbrick-template Show documentation
Show all versions of jetbrick-template Show documentation
Next generation template engine for Java.
The newest version!
/**
* Copyright 2013-2016 Guoqiang Chen, Shanghai, China. All rights reserved.
*
* Author: Guoqiang Chen
* Email: [email protected]
* WebURL: https://github.com/subchen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jetbrick.template.runtime.buildin;
import java.text.DecimalFormat;
import java.util.*;
import jetbrick.util.*;
public final class JetMethods {
//---- type cast -------------------------------------------------------
public static Boolean asBoolean(Object value) {
if (value == null) {
return null;
}
if (value instanceof Boolean) {
return (Boolean) value;
}
value = value.toString().toLowerCase();
if ("true".equals(value)) return Boolean.TRUE;
if ("yes".equals(value)) return Boolean.TRUE;
if ("on".equals(value)) return Boolean.TRUE;
if ("t".equals(value)) return Boolean.TRUE;
if ("y".equals(value)) return Boolean.TRUE;
if ("1".equals(value)) return Boolean.TRUE;
return Boolean.FALSE;
}
public static Integer asInt(Object value) {
if (value == null) {
return null;
}
if (value instanceof Number) {
return ((Number) value).intValue();
}
return Integer.valueOf(value.toString());
}
public static Long asLong(Object value) {
if (value == null) {
return null;
}
if (value instanceof Number) {
return ((Number) value).longValue();
}
return Long.valueOf(value.toString());
}
public static Float asFloat(Object value) {
if (value == null) {
return null;
}
if (value instanceof Number) {
return ((Number) value).floatValue();
}
return Float.valueOf(value.toString());
}
public static Double asDouble(Object value) {
if (value == null) {
return null;
}
if (value instanceof Number) {
return ((Number) value).doubleValue();
}
return Double.valueOf(value.toString());
}
public static Date asDate(String value) {
return DateUtils.parse(value);
}
public static Date asDate(String value, String format) {
return DateUtils.parse(value, format);
}
public static List asList(Collection values) {
if (values == null) {
return null;
}
if (values instanceof List) {
return (List) values;
}
return new ArrayList(values);
}
public static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy