Class Config.Builder

java.lang.Object
se.sics.kompics.config.Config.Builder
All Implemented Interfaces:
Config
Enclosing interface:
Config

public static class Config.Builder
extends Object
implements Config
  • Method Details

    • readValue

      public <T> Optional<T> readValue​(String key)
      Description copied from interface: Config
      Returns an Optional of the value at key as T or Absent<T> if none.

      Does not perform checked casting!

      Specified by:
      readValue in interface Config
      Type Parameters:
      T - The requested type of the value
      Parameters:
      key - The location of the value
      Returns:
      Optional.of(T) if present or Absent<T> otherwise
    • readValue

      public <T> Optional<T> readValue​(String key, Class<T> type)
      Description copied from interface: Config
      Returns an Optional of the value at key as T or Absent<T> if none.

      Performs checked casting against type.

      Specified by:
      readValue in interface Config
      Type Parameters:
      T - The requested type of the value
      Parameters:
      key - The location of the value
      type - The type to cast the value to
      Returns:
      Optional.of(T) if present or Absent<T> otherwise
    • getValue

      public <T> T getValue​(String key, Class<T> type) throws ClassCastException
      Description copied from interface: Config
      Return the value at key as T or null if none.

      Performs checked casting against type.

      Specified by:
      getValue in interface Config
      Type Parameters:
      T - The requested type of the value
      Parameters:
      key - The location of the value
      type - The type to cast the value to
      Returns:
      The value as T if present or null otherwise
      Throws:
      ClassCastException - if the value can not be cast to type
    • getValueOrDefault

      public <T> T getValueOrDefault​(String key, T defaultValue)
      Description copied from interface: Config
      Return the value at key as T or defaultValue if none.

      Performs checked casting against the type of defaultValue.

      Specified by:
      getValueOrDefault in interface Config
      Type Parameters:
      T - The requested type of the value
      Parameters:
      key - The location of the value
      defaultValue - Returned if there is not value of the right type at key
      Returns:
      The value as T if present or defaultValue otherwise
    • modify

      public Config.Builder modify​(UUID author)
      Specified by:
      modify in interface Config
    • getValues

      public <T> List<T> getValues​(String key)
      Description copied from interface: Config
      Returns a list of values at @{code key}.

      The casts to T are unchecked in this method. Use Config.getValues(java.lang.String, java.lang.Class) if you don't want this behaviour.

      Specified by:
      getValues in interface Config
      Type Parameters:
      T - The list value type
      Parameters:
      key - The location of the values
      Returns:
      A list of values at @{code key}
    • getValues

      public <T> List<T> getValues​(String key, Class<T> type)
      Description copied from interface: Config
      Returns a list of values at @{code key}.

      Value casts are checked against type. May throw a @{link se.sics.kompics.config.ConfigValueException } if a value can't be cast.

      Specified by:
      getValues in interface Config
      Type Parameters:
      T - The list value type
      Parameters:
      key - The location of the values
      type - The type to cast the values to
      Returns:
      A list of values at @{code key}
    • setValue

      public void setValue​(String key, Object o)
      Sets the value at key to o.

      Uses ValueOptions.DEFAULT.

      Parameters:
      key - The location of the target
      o - The new value of the target
    • setValue

      public void setValue​(String key, Object o, ValueOptions opts)
      Sets the value at key to o.

      Parameters:
      key - The location of the target
      o - The new value of the target
      opts - The options associated with the new value
    • addValue

      public void addValue​(String key, Object o)
      Adds o to the collection at key.

      Starts a new collection if the value doesn't exists or the value isn't currently a collection.

      Parameters:
      key - The location of the target collection
      o - The value to add to the target collection
    • addValues

      public void addValues​(String key, Collection<Object> os)
      Adds all values in o to the collection at key.

      Starts a new collection if the value doesn't exists or the value isn't currently a collection.

      Parameters:
      key - The location of the target collection
      os - The collection of values to add to the target collection
    • finalise

    • copy

      public Config copy​(boolean newVersionLine)
      Specified by:
      copy in interface Config