org.hibernate.search.util.impl.Maps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-search-engine Show documentation
Show all versions of hibernate-search-engine Show documentation
Core of the Object/Lucene mapper, query engine and index management
/*
* 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