Uploaded image for project: 'OpenNLP'
  1. OpenNLP
  2. OPENNLP-887

Replace the Cache class with a LinkedHashMap

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.7.0
    • None
    • None

    Description

      The existing cache implementation could be replaced with java.util.LinkedHashMap. This change would replace our custom implementation with an implementation which will be maintained for us.

      To have the same behaviour as our implementation LinkedHashMap must be subclasses. The LinkedHashMap.removeEldestEntry must be overwritten and return true if size limit is reached.

      This could be something like this:

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

      public class Cache<K, V> extends LinkedHashMap<K,V> {
      private final int capacity;

      public Cache(int capacity)

      { this.capacity = capacity; }

      @Override
      protected boolean removeEldestEntry(Map.Entry<K,V> eldest)

      { return this.size() > this.capacity; }

      }

      Attachments

        Issue Links

          Activity

            People

              smarthi Suneel Marthi
              joern Jörn Kottmann
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: