Package tenapull.sync

Class WeakInstancesTracker<K,​I>

java.lang.Object
tenapull.sync.WeakInstancesTracker<K,​I>
Type Parameters:
K - the key type
I - the instances type

public class WeakInstancesTracker<K,​I>
extends java.lang.Object
A thin wrapper for InstancesTracker, which wraps the key with weak references to the key.
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    class  WeakInstancesTracker.WeakRef
    A wrapper for WeakReference that also implement the Instances.KeyFinalizer interface, so that a key is held as a strong reference until it has been finalized
  • Constructor Summary

    Constructors 
    Constructor Description
    WeakInstancesTracker​(java.lang.Class<K> keyType, java.lang.Class<I> instanceType, Lambda1<K,​I> constructLambda)
    Instantiates a new Weak instances tracker.
    WeakInstancesTracker​(Type<K> keyType, Type<I> instanceType, Lambda1<K,​I> constructLambda)
    Instantiates a new Weak instances tracker.
  • Method Summary

    Modifier and Type Method Description
    I constructWith​(K key, Lambda1<K,​I> customLambda)
    Wraps InstancesTracker.constructWith
    I get​(K key)
    Returns the instance associated with the provided key
    java.util.List<I> get​(Lambda1<I,​java.lang.Boolean> filter)
    Wraps InstancesTracker.get
    java.util.List<I> get​(Lambda1<I,​java.lang.Boolean> filter, int limit)
    Wraps InstancesTracker.get
    java.util.Set<I> getInstances()
    Wraps InstancesTracker.getInstances
    java.util.Set<K> getKeysFor​(I instance)
    Wraps InstancesTracker.getKeysFor
    I getOrConstruct​(K key)
    Wraps InstancesTracker.getOrConstruct
    I getOrConstructWith​(K key, Lambda1<K,​I> lambda)
    Wraps InstancesTracker.getOrConstructWith
    java.util.Set<K> keySet()
    A view of the keyset for this WeakInstancesTracker.
    I put​(K key, I instance)
    Wraps InstancesTracker.put
    I remove​(K key)
    Wraps InstancesTracker.remove

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WeakInstancesTracker

      public WeakInstancesTracker​(java.lang.Class<K> keyType, java.lang.Class<I> instanceType, Lambda1<K,​I> constructLambda)
      Instantiates a new Weak instances tracker.
      Parameters:
      keyType - the key type
      instanceType - the instance type
      constructLambda - the construct lambda
    • WeakInstancesTracker

      public WeakInstancesTracker​(Type<K> keyType, Type<I> instanceType, Lambda1<K,​I> constructLambda)
      Instantiates a new Weak instances tracker.
      Parameters:
      keyType - the key type
      instanceType - the instance type
      constructLambda - the construct lambda
  • Method Details

    • get

      public I get​(K key)
      Returns the instance associated with the provided key
      Parameters:
      key - the key
      Returns:
      the instance
    • getOrConstruct

      public I getOrConstruct​(K key)
      Wraps InstancesTracker.getOrConstruct
      Parameters:
      key - the key
      Returns:
      the instance
    • getOrConstructWith

      public I getOrConstructWith​(K key, Lambda1<K,​I> lambda)
      Wraps InstancesTracker.getOrConstructWith
      Parameters:
      key - the key
      lambda - the construct lambda
      Returns:
      the instance
    • put

      public I put​(K key, I instance)
      Wraps InstancesTracker.put
      Parameters:
      key - the key
      instance - the instance to put
      Returns:
      any displaced instance
    • constructWith

      public I constructWith​(K key, Lambda1<K,​I> customLambda)
      Wraps InstancesTracker.constructWith
      Parameters:
      key - the key
      customLambda - the custom construct lambda
      Returns:
      the instance associated with the key at the time this returns
    • remove

      public I remove​(K key)
      Wraps InstancesTracker.remove
      Parameters:
      key - the key
      Returns:
      the instance that was previously associated with the key
    • getKeysFor

      public java.util.Set<K> getKeysFor​(I instance)
      Wraps InstancesTracker.getKeysFor
      Parameters:
      instance - the instance
      Returns:
      the keys that previously pointed to the provided instance
    • keySet

      public java.util.Set<K> keySet()
      A view of the keyset for this WeakInstancesTracker. Wraps InstancesTracker.keySet
      Returns:
      the set
    • get

      public java.util.List<I> get​(Lambda1<I,​java.lang.Boolean> filter)
      Wraps InstancesTracker.get
      Parameters:
      filter - the filter
      Returns:
      the list
    • get

      public java.util.List<I> get​(Lambda1<I,​java.lang.Boolean> filter, int limit)
      Wraps InstancesTracker.get
      Parameters:
      filter - the filter
      limit - the limit
      Returns:
      the list
    • getInstances

      public java.util.Set<I> getInstances()
      Wraps InstancesTracker.getInstances
      Returns:
      the instances