|
@@ -0,0 +1,219 @@
|
|
|
|
+package com.ywt.biz.common.util;
|
|
|
|
+
|
|
|
|
+import com.ywt.biz.common.constant.YwtCommonRespCode;
|
|
|
|
+import com.ywt.biz.common.exception.YwtCommonException;
|
|
|
|
+
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Created by huangguoping on 14/12/10.
|
|
|
|
+ */
|
|
|
|
+public class Checker {
|
|
|
|
+ public static boolean isNone(Map map) {
|
|
|
|
+ if (map == null || map.size() == 0) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void checkNone(Map map, String paramName) {
|
|
|
|
+ if (map == null || map.size() == 0) {
|
|
|
|
+ throw new YwtCommonException(YwtCommonRespCode.P_ERR, paramName + " is null or empty");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean isNone(List lst) {
|
|
|
|
+ if (lst == null || lst.size() == 0)
|
|
|
|
+ return true;
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean isNone(Set s) {
|
|
|
|
+ if (s == null || s.size() == 0)
|
|
|
|
+ return true;
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void checkNone(List lst, String paramName) {
|
|
|
|
+ if (lst == null || lst.size() == 0) {
|
|
|
|
+ throw new YwtCommonException(YwtCommonRespCode.P_ERR, paramName + " is null or empty");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean isNone(String str) {
|
|
|
|
+ if (str == null || str.equals(""))
|
|
|
|
+ return true;
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void checkNone(String str, String paramName) {
|
|
|
|
+ if (str == null || str.equals("")) {
|
|
|
|
+ throw new YwtCommonException(YwtCommonRespCode.P_ERR, paramName + " is null or empty");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean isNone(Object object) {
|
|
|
|
+ if (object == null) return true;
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void checkNone(Object object, String paramName) {
|
|
|
|
+ if (object == null) {
|
|
|
|
+ throw new YwtCommonException(YwtCommonRespCode.P_ERR, paramName + " is null or empty");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean isNone(Object[] objects) {
|
|
|
|
+ if (objects == null || objects.length == 0) return true;
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void checkNone(Object[] objects, String paramName) {
|
|
|
|
+ if (objects == null || objects.length == 0) {
|
|
|
|
+ throw new YwtCommonException(YwtCommonRespCode.P_ERR, paramName + " is null or empty");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean isNone(byte[] bytes) {
|
|
|
|
+ if (bytes == null || bytes.length == 0)
|
|
|
|
+ return true;
|
|
|
|
+ else
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void checkNone(byte[] bytes, String paramName) {
|
|
|
|
+ if (bytes == null || bytes.length == 0) {
|
|
|
|
+ throw new YwtCommonException(YwtCommonRespCode.P_ERR, paramName + " is null or empty");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static int getIntegerValue(Integer value, int defaultValue) {
|
|
|
|
+ return value != null ? value.intValue() : defaultValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static byte getByteValue(Byte value, byte defaultValue) {
|
|
|
|
+ return value != null ? value.byteValue() : defaultValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static short getShortValue(Short value, short defaultValue) {
|
|
|
|
+ return value != null ? value.shortValue() : defaultValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static double getDoubleValue(Double value, double defaultValue) {
|
|
|
|
+ return value != null ? value.doubleValue() : defaultValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean getBooleanValue(Boolean value, boolean defaultValue) {
|
|
|
|
+ return value != null ? value.booleanValue() : defaultValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String getStringValue(String value, String defaultValue) {
|
|
|
|
+ return value != null ? value : defaultValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String getStringValue(String value) {
|
|
|
|
+ return value != null ? value : "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static long getLongValue(Long value, long defaultValue) {
|
|
|
|
+ return value != null ? value.longValue() : defaultValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static Date getDateValue(Date date, Date defaultDate) {
|
|
|
|
+ return date != null ? date : defaultDate;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static int getIntegerValue(Integer value) {
|
|
|
|
+ return value != null ? value.intValue() : 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static byte getByteValue(Byte value) {
|
|
|
|
+ return value != null ? value.byteValue() : (byte) 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static short getShortValue(Short value) {
|
|
|
|
+ return value != null ? value.shortValue() : (short) 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static double getDoubleValue(Double value) {
|
|
|
|
+ return value != null ? value.doubleValue() : (double) 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean getBooleanValue(Boolean value) {
|
|
|
|
+ return value != null ? value.booleanValue() : false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static long getLongValue(Long value) {
|
|
|
|
+ return value != null ? value.longValue() : 0L;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String NullStringToEmpty(String value) {
|
|
|
|
+ return value != null ? value : "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static Date getDateValue(Date date) {
|
|
|
|
+ return date != null ? date : new Date(System.currentTimeMillis());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static int parseInt(String numStr, int defaultValue) {
|
|
|
|
+ try {
|
|
|
|
+ return Integer.parseInt(numStr);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static int parseInt(String numStr) {
|
|
|
|
+ return parseInt(numStr, 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static long parseLong(String numStr, long defaultValue) {
|
|
|
|
+ try {
|
|
|
|
+ return Long.parseLong(numStr);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static long parseLong(String numStr) {
|
|
|
|
+ return parseLong(numStr, 0L);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static double parseDouble(String numStr, double defaultValue) {
|
|
|
|
+ try {
|
|
|
|
+ return Double.parseDouble(numStr);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static double parseDouble(String numStr) {
|
|
|
|
+ return parseDouble(numStr, 0d);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean isNull(Object obj) {
|
|
|
|
+ return obj == null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * bigDecimal 转 int 型,放大100倍
|
|
|
|
+ *
|
|
|
|
+ * @param bigDecimal
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static int getBigDecimalTo100TimeIntValue(BigDecimal bigDecimal) {
|
|
|
|
+ try {
|
|
|
|
+ BigDecimal dec = new BigDecimal("100");
|
|
|
|
+ dec = dec.multiply(bigDecimal);
|
|
|
|
+ return dec.intValue();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|