org.apache.tapestry5.internal.util

## Class NamedSet<T>

- java.lang.Object
- - org.apache.tapestry5.ioc.internal.util.LockSupport
  - - org.apache.tapestry5.internal.util.NamedSet<T>

- Type Parameters:
    `T` - the type of value stored

      public class NamedSet<T>
      extends LockSupport

  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
    Constructor and Description
    `NamedSet()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <T> NamedSet<T>` | `create()` Convenience method for creating a new, empty set.
    `void` | `eachValue(Worker<T> worker)` Iterates over the values, passing each in turn to the supplied worker.
    `static <T> T` | `get(NamedSet<T> set, String name)` Convenience method for getting a value from a set that may be null.
    `T` | `get(String name)` Gets the value for the provided name.
    `Set<String>` | `getNames()` Returns a set of the names of all stored values.
    `static Set<String>` | `getNames(NamedSet<?> set)` Gets the names in the set, returning an empty set if the NamedSet is null.
    `Set<T>` | `getValues()` Returns a set of all the values in the set.
    `static <T> Set<T>` | `getValues(NamedSet<T> set)` Returns the values in the set, returning an empty set if the NamedSet is null.
    `void` | `put(String name, T newValue)` Stores a new value into the set, replacing any previous value with the same name.
    `boolean` | `putIfNew(String name, T newValue)` Puts a new value, but only if it does not already exist.

    - ### Methods inherited from class org.apache.tapestry5.ioc.internal.util.LockSupport

      `acquireReadLock, downgradeWriteLockToReadLock, releaseReadLock, releaseWriteLock, takeWriteLock, upgradeReadLockToWriteLock`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NamedSet

          public NamedSet()

  - ### Method Detail

    - #### getNames

          public Set<String> getNames()

      Returns a set of the names of all stored values.

    - #### getValues

          public Set<T> getValues()

      Returns a set of all the values in the set.

    - #### get

          public T get(String name)

      Gets the value for the provided name.
      Parameters:
        `name` - used to locate the value
      Returns:
        the value, or null if not found

    - #### put

          public void put(String name,
                          T newValue)

      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

          public void eachValue(Worker<T> worker)

      Iterates over the values, passing each in turn to the supplied worker.
      Parameters:
        `worker` - performs an operation on, or using, the value

    - #### putIfNew

          public boolean putIfNew(String name,
                                  T newValue)

      Puts a new value, but only if it does not already exist.
      Parameters:
        `name` - name to store (comparisons are case insensitive) may not be blank
        `newValue` - non-null value to store
      Returns:
        true if value stored, false if name already exists

    - #### create

          public static <T> NamedSet<T> create()

      Convenience method for creating a new, empty set.

    - #### get

          public static <T> T get(NamedSet<T> set,
                                  String name)

      Convenience method for getting a value from a set that may be null.
      Type Parameters:
        `T` -
      Parameters:
        `set` - set to search, may be null
        `name` - name to lookup
      Returns:
        value from set, or null if not found, or if set is null

    - #### getNames

          public static Set<String> getNames(NamedSet<?> set)

      Gets the names in the set, returning an empty set if the NamedSet is null.

    - #### getValues

          public static <T> Set<T> getValues(NamedSet<T> set)

      Returns the values in the set, returning an empty set if the NamedSet is null.

5.6.0 - Copyright © 2003-2020 The Apache Software Foundation.