Class ElementImpl

java.lang.Object
io.nosqlbench.nb.api.config.params.ElementImpl
All Implemented Interfaces:
Element

public class ElementImpl extends Object implements Element
The source data for a param reader is intended to be a collection of something, not a single value. As such, if a single value is provided, an attempt will be made to convert it from JSON if it starts with object or array notation. If not, the value is assumed to be in the simple ParamsParser form.
  • Constructor Details

  • Method Details

    • getElementName

      public String getElementName()
      Specified by:
      getElementName in interface Element
    • get

      public <T> Optional<T> get(String name, Class<? extends T> classOfT)
      Description copied from interface: Element

      Hierarchic get of a named variable. If the name is a simple word with no dots, such as param2, then this is a simple lookup. If it is a hierarchic name such as car.cabin.dashlight1, then multiple representations of the structure could suffice to serve the request. This is enabled with name flattening.

      Name flattening - It is possible that multiple representations of backing data can suffice to hold the same logically named element. For example the three JSON objects below are all semantically equivalent.

      
       [
         {
           "car": {
               "cabin": {
                   "dashlight1": "enabled"
               }
           }
         },
         {
           "car": {
               "cabin.dashlight1": "enabled"
           }
         },
         {
           "car.cabin": {
               "dashlight1": "enabled"
           }
         },
         {
             "car.cabin.dashlight": "enabled"
         }
       ]
       

      It is necessary to honor all of these representations due to the various ways that users may provide the constructions of their configuration data. Some of them will be long-form property maps from files, others will be programmatic data structures passed into an API. This means that we must also establish a clear order of precedence between them.

      The non-collapsed form takes precedence, starting from the root level. That is, if there are multiple backing data structures for the same name, the one with a flattened name will NOT be seen if there is another at the same level which is not flattened -- even if the leaf node is fully defined under the flattened name.

      Thus the examples above are actually in precedence order. The first JSON object has the most complete name defined at the root level, so it is what will be found first. All implementations should ensure that this order is preserved.

      This method requires a type which will be given to the underlying ElementData implementation for contextual type conversion.

      Specified by:
      get in interface Element
      Type Parameters:
      T - The value type parameter
      Parameters:
      name - The simple or hierarchic variable name to resolve
      classOfT - The type of value which the resolved value is required to be assignable to
      Returns:
      An optional value of type T
    • get

      public <T> Optional<T> get(String name)
      Description copied from interface: Element
      Perform the same lookup as Element.get(String, Class), except allow for full type inferencing when possible. The value asked for will be cast to the type T at runtime, as with type erasure there is no simple way to capture the requested type without reifying it into a runtime instance in the caller. Thus, this method is provided as a syntactic convenience at best. It will almost always be better to use Element.get(String, Class)
      Specified by:
      get in interface Element
      Type Parameters:
      T - The value type parameter
      Parameters:
      name - The simple or hierarchic variable name to resolve
      Returns:
      An optional value of type T
    • getOr

      public <T> T getOr(String name, T defaultValue)
      Description copied from interface: Element
      Perform the same lookup as Element.get(String, Class), but return the default value when a value isn't found.
      Specified by:
      getOr in interface Element
      Type Parameters:
      T - The value type parameter
      Parameters:
      name - The simple or hierarchic variable name to resolve
      defaultValue - The default value to return if the named variable is not found
      Returns:
      Either the found value or the default value provided
    • getMap

      public Map<String,Object> getMap()
      Description copied from interface: Element
      Return the backing data for this element in map form.
      Specified by:
      getMap in interface Element
      Returns:
      A Map of data.
    • toString

      public String toString()
      Overrides:
      toString in class Object