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

com.github.napp.util.mass.LazyInitializers Maven / Gradle / Ivy

/**
 *
 */
package com.github.napp.util.mass;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import com.github.napp.util.mass.MapUtil.LazyInit;



/**
 * @author Alexandru Bledea
 * @since Oct 19, 2013
 */
public class LazyInitializers {

	public static final LazyInit COLLECTION_ARRAYLIST = new LazyInit() {

		/* (non-Javadoc)
		 * @see java.util.concurrent.Callable#call()
		 */
		@Override
		public Collection call() throws Exception {
			return new ArrayList();
		}

	};

	public static final LazyInit COLLECTION_HASHSET = new LazyInit() {

		/* (non-Javadoc)
		 * @see java.util.concurrent.Callable#call()
		 */
		@Override
		public Collection call() throws Exception {
			return new HashSet();
		}

	};

	public static final LazyInit SET_HASHSET = new LazyInit() {

		/* (non-Javadoc)
		 * @see java.util.concurrent.Callable#call()
		 */
		@Override
		public Set call() throws Exception {
			return new HashSet();
		}

	};

	public static final LazyInit SET_TREESET = new LazyInit() {

		/* (non-Javadoc)
		 * @see java.util.concurrent.Callable#call()
		 */
		@Override
		public Set call() throws Exception {
			return new TreeSet();
		}
	};

	public static final LazyInit LIST_ARRAYLIST = new LazyInit() {

		/* (non-Javadoc)
		 * @see java.util.concurrent.Callable#call()
		 */
		@Override
		public List call() throws Exception {
			return new ArrayList();
		}
	};

	public static final LazyInit MAP_HASHMAP = new LazyInit() {

		/* (non-Javadoc)
		 * @see java.util.concurrent.Callable#call()
		 */
		@Override
		public Map call() throws Exception {
			return new HashMap();
		}
	};

	public static final LazyInit MAP_LINKEDHASHMAP = new LazyInit() {

		/* (non-Javadoc)
		 * @see java.util.concurrent.Callable#call()
		 */
		@Override
		public Map call() throws Exception {
			return new LinkedHashMap();
		}
	};

	public static final LazyInit MAP_TREEMAP = new LazyInit() {

		/* (non-Javadoc)
		 * @see java.util.concurrent.Callable#call()
		 */
		@Override
		public Map call() throws Exception {
			return new TreeMap();
		}
	};

	/**
	 * @param comparator
	 * @return
	 */
	public static final  LazyInit createTreeMapInitializer(final Comparator comparator) {
		if (comparator == null) {
			return MAP_TREEMAP;
		}
		return new LazyInit() {

			/* (non-Javadoc)
			 * @see java.util.concurrent.Callable#call()
			 */
			@Override
			public Map call() throws Exception {
				return new TreeMap(comparator);
			}
		};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy