Package org.geotools.util
Class SoftValueHashMap<K,V> 
Object
AbstractMap<K,V>
 
SoftValueHashMap<K,V> 
- Type Parameters:
- K- The type of keys in the map.
- V- The type of values in the map.
- All Implemented Interfaces:
- Map<K,- V> 
A hash map implementation that uses soft references, leaving memory when an entry is not
 used anymore and memory is low.
 
This map implementation actually maintains some of the first entries as hard references. Only oldest entries are retained by soft references, in order to avoid too aggressive garbage collection. The amount of entries to retain by hard reference is specified at construction time.
This map is thread-safe. It accepts the null key; it does not accept the null value. Usage of value, key or entry collections are supported. The iterator on the ConcurrentHashMap is weakly consistent.
- Since:
- 2.3
- Author:
- Simone Giannecchini, Martin Desruisseaux, Ugo Moschini
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceA delegate that can be used to perform clean up operation, such as resource closing, before the values cached in soft part of the cache gets disposed ofNested classes/interfaces inherited from class AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> 
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a map with the default hard references count.SoftValueHashMap(int hardReferencesCount) Creates a map with the specified hard references count.SoftValueHashMap(int hardReferencesCount, SoftValueHashMap.ValueCleaner cleaner) Creates a map with the specified hard references count.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclear()Removes all mappings from this map.booleancontainsKey(Object key) Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object value) Returnstrueif this map maps one or more keys to this value.entrySet()Returns a set view of the mappings contained in this map.booleanCompares the specified object with this map for equality.Returns the value to which this map maps the specified key.intReturns the number of hard references kept in this cacheinthashCode()Returns the hash code value for this map.Associates the specified value with the specified key in this map.voidCopies all of the mappings from the specified map to this map.Removes the mapping for this key from this map if present.intsize()Returns the number of entries in this map.toString()Returns a string representation of this map.Methods inherited from class AbstractMapclone, isEmpty, keySet, valuesMethods inherited from interface Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Field Details- 
cleanerThe eventual cleaner
 
- 
- 
Constructor Details- 
SoftValueHashMappublic SoftValueHashMap()Creates a map with the default hard references count.
- 
SoftValueHashMappublic SoftValueHashMap(int hardReferencesCount) Creates a map with the specified hard references count.- Parameters:
- hardReferencesCount- The maximal number of hard references to keep.
 
- 
SoftValueHashMapCreates a map with the specified hard references count.- Parameters:
- hardReferencesCount- The maximal number of hard references to keep.
 
 
- 
- 
Method Details- 
getHardReferencesCountpublic int getHardReferencesCount()Returns the number of hard references kept in this cache
- 
sizepublic int size()Returns the number of entries in this map.
- 
containsKeyReturnstrueif this map contains a mapping for the specified key.- Specified by:
- containsKeyin interface- Map<K,- V> 
- Overrides:
- containsKeyin class- AbstractMap<K,- V> 
 
- 
containsValueReturnstrueif this map maps one or more keys to this value.- Specified by:
- containsValuein interface- Map<K,- V> 
- Overrides:
- containsValuein class- AbstractMap<K,- V> 
 
- 
getReturns the value to which this map maps the specified key. Returnsnullif the map contains no mapping for this key, or the value has been garbage collected.
- 
putAssociates the specified value with the specified key in this map.- Specified by:
- putin interface- Map<K,- V> 
- Overrides:
- putin class- AbstractMap<K,- V> 
- Parameters:
- key- Key with which the specified value is to be associated.
- value- Value to be associated with the specified key. The value can't be null.
- Returns:
- Previous value associated with specified key, or nullif there was no mapping for key.
 
- 
putAllCopies all of the mappings from the specified map to this map.
- 
removeRemoves the mapping for this key from this map if present.
- 
clearpublic void clear()Removes all mappings from this map.
- 
entrySetReturns a set view of the mappings contained in this map.
- 
equalsCompares the specified object with this map for equality.
- 
hashCodepublic int hashCode()Returns the hash code value for this map.
- 
toStringReturns a string representation of this map.- Overrides:
- toStringin class- AbstractMap<K,- V> 
 
 
-