Package cdc.args

Class Args

java.lang.Object
cdc.args.Args

public final class Args extends Object
'Set' of effective arguments.

This class is immutable. Args.Builder can be used to create instances of Args.

Compliance rules

There is compliance between Args args and FormalArgs fargs when:

  • In STRICT mode: each arg of args corresponds to one farg of fargs with a compliant value.
  • In LOOSE mode: each arg of args 1) is absent of fargs, 2) or corresponds to one farg of fargs with a compliant value.
  • In both nodes, each MANDATORY farg has a compliant value defined in args.
For example, with fargs = [arg0: MANDATORY String, arg1: OPTIONAL Object], compliance will be:
  • true with: args = [arg0: "Hello"] in any mode.
  • true with: args = [arg0: "Hello", arg1: null] in any mode.
  • true with: args = [arg0: "Hello", arg1: "World"] in any mode.
  • true with: args = [arg0: "Hello", arg2: null] in LOOSE mode.
  • false with: args = [arg0: "Hello", arg2: null] in STRICT mode.
  • false with: args = [arg0: null] in any mode.
Author:
Damien Carbonne
  • Field Details

    • NO_ARGS

      public static final Args NO_ARGS
      Empty arguments.
  • Constructor Details

    • Args

      public Args()
      Creates an empty set.
    • Args

      public Args(Arg... args)
      Creates a set.
      Parameters:
      args - The arguments.
    • Args

      public Args(List<Arg> args)
      Creates a set.
      Parameters:
      args - The arguments.
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns:
      true when there are no arguments.
    • isEmptyOrAllValuesAreNull

      public boolean isEmptyOrAllValuesAreNull()
      Returns:
      true if this tuple is empty or all its values are null.
    • size

      public int size()
      Returns:
      The number of arguments.
    • getNames

      public List<String> getNames()
      Returns:
      A list of argument names, in the order they were declared.
    • getSortedNames

      public List<String> getSortedNames()
    • getArg

      public Arg getArg(String name)
      Returns the argument that has a given name or null.
      Parameters:
      name - The name.
      Returns:
      The argument named name or null
    • getArgs

      public List<Arg> getArgs()
      Returns:
      A list of arguments, in the order they were declared.
    • hasArg

      public boolean hasArg(String name)
      Returns true if this Args contains an argument with a particular name.
      Parameters:
      name - The name.
      Returns:
      true if this args contains an argument named name.
    • hasArgWithMatchingName

      public boolean hasArgWithMatchingName(FormalArg<?> farg)
      Returns true if this tuple contains an argument whose name matches the name of a formal argument.
      Parameters:
      farg - The formal argument.
      Returns:
      true if this tuple contains an argument whose name matches the name of farg.
    • set

      public Args set(Args other)
      Creates a new set from this one and another one.

      Values in other take precedence on values of this set.

      Parameters:
      other - The other arguments.
      Returns:
      A new set from this one and other.
    • getValue

      public Object getValue(String name, Object def)
      Returns the value (as Object) associated to a name or a default value.
      Parameters:
      name - Name of the retrieved value.
      def - The default value.
      Returns:
      The value (as Object) associated to name or def.
    • getValue

      public Object getValue(String name)
      Returns the value (as Object) associated to a name or null.

      If no value is associated to name, null is returned.

      Parameters:
      name - Name of the retrieved value.
      Returns:
      The value (as Object) associated to name or null.
      Throws:
      IllegalArgumentException - When name is null.
    • getValue

      public <T> T getValue(FormalArg<T> farg, T def)
      Returns the value associated to a formal argument or a default value.
      Type Parameters:
      T - The formal argument type.
      Parameters:
      farg - The formal argument.
      def - The default value.
      Returns:
      The value corresponding to farg or null.
      Throws:
      IllegalArgumentException - When farg is null.
      ClassCastException - When the associated value can not be cast to expected class.
    • getValue

      public <T> T getValue(FormalArg<T> farg)
      Returns the value associated to a formal argument or null.
      Type Parameters:
      T - The formal argument type.
      Parameters:
      farg - The formal argument.
      Returns:
      The value associated to farg.
      Throws:
      IllegalArgumentException - When farg is null.
      ClassCastException - When the associated value can not be cast to expected class.
    • getValue

      public <T> T getValue(String name, Class<T> cls, T def)
      Returns the value associated to a name, as a type, or a default value.

      If the value associated to name can not be converted to type, an exception is raised.

      Type Parameters:
      T - Return type.
      Parameters:
      name - Name of the retrieved value.
      cls - Class of the retrieved value.
      def - The default value to return if no value is associated to name.
      Returns:
      The value associated to name or def.
      Throws:
      IllegalArgumentException - When name of cls is null.
      ClassCastException - When the associated value can not be cast to cls.
    • getValue

      public <T> T getValue(String name, Class<T> cls)
      Returns the value associated to a name, as a type, or null.

      If no value is associated to name, null is returned.
      If the value associated to name can not be converted to type, an exception is raised.

      Type Parameters:
      T - Return type.
      Parameters:
      name - Name of the retrieved value.
      cls - Class of the retrieved value.
      Returns:
      The value associated to name or null.
      Throws:
      IllegalArgumentException - When name of cls is null.
      ClassCastException - When the associated value can not be cast to cls.
    • isCompliantWith

      public boolean isCompliantWith(FormalArgs fargs, Strictness strictness)
      Returns true when this Args is compliant with formal arguments and strictness.
      Parameters:
      fargs - The formal arguments.
      strictness - The compliance strictness.
      Returns:
      true if this Args is compliant with fargs and strictness.
    • isLooselyCompliantWith

      public boolean isLooselyCompliantWith(FormalArgs fargs)
      Returns true when this Args is loosely compliant with formal arguments.
      Parameters:
      fargs - The formal arguments.
      Returns:
      true if this Args is loosely compliant with fargs.
    • isStrictlyCompliantWith

      public boolean isStrictlyCompliantWith(FormalArgs fargs)
      Returns true when this Args is strictly compliant with formal arguments.
      Parameters:
      fargs - The formal arguments.
      Returns:
      true if this Args is strictly compliant with fargs.
    • isConflictingWith

      public boolean isConflictingWith(FormalArgs fargs)
    • isCompliantWithOneOf

      public boolean isCompliantWithOneOf(Strictness strictness, Collection<FormalArgs> collection)
      Returns true if this arguments is compliant with at least one formal argument tuple.
      Parameters:
      strictness - The compliance strictness.
      collection - The collection of formal arguments tuples.
      Returns:
      true if this arguments is compliant with at least one element of collection.
    • isLooselyCompliantWithOneOf

      public boolean isLooselyCompliantWithOneOf(Collection<FormalArgs> collection)
      Returns true if this arguments is loosely compliant with at least one formal argument tuple.
      Parameters:
      collection - The collection of formal arguments tuples.
      Returns:
      true if this arguments is loosely compliant with at least one element of collection.
    • isStrictlyCompliantWithOneOf

      public boolean isStrictlyCompliantWithOneOf(Collection<FormalArgs> collection)
      Returns true if this arguments is strictly compliant with at least one formal argument tuple.
      Parameters:
      collection - The collection of formal arguments tuples.
      Returns:
      true if this arguments is strictly compliant with at least one element of collection.
    • isCompliantWithOneOf

      public boolean isCompliantWithOneOf(Strictness strictness, FormalArgs... array)
      Returns true if this arguments is compliant with at least one formal argument tuple.
      Parameters:
      strictness - The compliance strictness.
      array - The array of formal arguments tuples.
      Returns:
      true if this arguments is compliant with at least one element of array.
    • isLooselyCompliantWithOneOf

      public boolean isLooselyCompliantWithOneOf(FormalArgs... array)
      Returns true if this arguments is loosely compliant with at least one formal argument tuple.
      Parameters:
      array - The array of formal arguments tuples.
      Returns:
      true if this arguments is loosely compliant with at least one element of array.
    • isStrictlyCompliantWithOneOf

      public boolean isStrictlyCompliantWithOneOf(FormalArgs... array)
      Returns true if this arguments is strictly compliant with at least one formal argument tuple.
      Parameters:
      array - The array of formal arguments tuples.
      Returns:
      true if this arguments is strictly compliant with at least one element of array.
    • checkComplianceWithOneOf

      public void checkComplianceWithOneOf(Strictness strictness, Collection<FormalArgs> collection)
      Checks compliance of this arguments with one of a collection of formal arguments.
      Parameters:
      strictness - The strictness.
      collection - The collection of formal arguments.
      Throws:
      InvalidArgsException - If there is no compliance.
    • checkLooseComplianceWithOneOf

      public void checkLooseComplianceWithOneOf(Collection<FormalArgs> collection)
      Checks loose compliance of this arguments with one of a collection of formal arguments.
      Parameters:
      collection - The collection of formal arguments.
      Throws:
      InvalidArgsException - If there is no compliance.
    • checkStrictComplianceWithOneOf

      public void checkStrictComplianceWithOneOf(Collection<FormalArgs> collection)
      Checks strict compliance of this arguments with one of a collection of formal arguments.
      Parameters:
      collection - The collection of formal arguments.
      Throws:
      InvalidArgsException - If there is no compliance.
    • checkComplianceWithOneOf

      public void checkComplianceWithOneOf(Strictness strictness, FormalArgs... array)
      Checks compliance of the arguments with formal arguments tuples.
      Parameters:
      strictness - The compliance strictness.
      array - The array of formal arguments tuples.
      Throws:
      InvalidArgsException - When there is no compliance.
    • checkLooseComplianceWithOneOf

      public void checkLooseComplianceWithOneOf(FormalArgs... array)
      Checks loose compliance of the arguments with formal arguments tuples.
      Parameters:
      array - The array of formal arguments tuples.
      Throws:
      IllegalArgumentException - When there is no compliance.
    • checkStrictComplianceWithOneOf

      public void checkStrictComplianceWithOneOf(FormalArgs... array)
      Checks strict compliance of the arguments with formal arguments tuples.
      Parameters:
      array - The array of formal arguments tuples.
      Throws:
      IllegalArgumentException - When there is no compliance.
    • areCompliant

      public static boolean areCompliant(Args args, FormalArgs fargs, Strictness strictness)
      Returns true when an arguments is compliant with a formal arguments.
      Parameters:
      args - The arguments.
      fargs - The formal arguments.
      strictness - The strictness.
      Returns:
      true when args is compliant with fargs.
    • areLooselyCompliant

      public static boolean areLooselyCompliant(Args args, FormalArgs fargs)
      Returns true when an arguments is loosely compliant with a formal arguments.
      Parameters:
      args - The arguments.
      fargs - The formal arguments.
      Returns:
      true when args is loosely compliant with fargs.
    • areStrictlyCompliant

      public static boolean areStrictlyCompliant(Args args, FormalArgs fargs)
      Returns true when an arguments is strictly compliant with a formal arguments.
      Parameters:
      args - The arguments.
      fargs - The formal arguments.
      Returns:
      true when args is strictly compliant with fargs.
    • areCompliant

      public static boolean areCompliant(Args args, Strictness strictness, Collection<FormalArgs> collection)
    • areLooselyCompliant

      public static boolean areLooselyCompliant(Args args, Collection<FormalArgs> collection)
    • areStrictlyCompliant

      public static boolean areStrictlyCompliant(Args args, Collection<FormalArgs> collection)
    • areCompliant

      public static boolean areCompliant(Args args, Strictness strictness, FormalArgs... array)
    • areLooselyCompliant

      public static boolean areLooselyCompliant(Args args, FormalArgs... array)
    • areStrictlyCompliant

      public static boolean areStrictlyCompliant(Args args, FormalArgs... array)
    • checkCompliance

      public static void checkCompliance(Args args, Strictness strictness, Collection<FormalArgs> collection)
    • checkLooseCompliance

      public static void checkLooseCompliance(Args args, Collection<FormalArgs> collection)
    • checkStrictCompliance

      public static void checkStrictCompliance(Args args, Collection<FormalArgs> collection)
    • checkCompliance

      public static void checkCompliance(Args args, Strictness strictness, FormalArgs... array)
    • checkLooseCompliance

      public static void checkLooseCompliance(Args args, FormalArgs... array)
    • checkStrictCompliance

      public static void checkStrictCompliance(Args args, FormalArgs... array)
    • reduceNecessity

      public static FormalArgs reduceNecessity(FormalArgs fargs, Args args)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static Args.Builder builder()
      Returns:
      A new Builder instance.
    • builder

      public static Args.Builder builder(FormalArgs fargs)