Class MildElements<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>

    final class MildElements<T>
    extends java.util.AbstractCollection<T>
    NON-thread-safe Collection of elements kept alive by soft/weak References.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.List<java.lang.ref.Reference<T>> list  
      private java.lang.ref.ReferenceQueue<T> queue  
      private boolean soft  
    • Constructor Summary

      Constructors 
      Constructor Description
      MildElements​(java.util.List<java.lang.ref.Reference<T>> list, boolean soft)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T element)  
      private void compact()
      Compacts the list by replacing unreachable References with ones from the end.
      (package private) void evict​(java.lang.ref.Reference<? extends T> ref)
      Evicts a single Reference from the list; replacing it with one from the end.
      java.util.Iterator<T> iterator()  
      int size()  
      • Methods inherited from class java.util.AbstractCollection

        addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

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

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

        forEach
    • Field Detail

      • queue

        private final java.lang.ref.ReferenceQueue<T> queue
      • list

        final java.util.List<java.lang.ref.Reference<T>> list
      • soft

        private final boolean soft
    • Constructor Detail

      • MildElements

        MildElements​(java.util.List<java.lang.ref.Reference<T>> list,
                     boolean soft)
    • Method Detail

      • add

        public boolean add​(T element)
        Specified by:
        add in interface java.util.Collection<T>
        Overrides:
        add in class java.util.AbstractCollection<T>
      • size

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

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in class java.util.AbstractCollection<T>
      • compact

        private void compact()
        Compacts the list by replacing unreachable References with ones from the end.
      • evict

        void evict​(java.lang.ref.Reference<? extends T> ref)
        Evicts a single Reference from the list; replacing it with one from the end.
        Parameters:
        ref - The reference to evict