Class TypeAndTarget<E extends Enum<E>,T>

java.lang.Object
io.nosqlbench.engine.api.templating.TypeAndTarget<E,T>
Type Parameters:
E -

public class TypeAndTarget<E extends Enum<E>,T> extends Object

A convenient pattern for users to specify a command is that of type and target. This emphasizes that users often need to specify what kind of action to take, and what subject to take the action on. This concept pervades programming, exmplified by a simple

function(object)  call

To facilitate this pattern in op templates with the help of type safety, this helper type allows for the scanning of a map for a matching enum field. If any map key matches one of the possible enum values, case-insensitively, and with only a single match, then the matching enum value is taken as a specific type of action, and the matching value in the map is taken as the intended target.

Further, the target may be indirect, such as a binding, rather than a specific literal or structured value. In such cases, only a lambda-style function may be available. The provided targetFunction is a LongFunction of Object which can be called to return an associated target value once the cycle value is known.

For example, with an enum like

 public enum LandMovers {
     BullDozer,
     DumpTruck
 }
 
and a parsed op like

 (json)
 {
  "op": {
   "bulldozer": "{dozerid}"
   }
 }

 (yaml)
 op:
  bulldozer: "{dozerid}
 
the result will be returned with the following:

  enumId: (Enum field) BullDozer
  field: (String) bulldozer
  targetFunction: (long l) -> template function for {dozerid}
 
  • Field Details

    • enumId

      public final E extends Enum<E> enumId
    • field

      public final String field
    • targetFunction

      public final LongFunction<T> targetFunction
  • Constructor Details

    • TypeAndTarget

      public TypeAndTarget(E enumId, String matchingOpFieldName, LongFunction<T> value)