Module java.money
Package javax.money

Class AbstractContextBuilder<B extends AbstractContextBuilder,C extends AbstractContext>

java.lang.Object
javax.money.AbstractContextBuilder<B,C>
Direct Known Subclasses:
AbstractQueryBuilder, AmountFormatContextBuilder, ConversionContextBuilder, CurrencyContextBuilder, MonetaryContextBuilder, ProviderContextBuilder, RoundingContextBuilder

public abstract class AbstractContextBuilder<B extends AbstractContextBuilder,C extends AbstractContext> extends Object
This interface defines the common generic parts of a query. Queries are used to pass complex parameters sets to lookup monetary artifacts, e.g. MonetaryAmountFactory, MonetaryRounding, CurrencyUnit, ExchangeRateProvider and .CurrencyConversion.

Instances of this class are not thread-safe and not serializable.

  • Field Details

  • Constructor Details

    • AbstractContextBuilder

      public AbstractContextBuilder()
  • Method Details

    • importContext

      public B importContext(AbstractContext context, boolean overwriteDuplicates)
      Apply all attributes on the given context.
      Parameters:
      context - the context to be applied, not null.
      overwriteDuplicates - flag, if existing entries should be overwritten.
      Returns:
      this Builder, for chaining
    • importContext

      public B importContext(AbstractContext context)
      Apply all attributes on the given context, hereby existing entries are preserved.
      Parameters:
      context - the context to be applied, not null.
      Returns:
      this Builder, for chaining
      See Also:
    • set

      public B set(String key, int value)
      Sets an Integer attribute.
      Parameters:
      key - the key, non null.
      value - the value
      Returns:
      the Builder, for chaining.
    • set

      public B set(String key, boolean value)
      Sets an Boolean attribute.
      Parameters:
      key - the key, non null.
      value - the value
      Returns:
      the Builder, for chaining.
    • set

      public B set(String key, long value)
      Sets an Long attribute.
      Parameters:
      key - the key, non null.
      value - the value
      Returns:
      the Builder, for chaining.
    • set

      public B set(String key, float value)
      Sets an Float attribute.
      Parameters:
      key - the key, non null.
      value - the value
      Returns:
      the Builder, for chaining.
    • set

      public B set(String key, double value)
      Sets an Double attribute.
      Parameters:
      key - the key, non null.
      value - the value
      Returns:
      the Builder, for chaining.
    • set

      public B set(String key, char value)
      Sets an Character attribute.
      Parameters:
      key - the key, non null.
      value - the value
      Returns:
      the Builder, for chaining.
    • set

      public B set(Object value)
      Sets an attribute, using attribute.getClass() as attribute type and attribute.getClass().getName() as attribute name.
      Parameters:
      value - the attribute value, not null.
      Returns:
      this Builder, for chaining
    • set

      public B set(String key, Object value)
      Sets an attribute, using attribute.getClass() as attribute type.
      Parameters:
      key - the attribute's key, not null
      value - the attribute value, not null.
      Returns:
      this Builder, for chaining
    • set

      public <T> B set(Class<T> key, T value)
      Sets an attribute, using attribute.getClass() as attribute type.
      Parameters:
      key - the attribute's key, not null
      value - the attribute value, not null.
      Returns:
      this Builder, for chaining
    • setProviderName

      public B setProviderName(String provider)
      Sets the provider.
      Parameters:
      provider - the provider, not null.
      Returns:
      the Builder for chaining
    • removeAttributes

      public B removeAttributes(String... keys)
      Removes an entry of a certain keys. This can be useful, when a context is initialized with another existing context, but only subset of the entries should be visible. For example removeAttributes ("a", "b", "c") removes all attributes named 'a','b' and 'c'.
      Parameters:
      keys - the keys
      Returns:
      this Builder, for chaining
    • build

      public abstract C build()
      Creates a new AbstractContext with the data from this Builder instance.
      Returns:
      a new AbstractContext. never null.
    • toString

      public String toString()
      Overrides:
      toString in class Object