All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mizhousoft.commons.lang.StringUtils Maven / Gradle / Ivy

The newest version!
package com.mizhousoft.commons.lang;

import java.text.Normalizer;
import java.text.Normalizer.Form;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang3.ArrayUtils;

/**
 * 字符串工具类
 *
 * @version
 */
public abstract class StringUtils
{
	private static final String SEPARATOR = ",";

	/**
	 * 字符串归一化
	 * 
	 * @param data
	 * @return
	 */
	public static String normalize(String data)
	{
		if (org.apache.commons.lang3.StringUtils.isBlank(data))
		{
			return data;
		}

		return Normalizer.normalize(data, Form.NFKC);
	}

	/**
	 * byte转字符串
	 * 
	 * @param bytes
	 * @return
	 */
	public static String toUTF8String(final byte[] bytes)
	{
		String data = new String(bytes, CharEncoding.UTF8);
		return data;
	}

	public static String join(Set list)
	{
		return org.apache.commons.lang3.StringUtils.join(list, SEPARATOR);
	}

	public static Set splitToIntSet(String data)
	{
		String[] values = org.apache.commons.lang3.StringUtils.split(data, SEPARATOR);

		if (!ArrayUtils.isEmpty(values))
		{
			Set results = new HashSet<>(values.length);
			for (String value : values)
			{
				results.add(Integer.valueOf(value));
			}

			return results;
		}
		else
		{
			return new HashSet<>(0);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy