package com.base.core.utiles;

import java.util.*;

/**
 * List Utility, which has the following functions:<br>
 * 1. check a List is Null or Empty<br>
 * 
 * @author samirliu on 2015-11-23
 * 
 * @version v0.0.1
 * 
 */
public class ListUtils {

	/**
	 * Check a List is Null or Empty
	 * 
	 * @param list
	 * 			list that will be checked
	 * @return
	 * 			<b>false</b> means neither null nor empty, <b>true</b> means null or empty
	 */
	@SuppressWarnings("rawtypes")
	public static boolean isNoE(List list) {
		return (list != null && list.size() > 0) ? false : true;
	}
	

	
	/**
	 * Start a new line
	 */
	public static void println() {
		System.out.println();
	}
	
	/**
	 * Print t onto the Console in one line
	 * 
	 * @param t
	 * 			Generic type t that will be printed
	 */
	public static <T> void print(T t) {
		System.out.print(t);
	}
	
	/**
	 * Print t onto the Console in a new line
	 * 
	 * @param t
	 * 			Generic type t that will be printed
	 */
	public static <T> void println(T t) {
		System.out.println(t);
	}
	
	/**
	 * return a new instance of {@link HashMap}
	 * 
	 * @return
	 * 			an instance of {@link HashMap}
	 */
	public static <K, V> Map<K, V> newHashMap() {
		return new HashMap<K, V>();
	}
	
	/**
	 * return a new instance of {@link ArrayList}
	 * 
	 * @return
	 * 			an instance of {@link ArrayList}
	 */
	public static <E> List<E> newArrayList() {
		return new ArrayList<E>();
	}
	
	/**
	 * return a new instance of {@link Arraylist} with initialized Array of E type
	 * 
	 * @param es
	 * 			Initialized Array of E type
	 * @return
	 * 			an instance of {@link ArrayList} with initialized Array of E type
	 */
	@SuppressWarnings("unchecked")
	public static <E> List<E> newArrayList(E... e1) {
		List<E> es = newArrayList();
		for (E e : e1) {
			es.add(e);
		}
		return es;
	}
	
	/**
	 * return a new Instance of {@link HashSet}
	 * 
	 * @return
	 * 			an instance of {@link HashSet}
	 */
	public static <E> Set<E> newHashSet() {
		return new HashSet<E>();
	}
	
	/**
	 * return a new instance of {@link HashSet} with initialized Array of E type
	 * 
	 * @param es
	 * 			Initialized Array of E type
	 * @return
	 * 			an instance of {@link HashSet} with initialized Array of E type
	 */
	@SuppressWarnings("unchecked")
	public static <E> Set<E> newHashSet(E... e1) {
		Set<E> es = newHashSet();
		for (E e : e1) {
			es.add(e);
		}
		return es;
	}
	
	/**
	 * return a new instance of {@link LinkedList}
	 * 
	 * @return
	 * 			an instance of {@link LinkedList}
	 */
	public static <E> List<E> newLinkList() {
		return new LinkedList<E>();
	}
	
	/**
	 * return a new instance of {@link LinkedList} with initialized Array of E type
	 * 
	 * @param es
	 * 			Initialized Array of E type
	 * @return
	 * 			an instance of {@link LinkedList} with initialized Array of E type
	 */
	@SuppressWarnings("unchecked")
	public static <E> List<E> newLinkList(E... e1) {
		List<E> es = newLinkList();
		for (E e : e1) {
			es.add(e);
		}
		return es;
	}
	
	/**
	 * return a new instance of {@link Vector}
	 * 
	 * @return
	 * 			an instance of {@link Vector}
	 */
	public static <E> List<E> newVector() {
		return new Vector<E>();
	}
	
	/**
	 * return a new instance of {@link Vector} with initialized Array of E type
	 * 
	 * @param es
	 * 			Initialized Array of E type
	 * @return
	 * 			an instance of {@link Vector} with initialized Array of E type
	 */
	@SuppressWarnings("unchecked")
	public static <E> List<E> newVector(E... e1) {
		List<E> es = newVector();
		for (E e : e1) {
			es.add(e);
		}
		return es;
	}
	
	public static void main(String[] args) {
		
	}

}
