Java tutorial
/* * Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group. * * 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 com.jms.notify.utils; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.UUID; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * String. * @company?? www.roncoo.com. * @author zenghao */ public final class StringUtil { private static final Log LOG = LogFactory.getLog(StringUtil.class); /** * ?,??. */ private StringUtil() { } /** * ? . ?? * * @? @param str * @? @return * @return boolean * @throws */ public static boolean isEmpty(String str) { return null == str || "".equals(str); } /** * ?. ?? * * @? @param obj * @? @return * @return boolean * @throws */ public static boolean isEmpty(Object[] obj) { return null == obj || 0 == obj.length; } /** * ?. ?? * * @? @param obj * @? @return * @return boolean * @throws */ public static boolean isEmpty(Object obj) { if (null == obj) { return true; } if (obj instanceof String) { return ((String) obj).trim().isEmpty(); } return !(obj instanceof Number) ? false : false; } /** * ??. ?? * * @? @param obj * @? @return * @return boolean * @throws */ public static boolean isEmpty(List<?> obj) { return null == obj || obj.isEmpty(); } /** * Map??. ?? * * @? @param obj * @? @return * @return boolean * @throws */ public static boolean isEmpty(Map<?, ?> obj) { return null == obj || obj.isEmpty(); } /** * ?????. ?? * * @? @param fileName * @? @return * @return String * @throws */ public static String getExt(String fileName) { return fileName.substring(fileName.lastIndexOf(".") + 1); } /** * ?32UUID. * * @author WuShuicheng. * @return uuid. */ public static String get32UUID() { return UUID.randomUUID().toString().replace("-", ""); } /** * ?36UUID. * * @author WuShuicheng. * @return uuid. */ public static String get36UUID() { return UUID.randomUUID().toString(); } /** * ???false. * * @author WuShuicheng . * @param str * ? . * @return true or false . */ public static boolean isNumeric(String str) { if (StringUtils.isBlank(str)) { return false; } else { return str.matches("\\d*"); } } /** * utf-8??? * * @param content * @return */ public static int getByteSize(String content) { int size = 0; if (null != content) { try { // utf-8??3 size = content.getBytes("utf-8").length; } catch (UnsupportedEncodingException e) { LOG.error(e); } } return size; } /** * ?in?. ?? * * @? @param ids * @? @return * @return String * @throws */ public static List<String> getInParam(String param) { boolean flag = param.contains(","); List<String> list = new ArrayList<String>(); if (flag) { list = Arrays.asList(param.split(",")); } else { list.add(param); } return list; } }