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

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

There is a newer version: 5.11.12.Final
Show newest version
/*
 * 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.EnumSet;
import java.util.concurrent.ConcurrentMap;

import org.hibernate.search.util.impl.ConcurrentReferenceHashMap.Option;
import org.hibernate.search.util.impl.ConcurrentReferenceHashMap.ReferenceType;

/**
 * Helper class to create maps with commonly needed constructors.
 *
 * @author Sanne Grinovero
 */
public class Maps {

	private Maps() {
		//not to be constructed
	}

	/**
	 * Creates a ConcurrentMap using weak references to keys, so that garbage collection
	 * of the key allows to remove the value from the map.
	 * Comparison on the keys is based on identity reference.
	 *
	 * @param  the key type in the map
	 * @param  the value type in the map
	 * @param initialSize for tuning of the initial size of the Map
	 * @param concurrencyLevel the estimated number of concurrently
	 * updating threads. The implementation performs internal sizing
	 * to try to accommodate this many threads.
	 * @return a new concurrent map with the properties described above.
	 */
	public static  ConcurrentMap createIdentityWeakKeyConcurrentMap(int initialSize, int concurrencyLevel) {
		return new ConcurrentReferenceHashMap<>(
				initialSize, 0.75f, concurrencyLevel,
				ReferenceType.WEAK, ReferenceType.STRONG,
				EnumSet.of( Option.IDENTITY_COMPARISONS ) );
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy