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

com.github.yydf.struts.util.ObjectUtils Maven / Gradle / Ivy

The newest version!
package com.github.yydf.struts.util;

import java.math.BigDecimal;

public class ObjectUtils {

	public static Object[] mergeArray(Object[] array, Object... args) {
		if (array.length == 0 && args.length == 0)
			return new Object[0];
		if (array.length == 0)
			return args;
		if (args.length == 0)
			return array;
		Object[] temp = new Object[array.length + args.length];
		System.arraycopy(array, 0, temp, 0, array.length);
		System.arraycopy(args, 0, temp, array.length, args.length);
		return temp;
	}

	public static Integer toInteger(Object obj) {
		if (StringUtils.isEmpty(obj))
			return null;
		if (obj instanceof BigDecimal)
			return ((BigDecimal) obj).intValue();
		return Integer.parseInt(obj.toString());
	}

	public static Long toLong(Object obj) {
		if (StringUtils.isEmpty(obj))
			return null;
		return Long.parseLong(obj.toString());
	}

	public static Double toDouble(Object obj) {
		if (StringUtils.isEmpty(obj))
			return null;
		return Double.parseDouble(obj.toString());
	}

	public static Boolean toBoolean(Object obj) {
		if (StringUtils.isEmpty(obj))
			return null;
		return Boolean.parseBoolean(obj.toString());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy