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

org.hibernate.search.util.impl.CollectionHelper Maven / Gradle / Ivy

/*
 * Hibernate Search, full-text search for your domain model
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later
 * See the lgpl.txt file in the root directory or .
 */

package org.hibernate.search.util.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * Provides some methods for simplified collection instantiation.
 *
 * @author Gunnar Morling
 * @author Hardy Ferentschik
 */
public final class CollectionHelper {

	private CollectionHelper() {
		// not allowed
	}

	public static  HashMap newHashMap() {
		return new HashMap();
	}

	public static  HashMap newHashMap(int size) {
		return new HashMap( size );
	}

	public static  SortedMap newSortedMap() {
		return new TreeMap();
	}

	public static  HashSet newHashSet() {
		return new HashSet();
	}

	public static  ArrayList newArrayList() {
		return new ArrayList();
	}

	public static  ArrayList newArrayList(final int size) {
		return new ArrayList( size );
	}

	public static  Set asSet(T... ts) {
		HashSet set = new HashSet( ts.length );
		Collections.addAll( set, ts );
		return set;
	}

	public static  List toImmutableList(final Collection c) {
		if ( c.isEmpty() ) {
			return Collections.emptyList();
		}
		else {
			return Collections.unmodifiableList( new ArrayList( c ) );
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy