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

org.mockserver.collections.CircularHashMap Maven / Gradle / Ivy

There is a newer version: 5.15.0
Show newest version
package org.mockserver.collections;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author jamesdbloom
 */
public class CircularHashMap extends LinkedHashMap {
    static final long serialVersionUID = 1530623482381786485L;
    private final int maxSize;

    public CircularHashMap(int maxSize) {
        this.maxSize = maxSize;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry eldest) {
        return size() > maxSize;
    }

    public K findKey(V value) {
        for (Map.Entry entry : entrySet()) {
            V entryValue = entry.getValue();
            if (entryValue == value || (value != null && value.equals(entryValue))) {
                return entry.getKey();
            }
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy