com.holonplatform.core.internal

## Class ContextResourceMap

- java.lang.Object
- - com.holonplatform.core.internal.ContextResourceMap

- All Implemented Interfaces:
    Serializable

      public final class ContextResourceMap
      extends Object
      implements Serializable

  Helper class to manage `Context` resources by key.
  Since:
    5.0.0
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ContextResourceMap(String scopeName, boolean threadSafe)` Construct a ContextResourceMap with default initial capacity
    `ContextResourceMap(String scopeName, boolean threadSafe, int initialCapacity)` Construct a ContextResourceMap

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Clears all resource bindings
    `<T> T` | `get(String key, Class<T> type)` Get a value of given `type` identified by given `key`.
    `<T> T` | `put(String key, T value)` Bind the given resource key with the specified value
    `<T> T` | `putIfAbsent(String key, T value)` Bind the given resource key with the specified value, if not already bound
    `boolean` | `remove(String key)` Removes the resource instance bound to given key

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

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

- - ### Constructor Detail

    - #### ContextResourceMap

          public ContextResourceMap(String scopeName,
                                    boolean threadSafe)

      Construct a ContextResourceMap with default initial capacity
      Parameters:
        `scopeName` - Scope name
        `threadSafe` - `true` to build a thread-safe resource map

    - #### ContextResourceMap

          public ContextResourceMap(String scopeName,
                                    boolean threadSafe,
                                    int initialCapacity)

      Construct a ContextResourceMap
      Parameters:
        `scopeName` - Scope name
        `threadSafe` - `true` to build a thread-safe resource map
        `initialCapacity` - Initial capacity

  - ### Method Detail

    - #### get

          public <T> T get(String key,
                           Class<T> type)
                    throws TypeMismatchException

      Get a value of given `type` identified by given `key`.
      Type Parameters:
        `T` - Resource type
      Parameters:
        `key` - Resource key
        `type` - Resource type
      Returns:
        Resource value, or `null` if not found
      Throws:
        `TypeMismatchException` - Expected and actual resource type mismatch

    - #### put

          public <T> T put(String key,
                           T value)

      Bind the given resource key with the specified value
      Type Parameters:
        `T` - Resource type
      Parameters:
        `key` - Resource key (not null)
        `value` - Resource instance. If `null`, the mapping will be removed
      Returns:
        Previous bound instance, if any

    - #### putIfAbsent

          public <T> T putIfAbsent(String key,
                                   T value)

      Bind the given resource key with the specified value, if not already bound
      Type Parameters:
        `T` - Resource type
      Parameters:
        `key` - Resource key (not null)
        `value` - Resource instance
      Returns:
        Previous value, or `null` if no value was bound and the new instance it's been mapped to the key

    - #### remove

          public boolean remove(String key)

      Removes the resource instance bound to given key
      Parameters:
        `key` - Resource key (not null)
      Returns:
        `true` if found and removed

    - #### clear

          public void clear()

      Clears all resource bindings

Copyright © 2019 The Holon Platform. All rights reserved.