Class NamedSet<T>
java.lang.Object
org.apache.tapestry5.commons.internal.util.LockSupport
org.apache.tapestry5.internal.util.NamedSet<T>
- Type Parameters:
T
- the type of value stored
Simple, thread-safe associative array that relates a name to a value. Names are case-insensitive.
This is optimized to use less memory (than a
CaseInsensitiveMap
(it uses a singly-liked list),
though the cost of a lookup is more expensive. However, this is a good match against many of the structures inside
a page instance, where most lookups occur only during page constructions, and the number of values is often small.
Each NameSet has its own ReadWriteLock
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> NamedSet<T>
create()
Convenience method for creating a new, empty set.void
Iterates over the values, passing each in turn to the supplied worker.Gets the value for the provided name.static <T> T
Convenience method for getting a value from a set that may be null.getNames()
Returns a set of the names of all stored values.Gets the names in the set, returning an empty set if the NamedSet is null.Returns a set of all the values in the set.static <T> Set<T>
Returns the values in the set, returning an empty set if the NamedSet is null.void
Stores a new value into the set, replacing any previous value with the same name.boolean
Puts a new value, but only if it does not already exist.Methods inherited from class org.apache.tapestry5.commons.internal.util.LockSupport
acquireReadLock, downgradeWriteLockToReadLock, releaseReadLock, releaseWriteLock, takeWriteLock, upgradeReadLockToWriteLock
-
Constructor Details
-
NamedSet
public NamedSet()
-
-
Method Details
-
getNames
Returns a set of the names of all stored values. -
getValues
Returns a set of all the values in the set. -
get
Gets the value for the provided name.- Parameters:
name
- used to locate the value- Returns:
- the value, or null if not found
-
put
Stores a new value into the set, replacing any previous value with the same name. Name comparisons are case insensitive.- Parameters:
name
- to store the value. May not be blank.newValue
- non-null value to store
-
eachValue
Iterates over the values, passing each in turn to the supplied worker.- Parameters:
worker
- performs an operation on, or using, the value
-
putIfNew
Puts a new value, but only if it does not already exist.- Parameters:
name
- name to store (comparisons are case insensitive) may not be blanknewValue
- non-null value to store- Returns:
- true if value stored, false if name already exists
-
create
Convenience method for creating a new, empty set. -
get
Convenience method for getting a value from a set that may be null.- Type Parameters:
T
-- Parameters:
set
- set to search, may be nullname
- name to lookup- Returns:
- value from set, or null if not found, or if set is null
-
getNames
Gets the names in the set, returning an empty set if the NamedSet is null. -
getValues
Returns the values in the set, returning an empty set if the NamedSet is null.
-