Package cdc.args
Class FormalArgs
- java.lang.Object
-
- cdc.args.FormalArgs
-
public final class FormalArgs extends Object
Tuple of formal arguments.- Author:
- Damien Carbonne
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFormalArgs.BuilderBuilder of formal arguments.
-
Field Summary
Fields Modifier and Type Field Description static List<FormalArgs>DEFAULT_FARGS_LISTstatic FormalArgsNO_FARGSEmpty tuple of formal arguments.
-
Constructor Summary
Constructors Constructor Description FormalArgs()Creates 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccepts(FormalArgs other)Returnstruewhen this formal tuple can accept another formal tuple.static FormalArgs.Builderbuilder()booleanequals(Object other)FormalArg<?>getArg(int index)Returns the argument that has a position.FormalArg<?>getArg(String name)Returns the argument that has a name.intgetArgIndex(String name)Returns the index of an argument.FormalArg<?>[]getArgs()FormalArgsgetArgs(Necessity necessity)Returns the arguments that match a necessity.booleanhasArg(String name)Returnstruewhen this tuple contains an argument that has a given name.booleanhasArgMatchingName(FormalArg<?> farg)booleanhasArgs(Necessity necessity)Returnstrueif 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()StringtoString()
-
-
-
Field Detail
-
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 Detail
-
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- Whenargsof of of its elements isnull, 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- Whenargsof of of its elements isnull, 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 Detail
-
isEmpty
public boolean isEmpty()
- Returns:
trueif this list is empty.
-
getArgs
public FormalArg<?>[] getArgs()
- Returns:
- The formal arguments as an array.
-
hasArgs
public boolean hasArgs(Necessity necessity)
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
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
nameor -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
nameornull.
-
hasArg
public boolean hasArg(String name)
Returnstruewhen this tuple contains an argument that has a given name.- Parameters:
name- The name.- Returns:
truewhen this tuple contains an argument namedname.
-
hasArgMatchingName
public boolean hasArgMatchingName(FormalArg<?> farg)
-
accepts
public boolean accepts(FormalArgs other)
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
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
leftandright. - Throws:
IllegalArgumentException- if there is a type conflict when merging 2 arguments.
-
merge
public static FormalArgs merge(FormalArgs... all)
-
builder
public static FormalArgs.Builder builder()
- Returns:
- A new Builder instance.
-
-