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

org.hibernate.envers.internal.tools.Tools Maven / Gradle / Ivy

There is a newer version: 7.0.0.Beta2
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * 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.envers.internal.tools;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.envers.tools.Pair;

/**
 * @author Adam Warski (adam at warski dot org)
 * @author HernпїЅn Chanfreau
 * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
 * @author Chris Cranford
 */
public abstract class Tools {
	public static  Map newHashMap() {
		return new HashMap<>();
	}

	public static  Set newHashSet() {
		return new HashSet<>();
	}

	public static  Map newLinkedHashMap() {
		return new LinkedHashMap<>();
	}

	public static  List iteratorToList(Iterator iter) {
		final List ret = new ArrayList<>();
		while ( iter.hasNext() ) {
			ret.add( iter.next() );
		}

		return ret;
	}

	public static  List collectionToList(Collection collection) {
		if ( collection instanceof List ) {
			return (List) collection;
		}
		else {
			return new ArrayList<>( collection );
		}
	}

	/**
	 * Transforms a list of arbitrary elements to a list of index-element pairs.
	 *
	 * @param list List to transform.
	 *
	 * @return A list of pairs: ((0, element_at_index_0), (1, element_at_index_1), ...)
	 */
	public static  List> listToIndexElementPairList(List list) {
		final List> ret = new ArrayList<>();
		final Iterator listIter = list.iterator();
		for ( int i = 0; i < list.size(); i++ ) {
			ret.add( Pair.make( i, listIter.next() ) );
		}

		return ret;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy