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

com.fasterxml.jackson.databind.util.LRUMap Maven / Gradle / Ivy

There is a newer version: 2.22.2
Show newest version
package com.fasterxml.jackson.databind.util;

import java.io.*;
import java.util.LinkedHashMap;
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 extends LinkedHashMap implements java.io.Serializable { private static final long serialVersionUID = 1L; protected final int _maxEntries; public LRUMap(int initialEntries, int maxEntries) { super(initialEntries, 0.8f, true); _maxEntries = maxEntries; } @Override protected boolean removeEldestEntry(Map.Entry eldest) { return size() > _maxEntries; } /* /********************************************************** /* 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. * * @since 2.1 */ protected transient int _jdkSerializeMaxEntries; private void readObject(ObjectInputStream in) throws IOException { _jdkSerializeMaxEntries = in.readInt(); } private void writeObject(ObjectOutputStream out) throws IOException { out.writeInt(_jdkSerializeMaxEntries); } protected Object readResolve() { return new LRUMap(_jdkSerializeMaxEntries, _jdkSerializeMaxEntries); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy