Module java.money
Package javax.money

Class AbstractContext

java.lang.Object
javax.money.AbstractContext
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AbstractQuery, AmountFormatContext, ConversionContext, CurrencyContext, MonetaryContext, ProviderContext, RoundingContext

public abstract class AbstractContext extends Object implements Serializable
Represents a general context of data targeting an item of type Q. Contexts are used to add arbitrary data that cannot be be mapped in a standard way to the money API, e.g. use case or customer specific extensions or specialities.

Superclasses of this class must be final, immutable, serializable and thread-safe.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getKeys

      public Set<String> getKeys(Class<?> type)
      Get the present keys of all entries with a given type, checking hereby if assignable.
      Parameters:
      type - The attribute type, not null.
      Returns:
      all present keys of attributes being assignable to the type, never null.
    • getType

      public Class<?> getType(String key)
      Get the current attribute type.
      Parameters:
      key - the entry's key, not null
      Returns:
      the current attribute type, or null, if no such attribute exists.
    • get

      public <T> T get(String key, Class<T> type)
      Access an attribute.
      Parameters:
      key - the attribute's key, not null
      type - the attribute's type, not null
      Returns:
      the attribute value, or null.
    • get

      public <T> T get(Class<T> type)
      Access an attribute, hereby using the class name as key.
      Parameters:
      type - the type, not null
      Returns:
      the type attribute value, or null.
    • getLong

      public Long getLong(String key)
      Access a Long attribute.
      Parameters:
      key - the attribute's key, not null.
      Returns:
      the value, or null.
    • getFloat

      public Float getFloat(String key)
      Access a Float attribute.
      Parameters:
      key - the attribute's key, not null.
      Returns:
      the value, or null.
    • getInt

      public Integer getInt(String key)
      Access an Integer attribute.
      Parameters:
      key - the attribute's key, not null.
      Returns:
      the value, or null.
    • getBoolean

      public Boolean getBoolean(String key)
      Access a Boolean attribute.
      Parameters:
      key - the attribute's key, not null.
      Returns:
      the value, or null.
    • getDouble

      public Double getDouble(String key)
      Access a Double attribute.
      Parameters:
      key - the attribute's key, not null.
      Returns:
      the value, or null.
    • getText

      public String getText(String key)
      Access a String attribute.
      Parameters:
      key - the attribute's key, not null.
      Returns:
      the value, or null.
    • getProviderName

      public String getProviderName()
      Get the provider name of this context.
      Returns:
      the provider name, or null.
    • isEmpty

      public boolean isEmpty()
      Checks if the current instance has no attributes set. This is often the cases, when used in default cases.
      Returns:
      true, if no attributes are set.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object