Class LRUSet<ELEMENTTYPE>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<ELEMENTTYPE>
-
- com.helger.commons.collection.map.LRUSet<ELEMENTTYPE>
-
- Type Parameters:
ELEMENTTYPE- Element type
- All Implemented Interfaces:
ICommonsCollection<ELEMENTTYPE>,ICommonsIterable<ELEMENTTYPE>,ICommonsOrderedSet<ELEMENTTYPE>,ICommonsSet<ELEMENTTYPE>,ICloneable<ICommonsSet<ELEMENTTYPE>>,IHasSize,Iterable<ELEMENTTYPE>,Collection<ELEMENTTYPE>,Set<ELEMENTTYPE>
@NotThreadSafe @UseDirectEqualsAndHashCode public class LRUSet<ELEMENTTYPE> extends AbstractSet<ELEMENTTYPE> implements ICommonsOrderedSet<ELEMENTTYPE>
A special ordered set, that has an upper limit of contained elements. It is therefore a "Last Recently Used" cache.
The underlying data structure is aLRUMapmap.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description LRUSet(int nMaxSize)LRUSet(LRUSet<ELEMENTTYPE> rhs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(ELEMENTTYPE aItem)booleanequals(Object o)LRUSet<ELEMENTTYPE>getClone()intgetMaxSize()inthashCode()Iterator<ELEMENTTYPE>iterator()protected voidonRemoveEldestEntry(int nSize, ELEMENTTYPE aEldest)Protected method that is invoked every time an element is removed from the cache, because the maximum size is exceeded.intsize()StringtoString()-
Methods inherited from class java.util.AbstractSet
removeAll
-
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsCollection
addAll, addAll, addAll, addAll, addAll, addAll, addAll, addAll, addAllMapped, addAllMapped, addAllMapped, addAllMapped, addAllMapped, addAllMapped, addIf, addIfNotNull, addObject, getAtIndex, getAtIndex, getAtIndex, getAtIndex, getAtIndexMapped, getAtIndexMapped, getAtIndexMapped, getAtIndexMapped, getCopyAsList, getCount, getSorted, iterator2, removeAll, removeObject, set, setAll, setAll, setAllMapped, setAllMapped
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsIterable
containsAny, containsNone, containsOnly, findAll, findAllInstanceOf, findAllMapped, findAllMapped, findAllMapped, findFirst, findFirst, findFirstIndex, findFirstMapped, findFirstMapped, findLastIndex, forEachBreakable, forEachByIndex, forEachThrowing, getCount
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsOrderedSet
createInstance, getAll, getAllInstanceOf, getAllMapped, getAllMapped, getFirst, getFirst, getLast, getLast
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsSet
getAsUnmodifiable, replace
-
Methods inherited from interface com.helger.commons.lang.IHasSize
isEmpty, isNotEmpty
-
-
-
-
Constructor Detail
-
LRUSet
public LRUSet(@Nonnegative int nMaxSize)
-
LRUSet
public LRUSet(@Nonnegative LRUSet<ELEMENTTYPE> rhs)
-
-
Method Detail
-
getClone
@Nonnull public LRUSet<ELEMENTTYPE> getClone()
- Specified by:
getClonein interfaceICloneable<ELEMENTTYPE>- Specified by:
getClonein interfaceICommonsOrderedSet<ELEMENTTYPE>- Returns:
- A 100% deep-copy of the implementing class.
-
onRemoveEldestEntry
@OverrideOnDemand protected void onRemoveEldestEntry(@Nonnegative int nSize, @Nonnull ELEMENTTYPE aEldest)
Protected method that is invoked every time an element is removed from the cache, because the maximum size is exceeded.- Parameters:
nSize- Current size of the map. Always ≥ 0.aEldest- The entry that is to be removed. Nevernull.
-
getMaxSize
@Nonnegative public final int getMaxSize()
- Returns:
- The maximum number of elements that can reside in this cache.
-
add
public boolean add(@Nullable ELEMENTTYPE aItem)
- Specified by:
addin interfaceCollection<ELEMENTTYPE>- Specified by:
addin interfaceSet<ELEMENTTYPE>- Overrides:
addin classAbstractCollection<ELEMENTTYPE>
-
iterator
@Nonnull public Iterator<ELEMENTTYPE> iterator()
- Specified by:
iteratorin interfaceCollection<ELEMENTTYPE>- Specified by:
iteratorin interfaceIterable<ELEMENTTYPE>- Specified by:
iteratorin interfaceSet<ELEMENTTYPE>- Specified by:
iteratorin classAbstractCollection<ELEMENTTYPE>
-
size
@Nonnegative public int size()
- Specified by:
sizein interfaceCollection<ELEMENTTYPE>- Specified by:
sizein interfaceIHasSize- Specified by:
sizein interfaceSet<ELEMENTTYPE>- Specified by:
sizein classAbstractCollection<ELEMENTTYPE>- Returns:
- The number of contained elements. Always ≥ 0.
-
equals
public boolean equals(Object o)
- Specified by:
equalsin interfaceCollection<ELEMENTTYPE>- Specified by:
equalsin interfaceSet<ELEMENTTYPE>- Overrides:
equalsin classAbstractSet<ELEMENTTYPE>
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<ELEMENTTYPE>- Specified by:
hashCodein interfaceSet<ELEMENTTYPE>- Overrides:
hashCodein classAbstractSet<ELEMENTTYPE>
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection<ELEMENTTYPE>
-
-