Class TimedCounterList<T>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<T>
org.apache.wiki.util.TimedCounterList<T>
Type Parameters:
T - The class you wish to store here
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>

public class TimedCounterList<T>
extends java.util.AbstractList<T>
Provides a List in which all items store their addition time. This can then be used to clean the list from old items.

This class is thread-safe - all modifications are blocking, but reading is non-blocking (unless a write is ongoing).

Since:
2.8
  • Field Summary

    Fields inherited from class java.util.AbstractList

    modCount
  • Constructor Summary

    Constructors
    Constructor Description
    TimedCounterList()  
  • Method Summary

    Modifier and Type Method Description
    void add​(int index, T element)
    void cleanup​(long maxage)
    Performs a cleanup of all items older than maxage.
    int count​(T obj)
    Returns the count how many times this object is available in this list, using equals().
    T get​(int index)
    long getAddTime​(int index)
    Returns the time when this particular item was added on the list.
    T remove​(int index)
    T set​(int index, T element)
    int size()

    Methods inherited from class java.util.AbstractList

    add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList

    Methods inherited from class java.util.AbstractCollection

    addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, 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.List

    addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
  • Constructor Details

  • Method Details

    • set

      public T set​(int index, T element)
      Specified by:
      set in interface java.util.List<T>
      Overrides:
      set in class java.util.AbstractList<T>
    • get

      public T get​(int index)
      Specified by:
      get in interface java.util.List<T>
      Specified by:
      get in class java.util.AbstractList<T>
    • size

      public int size()
      Specified by:
      size in interface java.util.Collection<T>
      Specified by:
      size in interface java.util.List<T>
      Specified by:
      size in class java.util.AbstractCollection<T>
    • add

      public void add​(int index, T element)
      Specified by:
      add in interface java.util.List<T>
      Overrides:
      add in class java.util.AbstractList<T>
    • remove

      public T remove​(int index)
      Specified by:
      remove in interface java.util.List<T>
      Overrides:
      remove in class java.util.AbstractList<T>
    • count

      public int count​(T obj)
      Returns the count how many times this object is available in this list, using equals().
      Parameters:
      obj - The object to count.
      Returns:
      The count of the objects.
    • cleanup

      public void cleanup​(long maxage)
      Performs a cleanup of all items older than maxage.
      Parameters:
      maxage - The maximum age in milliseconds after an item is removed.
    • getAddTime

      public long getAddTime​(int index)
      Returns the time when this particular item was added on the list.
      Parameters:
      index - The index of the object.
      Returns:
      The addition time in milliseconds (@see System.currentTimeMillis()).