Class MruList

  • All Implemented Interfaces:
    java.lang.Iterable, java.util.Collection, java.util.Set
    Direct Known Subclasses:
    MruMap.InnerMruList

    public class MruList
    extends java.lang.Object
    implements java.util.Set
    Most recently used list implementation. It support entries expiration by access time.
    Version:
    $Id: MruList.java,v 1.4 2005/04/26 17:41:59 thlee Exp $ $Name: $
    Author:
    TiongHiang Lee (thlee@onemindsoft.org)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  MruList.MruEntry
      Represent an entry in the MruList
      protected static class  MruList.MruIterator
      An iterator to the entries
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.HashMap _entryMap
      the entries map *
      private long _lastCleanupTime
      the last cleanup time *
      private java.util.TreeSet _mruList
      the sorted mru list *
      private long _sizeLimit
      the size *
      private long _timeout
      the timeout *
    • Constructor Summary

      Constructors 
      Constructor Description
      MruList()
      MruList​(long sizeLimit, long timeout)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean access​(java.lang.Object o)
      Record that object o is being accessed.
      boolean add​(java.lang.Object o)  
      boolean addAll​(java.util.Collection c)
      void clear()
      boolean contains​(java.lang.Object o)
      boolean containsAll​(java.util.Collection c)
      void expireEntries​(long t)
      Expire the entries that was last access longer that time t Document this method.
      protected void expireEntry​(java.lang.Object obj)
      Remove the entry from the MruList
      long getLastAccessTime​(java.lang.Object obj)
      Get the last access time object obj
      boolean isEmpty()
      java.util.Iterator iterator()
      boolean remove​(java.lang.Object o)
      boolean removeAll​(java.util.Collection c)
      boolean retainAll​(java.util.Collection c)
      int size()
      java.lang.Object[] toArray()
      java.lang.Object[] toArray​(java.lang.Object[] a)
      void truncateEntries​(long size)
      Truncate the entries to specific size
      protected void truncateEntry​(java.lang.Object obj)
      Remove the object from the MruList
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        equals, hashCode, spliterator
    • Field Detail

      • _entryMap

        private java.util.HashMap _entryMap
        the entries map *
      • _lastCleanupTime

        private long _lastCleanupTime
        the last cleanup time *
      • _mruList

        private java.util.TreeSet _mruList
        the sorted mru list *
      • _sizeLimit

        private long _sizeLimit
        the size *
      • _timeout

        private long _timeout
        the timeout *
    • Constructor Detail

      • MruList

        public MruList()
      • MruList

        public MruList​(long sizeLimit,
                       long timeout)
        Parameters:
        sizeLimit - the size limit of the MruList (0 for no size limit)
        timeout - the timeout (0 for never timeout)
    • Method Detail

      • access

        public boolean access​(java.lang.Object o)
        Record that object o is being accessed. This will put a timestamp to the object
        Parameters:
        o - the object
        Returns:
        true if the object was in the list before
      • add

        public boolean add​(java.lang.Object o)
        Specified by:
        add in interface java.util.Collection
        Specified by:
        add in interface java.util.Set
        See Also:
        access(java.lang.Object)
      • addAll

        public boolean addAll​(java.util.Collection c)
        Specified by:
        addAll in interface java.util.Collection
        Specified by:
        addAll in interface java.util.Set
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection
        Specified by:
        clear in interface java.util.Set
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection
        Specified by:
        contains in interface java.util.Set
      • containsAll

        public boolean containsAll​(java.util.Collection c)
        Specified by:
        containsAll in interface java.util.Collection
        Specified by:
        containsAll in interface java.util.Set
      • expireEntries

        public void expireEntries​(long t)
        Expire the entries that was last access longer that time t Document this method.
        Parameters:
        t - the elapse time
      • getLastAccessTime

        public long getLastAccessTime​(java.lang.Object obj)
        Get the last access time object obj
        Parameters:
        obj - the object
        Returns:
        the access time, or -1 if the object is not in the cache
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection
        Specified by:
        isEmpty in interface java.util.Set
      • iterator

        public java.util.Iterator iterator()
        Specified by:
        iterator in interface java.util.Collection
        Specified by:
        iterator in interface java.lang.Iterable
        Specified by:
        iterator in interface java.util.Set
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection
        Specified by:
        remove in interface java.util.Set
      • removeAll

        public boolean removeAll​(java.util.Collection c)
        Specified by:
        removeAll in interface java.util.Collection
        Specified by:
        removeAll in interface java.util.Set
      • retainAll

        public boolean retainAll​(java.util.Collection c)
        Specified by:
        retainAll in interface java.util.Collection
        Specified by:
        retainAll in interface java.util.Set
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection
        Specified by:
        size in interface java.util.Set
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection
        Specified by:
        toArray in interface java.util.Set
      • toArray

        public java.lang.Object[] toArray​(java.lang.Object[] a)
        Specified by:
        toArray in interface java.util.Collection
        Specified by:
        toArray in interface java.util.Set
      • truncateEntries

        public void truncateEntries​(long size)
        Truncate the entries to specific size
        Parameters:
        size - the size
      • truncateEntry

        protected void truncateEntry​(java.lang.Object obj)
        Remove the object from the MruList
        Parameters:
        obj - the object
      • expireEntry

        protected void expireEntry​(java.lang.Object obj)
        Remove the entry from the MruList
        Parameters:
        obj - expire the entry