Package cdc.args
Class FormalArgs
java.lang.Object
cdc.args.FormalArgs
Tuple of formal arguments.
- Author:
- Damien Carbonne
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder of formal arguments. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final List<FormalArgs>static final FormalArgsEmpty tuple of formal arguments. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty formal argument tuple.FormalArgs(FormalArg<?>... args) Creates a tuple of formal arguments from an array.FormalArgs(FormalArgs fargs1, FormalArgs fargs2) Creates a tuple of formal arguments by merging two tuples.FormalArgs(List<FormalArg<?>> args) Creates a tuple of formal arguments from a list. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccepts(FormalArgs other) Returnstruewhen this formal tuple can accept another formal tuple.static FormalArgs.Builderbuilder()booleanFormalArg<?>getArg(int index) Returns the argument that has a position.FormalArg<?>Returns the argument that has a name.intgetArgIndex(String name) Returns the index of an argument.FormalArg<?>[]getArgs()Returns the arguments that match a necessity.booleanReturnstruewhen this tuple contains an argument that has a given name.booleanhasArgMatchingName(FormalArg<?> farg) booleanReturnstrueif this tuple of formal arguments contains at least one argument whose necessity matches a necessity.inthashCode()booleanisEmpty()static FormalArgsmerge(FormalArgs... all) static FormalArgsmerge(FormalArgs fargs1, FormalArgs fargs2) Merges 2 tuples of formal arguments.intsize()toString()
-
Field Details
-
NO_FARGS
Empty tuple of formal arguments. -
DEFAULT_FARGS_LIST
-
-
Constructor Details
-
FormalArgs
public FormalArgs()Creates an empty formal argument tuple. -
FormalArgs
Creates a tuple of formal arguments from an array.- Parameters:
args- The formal arguments.- Throws:
IllegalArgumentException- Whenargsof of of its elements isnull, or when there are duplicate names.
-
FormalArgs
Creates a tuple of formal arguments from a list.- Parameters:
args- The formal arguments.- Throws:
IllegalArgumentException- Whenargsof of of its elements isnull, or when there are duplicate names.
-
FormalArgs
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:
trueif this list is empty.
-
getArgs
- Returns:
- The formal arguments as an array.
-
hasArgs
Returnstrueif this tuple of formal arguments contains at least one argument whose necessity matches a necessity.- Parameters:
necessity- The necessity.- Returns:
trueif this list contains at least one argument whose necessity matchesnecessity.
-
getArgs
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
Returns the argument that has a position.- Parameters:
index- The index- Returns:
- The argument at
index.
-
getArgIndex
Returns the index of an argument.- Parameters:
name- The argument name.- Returns:
- The index of the argument whose name is
nameor -1.
-
getArg
Returns the argument that has a name.- Parameters:
name- The argument name.- Returns:
- The argument whose name is
nameornull.
-
hasArg
Returnstruewhen this tuple contains an argument that has a given name.- Parameters:
name- The name.- Returns:
truewhen this tuple contains an argument namedname.
-
hasArgMatchingName
-
accepts
Returnstruewhen 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
otheror are present inotherand compliant.
- Parameters:
other- The other formal tuple.- Returns:
truewhen this formal tuple can accept other formal tuple.
- all mandatory args of this tuple are present and compliant in
-
merge
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
leftandright. - Throws:
IllegalArgumentException- if there is a type conflict when merging 2 arguments.
-
merge
-
hashCode
public int hashCode() -
equals
-
toString
-
builder
- Returns:
- A new Builder instance.
-