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

com.untzuntz.ustackserverapi.util.DataUtil Maven / Gradle / Ivy

There is a newer version: 2.1.115
Show newest version
package com.untzuntz.ustackserverapi.util;

import java.lang.reflect.Array;
import java.util.Collections;
import java.util.List;

public class DataUtil {

	/**
	 * Checks if the list is null, return an empty list
	 * @param other
	 * @return
	 */
	public static  List safeList(List other)
	{
		return other == null ? Collections.emptyList() : other;
	}
	
	/**
	 * Checks if the array is null, return an empty array
	 * @param other
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static  T[] safeArray(T[] other, Class clazz)
	{
		if (other == null)
			return (T[])Array.newInstance(clazz, 0);
		
		return other;
	}

	/**
	 * Closes a stream, handling all exceptions
	 * @param in
	 */
	public static void close(java.io.Closeable in) 
	{
		if (in == null)
			return;
		
		try {
			in.close();
		} catch (Exception e) { 
			// do nothing
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy