public class

WeakInterner

extends Object
java.lang.Object
   ↳ com.atlassian.jira.util.cache.WeakInterner<T>

Class Overview

Similar to a Guava WeakInterner, but significantly lighter weight.

The Guava implementation of a weak interner has considerable overhead because it is implemented in terms of the CustomConcurrentHashMap grab bag of functionality with all its accompanying statistical tracking, eviction policy, and so on. This implementation is based directly on the lighter ConcurrentHashMap implementation that comes with the JDK.

Note: This assumes that your interned objects are sane for interning purposes, meaning that they are immutable objects with stable hash codes that are consistent with equals and have a reasonably efficient implementation for equals. Violate these assumptions at your own risk.

Summary

Public Constructors
WeakInterner()
WeakInterner(int initialCapacity)
WeakInterner(int initialCapacity, float loadFactor)
WeakInterner(int initialCapacity, float loadFactor, int concurrencyLevel)
Public Methods
void cleanUp()
Requests an explicit clean-up pass.
@Nonnull T intern(T value)
Weakly interns the specified non-null value.
@Nullable T internOrNull(T value)
Weakly interns the specified value, with null values tolerated.
static <T> WeakInterner<T> newWeakInterner()
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public WeakInterner ()

public WeakInterner (int initialCapacity)

public WeakInterner (int initialCapacity, float loadFactor)

public WeakInterner (int initialCapacity, float loadFactor, int concurrencyLevel)

Public Methods

public void cleanUp ()

Requests an explicit clean-up pass.

The clean-up is invoked implicitly on every call to intern(Object) or internOrNull(Object) (provided the argument is not in fact null), so it should not normally be necessary to call this method explicitly.

@Nonnull public T intern (T value)

Weakly interns the specified non-null value.

Implicitly calls cleanUp().

Parameters
value the value to intern; must not be null
Returns
  • either another object that was previously interned and is semantically equal to value, or value itself if there is no previously interned instance available.
Throws
IllegalArgumentException if value is null

@Nullable public T internOrNull (T value)

Weakly interns the specified value, with null values tolerated.

Implicitly calls cleanUp() unless value is null.

Parameters
value the value to intern; may be null
Returns
  • either value or another instance of that object which was previously interned and is semantically equal to value

public static WeakInterner<T> newWeakInterner ()