|
Last change
on this file since 16082 was 16082, checked in by simon04, 6 years ago |
|
fix Java warning, Javadoc warning
|
|
File size:
734 bytes
|
| Line | |
|---|
| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui.util;
|
|---|
| 3 |
|
|---|
| 4 | import java.util.LinkedHashMap;
|
|---|
| 5 | import java.util.Map;
|
|---|
| 6 |
|
|---|
| 7 | /**
|
|---|
| 8 | * LRU cache
|
|---|
| 9 | * @see <a href="http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html">
|
|---|
| 10 | * Java Planet: How to set up a simple LRU cache using LinkedHashMap</a>
|
|---|
| 11 | */
|
|---|
| 12 | public final class LruCache<K, V> extends LinkedHashMap<K, V> {
|
|---|
| 13 | private static final long serialVersionUID = 1L;
|
|---|
| 14 | private final int capacity;
|
|---|
| 15 |
|
|---|
| 16 | public LruCache(int capacity) {
|
|---|
| 17 | super(capacity + 1, 1.1f, true);
|
|---|
| 18 | this.capacity = capacity;
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | @Override
|
|---|
| 22 | protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
|
|---|
| 23 | return size() > capacity;
|
|---|
| 24 | }
|
|---|
| 25 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.