Interface Environment

All Known Implementing Classes:
AbstractEnvironment, DefaultEnvironment

public interface Environment
Access to the platform user local environment. Properties stored in the environment should be persisted across sessions, using an appropriate platform storage mechanism such as cookies.
Author:
Garret Wilson
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the available environment properties as a read-only map of property names and values.
    <T> T
    Retrieves an environment property by its name.
    <T> T
    getProperty(String name, T defaultValue)
    Retrieves an environment property by its name, returning a default value if no value is available.
    <T> T
    Retrieves a required environment property by its name, throwing an exception if the value is missing.
    boolean
    Determines if an environment property exists.
    void
    Removes the property specified by the given name.
    void
    Sets multiple environment properties.
    void
    setProperty(String name, Object value)
    Sets an environment property.
  • Method Details

    • hasProperty

      boolean hasProperty(String name)
      Determines if an environment property exists.
      Parameters:
      name - The name of the property to check.
      Returns:
      true if the environment has the given property.
    • getProperty

      <T> T getProperty(String name)
      Retrieves an environment property by its name. A ClassCastException will eventually be thrown if the given value is not the generic type requested.
      Type Parameters:
      T - The type of property value expected.
      Parameters:
      name - The name of the property to retrieve.
      Returns:
      The property value, or null if there is no such property.
    • getProperty

      <T> T getProperty(String name, T defaultValue)
      Retrieves an environment property by its name, returning a default value if no value is available. A ClassCastException will eventually be thrown if the given value is not the generic type requested.
      Type Parameters:
      T - The type of property value expected.
      Parameters:
      name - The name of the property to retrieve.
      defaultValue - The value to return if no such property is available, or null if there is no default value.
      Returns:
      The property value, or the provided default value if there is no such property.
    • getRequiredProperty

      <T> T getRequiredProperty(String name)
      Retrieves a required environment property by its name, throwing an exception if the value is missing. A ClassCastException will eventually be thrown if the given value is not the generic type requested.
      Type Parameters:
      T - The type of property value expected.
      Parameters:
      name - The name of the property to retrieve.
      Returns:
      The property value.
      Throws:
      IllegalStateException - if no such property exists.
    • setProperty

      void setProperty(String name, Object value)
      Sets an environment property.
      Parameters:
      name - The name of the property.
      value - The value to associate with the name.
      Throws:
      IllegalArgumentException - if the given property cannot be set to the given value or cannot be changed.
    • setProperties

      void setProperties(Map<String,Object> map)
      Sets multiple environment properties.
      Parameters:
      map - The map of property names and values to set.
      Throws:
      IllegalArgumentException - if the given property cannot be set to the given value or cannot be changed.
    • removeProperty

      void removeProperty(String name)
      Removes the property specified by the given name.
      Parameters:
      name - The name of the property to remove.
      Throws:
      IllegalArgumentException - if the given property cannot be removed.
    • getProperties

      Map<String,Object> getProperties()
      Returns the available environment properties as a read-only map of property names and values.
      Returns:
      The available environment properties.