edu.northwestern.at.utils.cache

## Class OldLRUCache<K,V>

- java.lang.Object
- - edu.northwestern.at.utils.cache.OldLRUCache<K,V>

- All Implemented Interfaces:
    Cache<K,V>

      public class OldLRUCache<K,V>
      extends java.lang.Object
      implements Cache<K,V>

  Fixed maximum size cache employing least-recently used method to age entries.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `OldLRUCache.Node`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected SoftReferenceCache<K,OldLRUCache.Node>` | `cache` SoftReferenceCache which holds actual cached entries.
    `protected OldLRUCache.Node` | `head`
    `protected int` | `maxEntries`
    `protected OldLRUCache.Node` | `tail`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OldLRUCache(int maxEntries)` Create a new cache.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Clear all entries in the cache.
    `boolean` | `containsKey(K key)` True if cache contains a specified key.
    `protected boolean` | `deleteLeastRecentlyUsed()`
    `V` | `get(K key)` Retrieve a cached value.
    `int` | `getMaxSize()` Returns the maximum number of items allowed in the cache.
    `protected void` | `insertNode(OldLRUCache.Node node)`
    `V` | `put(K key, V value)` Add or replace a cached value.
    `V` | `remove(K key)` Remove a specific entry from the cache.
    `protected void` | `removeNode(OldLRUCache.Node node)`
    `int` | `size()` Return current size of cache.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### maxEntries

          protected int maxEntries

    - #### cache

          protected SoftReferenceCache<K,OldLRUCache.Node> cache

      SoftReferenceCache which holds actual cached entries.

    - #### head

          protected OldLRUCache.Node head

    - #### tail

          protected OldLRUCache.Node tail

  - ### Constructor Detail

    - #### OldLRUCache

          public OldLRUCache(int maxEntries)

      Create a new cache.
      Parameters:
        `maxEntries` - Maximum number of entries allowed.

  - ### Method Detail

    - #### clear

          public void clear()

      Clear all entries in the cache.
      Specified by:
        `clear` in interface `Cache<K,V>`

    - #### containsKey

          public boolean containsKey(K key)

      True if cache contains a specified key.
      Specified by:
        `containsKey` in interface `Cache<K,V>`
      Parameters:
        `key` - The key to look up.
      Returns:
        true if the cache contains the key.

    - #### getMaxSize

          public int getMaxSize()

      Returns the maximum number of items allowed in the cache.
      Returns:
        Maximum number of entries allowed in cache.

    - #### get

          public V get(K key)

      Retrieve a cached value.
      Specified by:
        `get` in interface `Cache<K,V>`
      Parameters:
        `key` - The key of the entry to retrieve.
      Returns:
        The value of the cached entry specified by key; null if the cache does not contain the key.

    - #### put

          public V put(K key,
              V value)

      Add or replace a cached value.
      Specified by:
        `put` in interface `Cache<K,V>`
      Parameters:
        `key` - The key of the entry to add.
        `value` - The value of the entry to add.
      Returns:
        The value of any existing cached entry specified by the key; null if the cache does not contain the key.

    - #### remove

          public V remove(K key)

      Remove a specific entry from the cache.
      Specified by:
        `remove` in interface `Cache<K,V>`
      Parameters:
        `key` - The key of the entry to remove.
      Returns:
        The entry removed, or null if none.

    - #### size

          public int size()

      Return current size of cache.
      Specified by:
        `size` in interface `Cache<K,V>`
      Returns:
        Number of entries (keys) currently stored in cache.

    - #### deleteLeastRecentlyUsed

          protected boolean deleteLeastRecentlyUsed()

    - #### insertNode

          protected void insertNode(OldLRUCache.Node node)

    - #### removeNode

          protected void removeNode(OldLRUCache.Node node)