From b419209310112939039b6e2935bee6c53cdf7a52 Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Thu, 25 Jul 2019 14:30:48 +0800
Subject: [PATCH] 新增无人机飞行轨迹地图页面
---
src/main/java/com/moral/common/util/StringUtils.java | 73 +++++++++++++++++++++++++++++++++++-
1 files changed, 71 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/moral/common/util/StringUtils.java b/src/main/java/com/moral/common/util/StringUtils.java
index 4b2791b..87d1cd0 100644
--- a/src/main/java/com/moral/common/util/StringUtils.java
+++ b/src/main/java/com/moral/common/util/StringUtils.java
@@ -1,11 +1,21 @@
package com.moral.common.util;
+import com.mysql.jdbc.TimeUtil;
+
+import javax.validation.constraints.NotNull;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+/**
+ *
+ * ������������: string ���������
+ * @author: fengxiang
+ * @date: 2018/7/30 10:53
+ */
public class StringUtils {
public static final char UNDERLINE = '_';
+ public static final String NULL = "null";
/**
* ������������������������������������������������������
@@ -44,11 +54,10 @@
return sb.toString();
}
public static boolean isNullOrEmpty(String toTest) {
- return toTest == null || toTest.length() == 0;
+ return toTest == null || toTest.length() == 0 || NULL.equals(toTest);
}
public static Object stringToObject4Type(Class<?> type,String value) throws Exception{
Object result = value;
-
if (type == double.class || type == Double.class) {
result = Double.parseDouble(value);
} else if (type == float.class || type == Float.class) {
@@ -82,4 +91,64 @@
return result;
}
+ /**
+ * ���������������������������
+ * @param str
+ * @param maxLength
+ * @return
+ */
+ public static String subStringCN(final String str, final int maxLength) {
+ if (str == null) {
+ return str;
+ }
+ String suffix = "...";
+ int suffixLen = suffix.length();
+
+ final StringBuffer sbuffer = new StringBuffer();
+ final char[] chr = str.trim().toCharArray();
+ int len = 0;
+ for (int i = 0; i < chr.length; i++) {
+
+ if (chr[i] >= 0xa1) {
+ len += 2;
+ } else {
+ len++;
+ }
+ }
+
+ if(len<=maxLength){
+ return str;
+ }
+
+ len = 0;
+ for (int i = 0; i < chr.length; i++) {
+
+ if (chr[i] >= 0xa1) {
+ len += 2;
+ if (len + suffixLen > maxLength) {
+ break;
+ }else {
+ sbuffer.append(chr[i]);
+ }
+ } else {
+ len++;
+ if (len + suffixLen > maxLength) {
+ break;
+ }else {
+ sbuffer.append(chr[i]);
+ }
+ }
+ }
+ sbuffer.append(suffix);
+ return sbuffer.toString();
+ }
+ public static boolean isNumericZidai(String str) {
+ for (int i = 0; i < str.length(); i++) {
+ //System.out.println(str.charAt(i));
+ if (!Character.isDigit(str.charAt(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
}
--
Gitblit v1.8.0