Package org.apache.tapestry5.commons.util

## Class StrategyRegistry<A>

- java.lang.Object
- - org.apache.tapestry5.commons.util.StrategyRegistry<A>

- Type Parameters:
    `A` - the type of the strategy adapter

      public final class StrategyRegistry<A>
      extends java.lang.Object

  A key component in implementing the "Gang of Four" Strategy pattern. A StrategyRegistry will match up a given input type with a registered strategy for that type.

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `clearCache()` |
    `A` | `get​(java.lang.Class type)` | Searches for an adapter corresponding to the given input type.
    `java.lang.Class<A>` | `getAdapterType()` |
    `A` | `getByInstance​(java.lang.Object value)` | Gets an adapter for an object.
    `java.util.Collection<java.lang.Class>` | `getTypes()` | Returns the registered types for which adapters are available.
    `static <A> StrategyRegistry<A>` | `newInstance​(java.lang.Class<A> adapterType, java.util.Map<java.lang.Class,​A> registrations)` | Creates a strategy registry for the given adapter type.
    `static <A> StrategyRegistry<A>` | `newInstance​(java.lang.Class<A> adapterType, java.util.Map<java.lang.Class,​A> registrations, boolean allowNonMatch)` | Creates a strategy registry for the given adapter type.
    `java.lang.String` | `toString()` |

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

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

- - ### Method Detail

    - #### newInstance

          public static <A> StrategyRegistry<A> newInstance​(java.lang.Class<A> adapterType,
                                                            java.util.Map<java.lang.Class,​A> registrations)

      Creates a strategy registry for the given adapter type. The registry will be configured to require matches.
      Parameters:
        `adapterType` - the type of adapter retrieved from the registry
        `registrations` - map of registrations (the contents of the map are copied)

    - #### newInstance

          public static <A> StrategyRegistry<A> newInstance​(java.lang.Class<A> adapterType,
                                                            java.util.Map<java.lang.Class,​A> registrations,
                                                            boolean allowNonMatch)

      Creates a strategy registry for the given adapter type.
      Parameters:
        `adapterType` - the type of adapter retrieved from the registry
        `registrations` - map of registrations (the contents of the map are copied)
        `allowNonMatch` - if true, then the registry supports non-matches when retrieving an adapter

    - #### clearCache

          public void clearCache()

    - #### getAdapterType

          public java.lang.Class<A> getAdapterType()

    - #### getByInstance

          public A getByInstance​(java.lang.Object value)

      Gets an adapter for an object. Searches based on the value's class, unless the value is null, in which case, a search on class void is used.
      Parameters:
        `value` - for which an adapter is needed
      Returns:
        the adapter for the value or null if not found (and allowNonMatch is true)
      Throws:
        `java.lang.IllegalArgumentException` - if no matching adapter may be found and allowNonMatch is false

    - #### get

          public A get​(java.lang.Class type)

      Searches for an adapter corresponding to the given input type.
      Parameters:
        `type` - the type to search
      Returns:
        the adapter for the type or null if not found (and allowNonMatch is true)
      Throws:
        `java.lang.IllegalArgumentException` - if no matching adapter may be found and allowNonMatch is false

    - #### getTypes

          public java.util.Collection<java.lang.Class> getTypes()

      Returns the registered types for which adapters are available.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`