Class VariableManager

java.lang.Object
org.incenp.obofoundry.sssom.transform.VariableManager

public class VariableManager extends Object
A helper class to track variables that can have a different value depending on the mapping that is currently being processed.

Example:

 VariableManager vm = new VariableManager();
 vm.addVariable("myvar", "my default value");
 vm.addVariable("myvar", "my value", (mapping) -> mapping.getObjectId().startsWith("ABC");
 ...
 Mapping m = ...
 String value = vm.expandVariable("myvar", m);
 ...
 IMappingTransformer<String> myVarTransformer = vm.getTransformer("myvar");
 Mapping m = ...
 String value = myVarTransformer.transform(m);
 
  • Constructor Details

    • VariableManager

      public VariableManager()
  • Method Details

    • addVariable

      public void addVariable(String name, String value)
      Defines a new variable to track.
      Parameters:
      name - The name of the new variable.
      value - The variable's default value.
    • addVariable

      public void addVariable(String name, String value, IMappingFilter filter)
      Defines a new variable to track for certain mappings.
      Parameters:
      name - The name of the variable; if no variable with that name has been declared yet, it is created as needed,
      value - The value of the variable.
      filter - The filter determining for which mappings the variable has the specified value.
    • hasVariable

      public boolean hasVariable(String name)
      Checks if a name is the name of a known variable.
      Parameters:
      name - The name to check
      Returns:
      true if a variable with the given name is known to this manager, otherwise false.
    • expandVariable

      public String expandVariable(String name, Mapping mapping)
      Gets the value of a variable for a given mapping.
      Parameters:
      name - The name of the variable to lookup.
      mapping - The mapping for which to get the variable's value.
      Returns:
      The value of the variable, according to the filter/values registered for that variable.
    • getTransformer

      public IMappingTransformer<Object> getTransformer(String name)
      Gets a mapping transformer that will return the value of the variable for the mapping it is applied to.
      Parameters:
      name - The variable to look up.
      Returns:
      A mapping transformer that, when applied to a mapping, will yield the value the variable should have for this mapping.