Class Refs<T extends RefCounted<T>>

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

    public final class Refs<T extends RefCounted<T>>
    extends java.util.AbstractCollection<T>
    implements java.lang.AutoCloseable
    A collection of managed Ref references to RefCounted objects, and the objects they are referencing. Care MUST be taken when using this collection, as if a permanent reference to it leaks we will not be alerted to a lack of reference release. All of the java.util.Collection operations that modify the collection are unsupported.
    • Constructor Summary

      Constructors 
      Constructor Description
      Refs()  
      Refs​(java.util.Map<T,​Ref<T>> references)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Refs<T> addAll​(Refs<T> add)
      Merge two sets of references, ensuring only one reference is retained between the two sets
      void close()
      Ref<T> get​(T referenced)  
      java.util.Iterator<T> iterator()  
      static <T extends RefCounted<T>>
      Refs<T>
      ref​(java.lang.Iterable<? extends T> reference)  
      void relaseAllExcept​(java.util.Collection<T> keep)  
      void release()
      Release ALL of the references held by this Refs collection
      static void release​(java.lang.Iterable<? extends Ref<?>> refs)  
      static java.lang.Throwable release​(java.lang.Iterable<? extends Ref<?>> refs, java.lang.Throwable accumulate)  
      void release​(java.util.Collection<T> release)
      Release a retained Ref to all of the provided objects; if any is not held, an exception will be thrown
      void release​(T referenced)  
      boolean releaseIfHolds​(T referenced)
      Release the retained Ref to the provided object, if held, return false otherwise
      static <T extends SelfRefCounted<T>>
      java.lang.Iterable<Ref<T>>
      selfRefs​(java.lang.Iterable<T> refs)  
      int size()  
      static <T extends RefCounted<T>>
      Refs<T>
      tryRef​(java.lang.Iterable<? extends T> reference)
      Acquire a reference to all of the provided objects, or none
      boolean tryRef​(T t)
      Attempt to take a reference to the provided object; if it has already been released, null will be returned
      • Methods inherited from class java.util.AbstractCollection

        add, 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
    • Constructor Detail

      • Refs

        public Refs()
      • Refs

        public Refs​(java.util.Map<T,​Ref<T>> references)
    • Method Detail

      • release

        public void release()
        Release ALL of the references held by this Refs collection
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
      • get

        public Ref<T> get​(T referenced)
        Parameters:
        referenced - the object we have a Ref to
        Returns:
        the Ref to said object
      • release

        public void release​(T referenced)
        Parameters:
        referenced - the object we have a Ref to
      • releaseIfHolds

        public boolean releaseIfHolds​(T referenced)
        Release the retained Ref to the provided object, if held, return false otherwise
        Parameters:
        referenced - the object we retain a Ref to
        Returns:
        return true if we held a reference to the object, and false otherwise
      • relaseAllExcept

        public void relaseAllExcept​(java.util.Collection<T> keep)
      • release

        public void release​(java.util.Collection<T> release)
        Release a retained Ref to all of the provided objects; if any is not held, an exception will be thrown
        Parameters:
        release -
      • tryRef

        public boolean tryRef​(T t)
        Attempt to take a reference to the provided object; if it has already been released, null will be returned
        Parameters:
        t - object to acquire a reference to
        Returns:
        true iff success
      • iterator

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

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

        public Refs<T> addAll​(Refs<T> add)
        Merge two sets of references, ensuring only one reference is retained between the two sets
      • tryRef

        public static <T extends RefCounted<T>> Refs<T> tryRef​(java.lang.Iterable<? extends T> reference)
        Acquire a reference to all of the provided objects, or none
      • ref

        public static <T extends RefCounted<T>> Refs<T> ref​(java.lang.Iterable<? extends T> reference)
      • release

        public static void release​(java.lang.Iterable<? extends Ref<?>> refs)
      • release

        public static java.lang.Throwable release​(java.lang.Iterable<? extends Ref<?>> refs,
                                                  java.lang.Throwable accumulate)
      • selfRefs

        public static <T extends SelfRefCounted<T>> java.lang.Iterable<Ref<T>> selfRefs​(java.lang.Iterable<T> refs)