Class ConditionalFunctions.Switch

java.lang.Object
org.apache.juneau.commons.svl.TypedFunction
org.apache.juneau.commons.svl.functions.ConditionalFunctions.Switch
All Implemented Interfaces:
VarFunction
Enclosing class:
ConditionalFunctions

public static class ConditionalFunctions.Switch extends TypedFunction
#{switch(value, case1, val1, case2, val2, ..., default)} — replacement for the legacy $SW{...}.

Compares value against each caseN glob pattern and returns the matching valN for the first match. caseN patterns may contain * (any sequence of characters) and ? (any single character) wildcards — same semantics as the legacy SwitchVar. Plain literals (no wildcards) match by full-string equality.

The last unmatched arg is the default; if the arg count is even (no trailing default), an empty string is returned for unmatched values.

Examples:
  • #{switch(${os}, *win*, Windows, *nix*, Linux, *)} — glob-routes by substring.
  • #{switch(${env}, prod, A, dev, B, default)} — exact equality, three branches.
  • Constructor Details

  • Method Details

    • name

      public String name()
      Description copied from interface: VarFunction
      The function's invocation name as it appears between #{} and the opening parenthesis in the template. Must consist of ASCII letters, digits, and underscores; must begin with a letter.
      Returns:
      The invocation name. Never null or empty.
    • invoke

      public String invoke(String[] args)