','
48 | */
49 | public static final char DEFAULT_DELIMITER_CHAR = ',';
50 |
51 | /**
52 | * Constant representing the default quote character (double quote), equal
53 | * to '"'
54 | */
55 | public static final char DEFAULT_QUOTE_CHAR = '"';
56 |
57 | /**
58 | * Check whether the given String has actual text. More specifically,
59 | * returns true
if the string not null
, its length
60 | * is greater than 0, and it contains at least one non-whitespace character.
61 | *
62 | * StringUtils.hasText(null) == false
63 | * StringUtils.hasText("") == false
64 | * StringUtils.hasText(" ") == false
65 | * StringUtils.hasText("12345") == true
66 | * StringUtils.hasText(" 12345 ") == true
67 | *
68 | *
69 | * Copied from the Spring Framework while retaining all license, copyright
70 | * and author information.
71 | *
72 | * @param str the String to check (may be null
)
73 | * @return true
if the String is not null
, its
74 | * length is greater than 0, and it does not contain whitespace only
75 | * @see Character#isWhitespace
76 | */
77 | public static boolean hasText(String str) {
78 | if (!hasLength(str)) {
79 | return false;
80 | }
81 | int strLen = str.length();
82 | for (int i = 0; i < strLen; i++) {
83 | if (!Character.isWhitespace(str.charAt(i))) {
84 | return true;
85 | }
86 | }
87 | return false;
88 | }
89 |
90 | /**
91 | * Check that the given String is neither null
nor of length 0.
92 | * Note: Will return true
for a String that purely consists of
93 | * whitespace.
94 | *
StringUtils.hasLength(null) == false
96 | * StringUtils.hasLength("") == false
97 | * StringUtils.hasLength(" ") == true
98 | * StringUtils.hasLength("Hello") == true
99 | *
100 | * Copied from the Spring Framework while retaining all license, copyright
101 | * and author information.
102 | *
103 | * @param str the String to check (may be null
)
104 | * @return true
if the String is not null and has length
105 | * @see #hasText(String)
106 | */
107 | public static boolean hasLength(String str) {
108 | return (str != null && str.length() > 0);
109 | }
110 |
111 | /**
112 | * Test if the given String starts with the specified prefix, ignoring
113 | * upper/lower case.
114 | *
115 | *
116 | * Copied from the Spring Framework while retaining all license, copyright
117 | * and author information.
118 | *
119 | * @param str the String to check
120 | * @param prefix the prefix to look for
121 | * @return true
starts with the specified prefix (ignoring
122 | * case), false
if it does not.
123 | * @see String#startsWith
124 | */
125 | public static boolean startsWithIgnoreCase(String str, String prefix) {
126 | if (str == null || prefix == null) {
127 | return false;
128 | }
129 | if (str.startsWith(prefix)) {
130 | return true;
131 | }
132 | if (str.length() < prefix.length()) {
133 | return false;
134 | }
135 | String lcStr = str.substring(0, prefix.length()).toLowerCase();
136 | String lcPrefix = prefix.toLowerCase();
137 | return lcStr.equals(lcPrefix);
138 | }
139 |
140 | /**
141 | * Returns a 'cleaned' representation of the specified argument. 'Cleaned'
142 | * is defined as the following:
143 | *
String
is null
, return
146 | * null
null
, {@link String#trim() trim()} it.null
null
is returned.
156 | *
157 | * @param in the input String to clean.
158 | * @return a populated-but-trimmed String or null
otherwise
159 | */
160 | public static String clean(String in) {
161 | String out = in;
162 |
163 | if (in != null) {
164 | out = in.trim();
165 | if (out.equals(EMPTY_STRING)) {
166 | out = null;
167 | }
168 | }
169 |
170 | return out;
171 | }
172 |
173 | /**
174 | * Returns the specified array as a comma-delimited (',') string.
175 | *
176 | * @param array the array whose contents will be converted to a string.
177 | * @return the array's contents as a comma-delimited (',') string.
178 | * @since 1.0
179 | */
180 | public static String toString(Object[] array) {
181 | return toDelimitedString(array, ",");
182 | }
183 |
184 | /**
185 | * Returns the array's contents as a string, with each element delimited by
186 | * the specified {@code delimiter} argument. Useful for {@code toString()}
187 | * implementations and log messages.
188 | *
189 | * @param array the array whose contents will be converted to a string
190 | * @param delimiter the delimiter to use between each element
191 | * @return a single string, delimited by the specified {@code delimiter}.
192 | * @since 1.0
193 | */
194 | public static String toDelimitedString(Object[] array, String delimiter) {
195 | if (array == null || array.length == 0) {
196 | return EMPTY_STRING;
197 | }
198 | StringBuilder sb = new StringBuilder();
199 | for (int i = 0; i < array.length; i++) {
200 | if (i > 0) {
201 | sb.append(delimiter);
202 | }
203 | sb.append(array[i]);
204 | }
205 | return sb.toString();
206 | }
207 |
208 | /**
209 | * Tokenize the given String into a String array via a StringTokenizer.
210 | * Trims tokens and omits empty tokens.
211 | *
212 | * The given delimiters string is supposed to consist of any number of
213 | * delimiter characters. Each of those characters can be used to separate
214 | * tokens. A delimiter is always a single character; for multi-character
215 | * delimiters, consider using delimitedListToStringArray
216 | *
218 | * Copied from the Spring Framework while retaining all license, copyright 219 | * and author information. 220 | * 221 | * @param str the String to tokenize 222 | * @param delimiters the delimiter characters, assembled as String (each of 223 | * those characters is individually considered as delimiter). 224 | * @return an array of the tokens 225 | * @see StringTokenizer 226 | * @see String#trim() 227 | */ 228 | public static String[] tokenizeToStringArray(String str, String delimiters) { 229 | return tokenizeToStringArray(str, delimiters, true, true); 230 | } 231 | 232 | /** 233 | * Tokenize the given String into a String array via a StringTokenizer. 234 | *
235 | * The given delimiters string is supposed to consist of any number of
236 | * delimiter characters. Each of those characters can be used to separate
237 | * tokens. A delimiter is always a single character; for multi-character
238 | * delimiters, consider using delimitedListToStringArray
239 | *
241 | * Copied from the Spring Framework while retaining all license, copyright
242 | * and author information.
243 | *
244 | * @param str the String to tokenize
245 | * @param delimiters the delimiter characters, assembled as String (each of
246 | * those characters is individually considered as delimiter)
247 | * @param trimTokens trim the tokens via String's trim
248 | * @param ignoreEmptyTokens omit empty tokens from the result array (only
249 | * applies to tokens that are empty after trimming; StringTokenizer will not
250 | * consider subsequent delimiters as token in the first place).
251 | * @return an array of the tokens (null
if the input String was
252 | * null
)
253 | * @see StringTokenizer
254 | * @see String#trim()
255 | */
256 | @SuppressWarnings({"unchecked"})
257 | public static String[] tokenizeToStringArray(
258 | String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) {
259 |
260 | if (str == null) {
261 | return null;
262 | }
263 | StringTokenizer st = new StringTokenizer(str, delimiters);
264 | List tokens = new ArrayList();
265 | while (st.hasMoreTokens()) {
266 | String token = st.nextToken();
267 | if (trimTokens) {
268 | token = token.trim();
269 | }
270 | if (!ignoreEmptyTokens || token.length() > 0) {
271 | tokens.add(token);
272 | }
273 | }
274 | return toStringArray(tokens);
275 | }
276 |
277 | /**
278 | * Copy the given Collection into a String array. The Collection must
279 | * contain String elements only.
280 | *
282 | * Copied from the Spring Framework while retaining all license, copyright
283 | * and author information.
284 | *
285 | * @param collection the Collection to copy
286 | * @return the String array (null
if the passed-in Collection
287 | * was null
)
288 | */
289 | @SuppressWarnings({"unchecked"})
290 | public static String[] toStringArray(Collection collection) {
291 | if (collection == null) {
292 | return null;
293 | }
294 | return (String[]) collection.toArray(new String[collection.size()]);
295 | }
296 |
297 | public static String[] splitKeyValue(String aLine) throws ParseException {
298 | String line = clean(aLine);
299 | if (line == null) {
300 | return null;
301 | }
302 | String[] split = line.split(" ", 2);
303 | if (split.length != 2) {
304 | //fallback to checking for an equals sign
305 | split = line.split("=", 2);
306 | if (split.length != 2) {
307 | String msg = "Unable to determine Key/Value pair from line [" + line + "]. There is no space from "
308 | + "which the split location could be determined.";
309 | throw new ParseException(msg, 0);
310 | }
311 |
312 | }
313 |
314 | split[0] = clean(split[0]);
315 | split[1] = clean(split[1]);
316 | if (split[1].startsWith("=")) {
317 | //they used spaces followed by an equals followed by zero or more spaces to split the key/value pair, so
318 | //remove the equals sign to result in only the key and values in the
319 | split[1] = clean(split[1].substring(1));
320 | }
321 |
322 | if (split[0] == null) {
323 | String msg = "No valid key could be found in line [" + line + "] to form a key/value pair.";
324 | throw new ParseException(msg, 0);
325 | }
326 | if (split[1] == null) {
327 | String msg = "No corresponding value could be found in line [" + line + "] for key [" + split[0] + "]";
328 | throw new ParseException(msg, 0);
329 | }
330 |
331 | return split;
332 | }
333 |
334 | public static String[] split(String line) {
335 | return split(line, DEFAULT_DELIMITER_CHAR);
336 | }
337 |
338 | public static String[] split(String line, char delimiter) {
339 | return split(line, delimiter, DEFAULT_QUOTE_CHAR);
340 | }
341 |
342 | public static String[] split(String line, char delimiter, char quoteChar) {
343 | return split(line, delimiter, quoteChar, quoteChar);
344 | }
345 |
346 | public static String[] split(String line, char delimiter, char beginQuoteChar, char endQuoteChar) {
347 | return split(line, delimiter, beginQuoteChar, endQuoteChar, false, true);
348 | }
349 |
350 | /**
351 | * Splits the specified delimited String into tokens, supporting quoted
352 | * tokens so that quoted strings themselves won't be tokenized.
353 | *
941 | *
942 | * This method is under the Jive Open Source Software License and was
943 | * written by Mark Imbriaco.
944 | *
945 | * @param text a String of text to convert into an array of words
946 | * @return text broken up into an array of words.
947 | */
948 | public static String[] toLowerCaseWordArray(String text) {
949 | if (text == null || text.length() == 0) {
950 | return new String[0];
951 | }
952 |
953 | List
997 | * length
, the String will be chopped
1020 | * there. If no newline or whitespace is found in string
up to
1021 | * the index length
, the String will chopped at
1022 | * length
.
1023 | *
1024 | * For example, chopAtWord("This is a nice String", 10) will return "This is
1025 | * a" which is the first word boundary less than or equal to 10 characters
1026 | * into the original String.
1027 | *
1028 | * @param string the String to chop.
1029 | * @param length the index in string
to start looking for a
1030 | * whitespace boundary at.
1031 | * @return a substring of string
whose length is less than or
1032 | * equal to length
, and that is chopped at whitespace.
1033 | */
1034 | public static String chopAtWord(String string, int length) {
1035 | if (string == null || string.length() == 0) {
1036 | return string;
1037 | }
1038 |
1039 | char[] charArray = string.toCharArray();
1040 | int sLength = string.length();
1041 | if (length < sLength) {
1042 | sLength = length;
1043 | }
1044 |
1045 | // First check if there is a newline character before length; if so,
1046 | // chop word there.
1047 | for (int i = 0; i < sLength - 1; i++) {
1048 | // Windows
1049 | if (charArray[i] == '\r' && charArray[i + 1] == '\n') {
1050 | return string.substring(0, i + 1);
1051 | } // Unix
1052 | else if (charArray[i] == '\n') {
1053 | return string.substring(0, i);
1054 | }
1055 | }
1056 | // Also check boundary case of Unix newline
1057 | if (charArray[sLength - 1] == '\n') {
1058 | return string.substring(0, sLength - 1);
1059 | }
1060 |
1061 | // Done checking for newline, now see if the total string is less than
1062 | // the specified chop point.
1063 | if (string.length() < length) {
1064 | return string;
1065 | }
1066 |
1067 | // No newline, so chop at the first whitespace.
1068 | for (int i = length - 1; i > 0; i--) {
1069 | if (charArray[i] == ' ') {
1070 | return string.substring(0, i).trim();
1071 | }
1072 | }
1073 |
1074 | // Did not find word boundary so return original String chopped at
1075 | // specified length.
1076 | return string.substring(0, length);
1077 | }
1078 |
1079 | /**
1080 | * Escapes all necessary characters in the String so that it can be used in
1081 | * SQL
1082 | *
1083 | * @param string the string to escape.
1084 | * @return the string with appropriate characters escaped.
1085 | */
1086 | public static String escapeForSQL(String string) {
1087 | if (string == null) {
1088 | return null;
1089 | } else if (string.length() == 0) {
1090 | return string;
1091 | }
1092 |
1093 | char ch;
1094 | char[] input = string.toCharArray();
1095 | int i = 0;
1096 | int last = 0;
1097 | int len = input.length;
1098 | StringBuilder out = null;
1099 | for (; i < len; i++) {
1100 | ch = input[i];
1101 |
1102 | if (ch == '\'') {
1103 | if (out == null) {
1104 | out = new StringBuilder(len + 2);
1105 | }
1106 | if (i > last) {
1107 | out.append(input, last, i - last);
1108 | }
1109 | last = i + 1;
1110 | out.append('\'').append('\'');
1111 | }
1112 | }
1113 |
1114 | if (out == null) {
1115 | return string;
1116 | } else if (i > last) {
1117 | out.append(input, last, i - last);
1118 | }
1119 |
1120 | return out.toString();
1121 | }
1122 |
1123 | /**
1124 | * Escapes all necessary characters in the String so that it can be used in
1125 | * an XML doc.
1126 | *
1127 | * @param string the string to escape.
1128 | * @return the string with appropriate characters escaped.
1129 | */
1130 | public static String escapeForXML(String string) {
1131 | if (string == null) {
1132 | return null;
1133 | }
1134 | char ch;
1135 | int i = 0;
1136 | int last = 0;
1137 | char[] input = string.toCharArray();
1138 | int len = input.length;
1139 | StringBuilder out = new StringBuilder((int) (len * 1.3));
1140 | for (; i < len; i++) {
1141 | ch = input[i];
1142 | if (ch > '>') {
1143 | } else if (ch == '<') {
1144 | if (i > last) {
1145 | out.append(input, last, i - last);
1146 | }
1147 | last = i + 1;
1148 | out.append(LT_ENCODE);
1149 | } else if (ch == '&') {
1150 | if (i > last) {
1151 | out.append(input, last, i - last);
1152 | }
1153 | last = i + 1;
1154 | out.append(AMP_ENCODE);
1155 | } else if (ch == '"') {
1156 | if (i > last) {
1157 | out.append(input, last, i - last);
1158 | }
1159 | last = i + 1;
1160 | out.append(QUOTE_ENCODE);
1161 | }
1162 | }
1163 | if (last == 0) {
1164 | return string;
1165 | }
1166 | if (i > last) {
1167 | out.append(input, last, i - last);
1168 | }
1169 | return out.toString();
1170 | }
1171 |
1172 | /**
1173 | * Unescapes the String by converting XML escape sequences back into normal
1174 | * characters.
1175 | *
1176 | * @param string the string to unescape.
1177 | * @return the string with appropriate characters unescaped.
1178 | */
1179 | public static String unescapeFromXML(String string) {
1180 | string = replace(string, "<", "<");
1181 | string = replace(string, ">", ">");
1182 | string = replace(string, """, "\"");
1183 | return replace(string, "&", "&");
1184 | }
1185 | private static final char[] zeroArray
1186 | = "0000000000000000000000000000000000000000000000000000000000000000".toCharArray();
1187 |
1188 | /**
1189 | * Pads the supplied String with 0's to the specified length and returns the
1190 | * result as a new String. For example, if the initial String is "9999" and
1191 | * the desired length is 8, the result would be "00009999". This type of
1192 | * padding is useful for creating numerical values that need to be stored
1193 | * and sorted as character data. Note: the current implementation of this
1194 | * method allows for a maximum length of 64.
1195 | *
1196 | * @param string the original String to pad.
1197 | * @param length the desired length of the new padded String.
1198 | * @return a new String padded with the required number of 0's.
1199 | */
1200 | public static String zeroPadString(String string, int length) {
1201 | if (string == null || string.length() > length) {
1202 | return string;
1203 | }
1204 | StringBuilder buf = new StringBuilder(length);
1205 | buf.append(zeroArray, 0, length - string.length()).append(string);
1206 | return buf.toString();
1207 | }
1208 |
1209 | /**
1210 | * Formats a Date as a fifteen character long String made up of the Date's
1211 | * padded millisecond value.
1212 | *
1213 | * @param date
1214 | * @return a Date encoded as a String.
1215 | */
1216 | public static String dateToMillis(Date date) {
1217 | return zeroPadString(Long.toString(date.getTime()), 15);
1218 | }
1219 |
1220 | /**
1221 | * Returns a formatted String from time.
1222 | *
1223 | * @param diff the amount of elapsed time.
1224 | * @return the formatte String.
1225 | */
1226 | public static String getTimeFromLong(long diff) {
1227 | final String HOURS = "h";
1228 | final String MINUTES = "min";
1229 | //final String SECONDS = "sec";
1230 |
1231 | final long MS_IN_A_DAY = 1000 * 60 * 60 * 24;
1232 | final long MS_IN_AN_HOUR = 1000 * 60 * 60;
1233 | final long MS_IN_A_MINUTE = 1000 * 60;
1234 | final long MS_IN_A_SECOND = 1000;
1235 | //Date currentTime = new Date();
1236 | //long numDays = diff / MS_IN_A_DAY;
1237 | diff = diff % MS_IN_A_DAY;
1238 | long numHours = diff / MS_IN_AN_HOUR;
1239 | diff = diff % MS_IN_AN_HOUR;
1240 | long numMinutes = diff / MS_IN_A_MINUTE;
1241 | diff = diff % MS_IN_A_MINUTE;
1242 | //long numSeconds = diff / MS_IN_A_SECOND;
1243 | diff = diff % MS_IN_A_SECOND;
1244 | //long numMilliseconds = diff;
1245 |
1246 | StringBuffer buf = new StringBuffer();
1247 | if (numHours > 0) {
1248 | buf.append(numHours + " " + HOURS + ", ");
1249 | }
1250 |
1251 | if (numMinutes > 0) {
1252 | buf.append(numMinutes + " " + MINUTES);
1253 | }
1254 |
1255 | //buf.append(numSeconds + " " + SECONDS);
1256 | String result = buf.toString();
1257 |
1258 | if (numMinutes < 1) {
1259 | result = "< 1 minute";
1260 | }
1261 |
1262 | return result;
1263 | }
1264 |
1265 | public static boolean isBlank(String s) {
1266 | if (s == null) {
1267 | return true;
1268 | }
1269 | if (s.trim().length() == 0) {
1270 | return true;
1271 | }
1272 | return false;
1273 | }
1274 |
1275 | public static boolean isEmpty(String s) {
1276 | return isBlank(s);
1277 | }
1278 |
1279 | /**
1280 | *
1281 | * @param str
1282 | * @return
1283 | * @author mclaren.pan
1284 | */
1285 | public static boolean isNotBlank(String str) {
1286 | return !isBlank(str);
1287 | }
1288 |
1289 | /**
1290 | * Returns a collection of Strings as a comma-delimitted list of strings.
1291 | *
1292 | * @return a String representing the Collection.
1293 | */
1294 | public static String collectionToString(Collection
1329 | * user1@jivesoftware.com/home
1330 | *
and a maximum length of 20 characters, the abbreviate method will
1331 | * return:
1332 | *
1333 | * user1@jivesoftware.c...
1334 | *
1335 | *
1336 | * @param str the String to abbreviate.
1337 | * @param maxWidth the maximum size of the string, minus the ellipsis.
1338 | * @return the abbreviated String, or null if the string was
1339 | * null.
1340 | */
1341 | public static String abbreviate(String str, int maxWidth) {
1342 | if (null == str) {
1343 | return null;
1344 | }
1345 |
1346 | if (str.length() <= maxWidth) {
1347 | return str;
1348 | }
1349 |
1350 | return str.substring(0, maxWidth) + "...";
1351 | }
1352 |
1353 | /**
1354 | * Removes characters likely to enable Cross Site Scripting attacks from the
1355 | * provided input string. The characters that are removed from the input
1356 | * string, if present, are:
1357 | *
1358 | *
1359 | * < > " ' % ; ) ( & + -
1360 | *
1361 | *
1362 | * @param string input
1363 | * @return Input without certain characters;
1364 | */
1365 | public static String removeXSSCharacters(String input) {
1366 | final String[] xss = {"<", ">", "\"", "'", "%", ";", ")", "(", "&",
1367 | "+", "-"};
1368 | for (int i = 0; i < xss.length; i++) {
1369 | input = input.replace(xss[i], "");
1370 | }
1371 | return input;
1372 | }
1373 |
1374 | public static String valueOf(Object object) {
1375 |
1376 | return valueOf(object, "").trim();
1377 | }
1378 |
1379 | public static String valueOf(Object object, String defaultEmptyValue) {
1380 |
1381 | if (object == null) {
1382 | return defaultEmptyValue;
1383 | }
1384 |
1385 | return String.valueOf(object);
1386 | }
1387 | /**
1388 | * 判断对象是否为空
1389 | * @param object
1390 | * @return
1391 | */
1392 | public static boolean isEmptyOrNull(Object object) {
1393 |
1394 | if (StringUtils.valueOf(object).equals("")) {
1395 | return true;
1396 | }
1397 | if(StringUtils.valueOf(object).equals("null")){
1398 | return true;
1399 | }
1400 | return false;
1401 | }
1402 | /**
1403 | * 判断对象是否为,如果为空
1404 | * @param object
1405 | * @return
1406 | */
1407 | public static boolean isNotEmptyOrNull(Object object) {
1408 | return !isEmptyOrNull(object);
1409 | }
1410 |
1411 |
1412 | /**
1413 | *
1414 | * @Title: 去除字符串中的首尾空格、回车、换行符、制表符
1415 | * @Description:
1416 | * @Version 1.0
1417 | * @param str
1418 | * @return
1419 | */
1420 | public static String replaceBlank(String str) {
1421 | String dest = "";
1422 | if (str!=null) {
1423 | Pattern p = Pattern.compile("\\t|\r|\n");
1424 | Matcher m = p.matcher(str);
1425 | dest = m.replaceAll("");
1426 | return dest.trim();
1427 | }
1428 | return "";
1429 | }
1430 |
1431 | /**
1432 | * 仅将形如{0}替换为参数,不支持字符转义
1433 | *
1434 | * @param text
1435 | * @param paramsArray
1436 | * @return
1437 | */
1438 | public static String format(String text, String[] paramsArray) {
1439 | for (int i = 0; i < paramsArray.length; i++) {
1440 | String param = paramsArray[i];
1441 | if (param != null) {
1442 | text = text.replace("{" + i + "}", param);
1443 | }
1444 | }
1445 |
1446 | return text;
1447 | }
1448 |
1449 | }
1450 |
--------------------------------------------------------------------------------
/louie-order/pom.xml:
--------------------------------------------------------------------------------
1 |
16 |
18 |
17 |
19 |