Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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 jetbrick.util.DateUtils;
import jetbrick.util.IdentifiedNameUtils;
import jetbrick.util.JSONUtils;
import jetbrick.util.StringEscapeUtils;
import jetbrick.util.StringUtils;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
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