Package cdc.args

Class FormalArgs

java.lang.Object
cdc.args.FormalArgs

public final class FormalArgs extends Object
Tuple of formal arguments.
Author:
Damien Carbonne
  • Field Details

    • NO_FARGS

      public static final FormalArgs NO_FARGS
      Empty tuple of formal arguments.
    • DEFAULT_FARGS_LIST

      public static final List<FormalArgs> DEFAULT_FARGS_LIST
  • Constructor Details

    • FormalArgs

      public FormalArgs()
      Creates an empty formal argument tuple.
    • FormalArgs

      public FormalArgs(FormalArg<?>... args)
      Creates a tuple of formal arguments from an array.
      Parameters:
      args - The formal arguments.
      Throws:
      IllegalArgumentException - When args of of of its elements is null, or when there are duplicate names.
    • FormalArgs

      public FormalArgs(List<FormalArg<?>> args)
      Creates a tuple of formal arguments from a list.
      Parameters:
      args - The formal arguments.
      Throws:
      IllegalArgumentException - When args of of of its elements is null, or when there are duplicate names.
    • FormalArgs

      public FormalArgs(FormalArgs fargs1, FormalArgs fargs2)
      Creates a tuple of formal arguments by merging two tuples.
      Parameters:
      fargs1 - The first tuple of formal arguments.
      fargs2 - The second tuple of formal arguments.
      Throws:
      IllegalArgumentException - When there are duplicate names.
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns:
      true if this list is empty.
    • getArgs

      public FormalArg<?>[] getArgs()
      Returns:
      The formal arguments as an array.
    • hasArgs

      public boolean hasArgs(Necessity necessity)
      Returns true if this tuple of formal arguments contains at least one argument whose necessity matches a necessity.
      Parameters:
      necessity - The necessity.
      Returns:
      true if this list contains at least one argument whose necessity matches necessity.
    • getArgs

      public FormalArgs getArgs(Necessity necessity)
      Returns the arguments that match a necessity.
      Parameters:
      necessity - The necessity.
      Returns:
      The arguments that match necessity.
    • size

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

      public FormalArg<?> getArg(int index)
      Returns the argument that has a position.
      Parameters:
      index - The index
      Returns:
      The argument at index.
    • getArgIndex

      public int getArgIndex(String name)
      Returns the index of an argument.
      Parameters:
      name - The argument name.
      Returns:
      The index of the argument whose name is name or -1.
    • getArg

      public FormalArg<?> getArg(String name)
      Returns the argument that has a name.
      Parameters:
      name - The argument name.
      Returns:
      The argument whose name is name or null.
    • hasArg

      public boolean hasArg(String name)
      Returns true when this tuple contains an argument that has a given name.
      Parameters:
      name - The name.
      Returns:
      true when this tuple contains an argument named name.
    • hasArgMatchingName

      public boolean hasArgMatchingName(FormalArg<?> farg)
    • accepts

      public boolean accepts(FormalArgs other)
      Returns true when this formal tuple can accept another formal tuple.

      The result is positive when:

      • all mandatory args of this tuple are present and compliant in other (they may be optional or mandatory).
      • all optional args of this tuple are either absent from other or are present in other and compliant.
      Parameters:
      other - The other formal tuple.
      Returns:
      true when this formal tuple can accept other formal tuple.
    • merge

      public static FormalArgs merge(FormalArgs fargs1, FormalArgs fargs2)
      Merges 2 tuples of formal arguments.
      • If an argument name is in only one tuple, the argument it is added as defined.
      • If an argument name is in both tuples, arguments are merged, choosing MANDATORY if necessities are different, and the most specialized type.
        This may raise an exception if merge is impossible (no inheritance hierarchy between types).
      Parameters:
      fargs1 - The first tuple.
      fargs2 - the second tuple.
      Returns:
      The merge of left and right.
      Throws:
      IllegalArgumentException - if there is a type conflict when merging 2 arguments.
    • merge

      public static FormalArgs merge(FormalArgs... all)
    • hashCode

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

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

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

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