Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.util;
 import java.util.Map;

Helper for simple bounded LRU maps used for reusing lookup values.

Note that serialization behavior is such that contents are NOT serialized, on assumption that all use cases are for caching where persistence does not make sense. The only thing serialized is the cache size of Map.

public class LRUMap<K,V> extends LinkedHashMap<K,V>
    private static final long serialVersionUID = 1L;
    protected final int _maxEntries;
    public LRUMap(int initialEntriesint maxEntries)
        super(initialEntries, 0.8f, true);
         = maxEntries;
    protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
        return size() > ;
    /* Serializable overrides

Ugly hack, to work through the requirement that _value is indeed final, and that JDK serialization won't call ctor(s) if Serializable is implemented.

    protected transient int _jdkSerializeMaxEntries;
    private void readObject(ObjectInputStream inthrows IOException {
         = in.readInt();
    private void writeObject(ObjectOutputStream outthrows IOException {
    protected Object readResolve() {
New to GrepCode? Check out our FAQ X