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.Buildercan be used to create instances of Args.Compliance rules
There is compliance between Args
argsand FormalArgsfargswhen:- In STRICT mode: each
argofargscorresponds to onefargoffargswith a compliant value. - In LOOSE mode: each
argofargs1) is absent offargs, 2) or corresponds to onefargoffargswith a compliant value. - In both nodes, each MANDATORY
farghas a compliant value defined inargs.
fargs = [arg0: MANDATORY String, arg1: OPTIONAL Object], compliance will be:truewith:args = [arg0: "Hello"]in any mode.truewith:args = [arg0: "Hello", arg1: null]in any mode.truewith:args = [arg0: "Hello", arg1: "World"]in any mode.truewith:args = [arg0: "Hello", arg2: null]in LOOSE mode.falsewith:args = [arg0: "Hello", arg2: null]in STRICT mode.falsewith:args = [arg0: null]in any mode.
- Author:
- Damien Carbonne
- In STRICT mode: each
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classArgs.BuilderHelper class used to create Args.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleanareCompliant(Args args, FormalArgs fargs, Strictness strictness)Returnstruewhen an arguments is compliant with a formal arguments.static booleanareCompliant(Args args, Strictness strictness, FormalArgs... array)static booleanareCompliant(Args args, Strictness strictness, Collection<FormalArgs> collection)static booleanareLooselyCompliant(Args args, FormalArgs fargs)Returnstruewhen an arguments is loosely compliant with a formal arguments.static booleanareLooselyCompliant(Args args, FormalArgs... array)static booleanareLooselyCompliant(Args args, Collection<FormalArgs> collection)static booleanareStrictlyCompliant(Args args, FormalArgs fargs)Returnstruewhen an arguments is strictly compliant with a formal arguments.static booleanareStrictlyCompliant(Args args, FormalArgs... array)static booleanareStrictlyCompliant(Args args, Collection<FormalArgs> collection)static Args.Builderbuilder()static Args.Builderbuilder(FormalArgs fargs)static voidcheckCompliance(Args args, Strictness strictness, FormalArgs... array)static voidcheckCompliance(Args args, Strictness strictness, Collection<FormalArgs> collection)voidcheckComplianceWithOneOf(Strictness strictness, FormalArgs... array)Checks compliance of the arguments with formal arguments tuples.voidcheckComplianceWithOneOf(Strictness strictness, Collection<FormalArgs> collection)Checks compliance of this arguments with one of a collection of formal arguments.static voidcheckLooseCompliance(Args args, FormalArgs... array)static voidcheckLooseCompliance(Args args, Collection<FormalArgs> collection)voidcheckLooseComplianceWithOneOf(FormalArgs... array)Checks loose compliance of the arguments with formal arguments tuples.voidcheckLooseComplianceWithOneOf(Collection<FormalArgs> collection)Checks loose compliance of this arguments with one of a collection of formal arguments.static voidcheckStrictCompliance(Args args, FormalArgs... array)static voidcheckStrictCompliance(Args args, Collection<FormalArgs> collection)voidcheckStrictComplianceWithOneOf(FormalArgs... array)Checks strict compliance of the arguments with formal arguments tuples.voidcheckStrictComplianceWithOneOf(Collection<FormalArgs> collection)Checks strict compliance of this arguments with one of a collection of formal arguments.booleanequals(Object object)ArggetArg(String name)Returns the argument that has a given name ornull.List<Arg>getArgs()List<String>getNames()List<String>getSortedNames()<T> TgetValue(FormalArg<T> farg)Returns the value associated to a formal argument ornull.<T> TgetValue(FormalArg<T> farg, T def)Returns the value associated to a formal argument or a default value.ObjectgetValue(String name)Returns the value (as Object) associated to a name or null.<T> TgetValue(String name, Class<T> cls)Returns the value associated to a name, as a type, ornull.<T> TgetValue(String name, Class<T> cls, T def)Returns the value associated to a name, as a type, or a default value.ObjectgetValue(String name, Object def)Returns the value (as Object) associated to a name or a default value.booleanhasArg(String name)Returnstrueif this Args contains an argument with a particular name.booleanhasArgWithMatchingName(FormalArg<?> farg)Returnstrueif this tuple contains an argument whose name matches the name of a formal argument.inthashCode()booleanisCompliantWith(FormalArgs fargs, Strictness strictness)Returns true when this Args is compliant with formal arguments and strictness.booleanisCompliantWithOneOf(Strictness strictness, FormalArgs... array)Returnstrueif this arguments is compliant with at least one formal argument tuple.booleanisCompliantWithOneOf(Strictness strictness, Collection<FormalArgs> collection)Returnstrueif this arguments is compliant with at least one formal argument tuple.booleanisConflictingWith(FormalArgs fargs)booleanisEmpty()booleanisEmptyOrAllValuesAreNull()booleanisLooselyCompliantWith(FormalArgs fargs)Returns true when this Args is loosely compliant with formal arguments.booleanisLooselyCompliantWithOneOf(FormalArgs... array)Returnstrueif this arguments is loosely compliant with at least one formal argument tuple.booleanisLooselyCompliantWithOneOf(Collection<FormalArgs> collection)Returnstrueif this arguments is loosely compliant with at least one formal argument tuple.booleanisStrictlyCompliantWith(FormalArgs fargs)Returns true when this Args is strictly compliant with formal arguments.booleanisStrictlyCompliantWithOneOf(FormalArgs... array)Returnstrueif this arguments is strictly compliant with at least one formal argument tuple.booleanisStrictlyCompliantWithOneOf(Collection<FormalArgs> collection)Returnstrueif this arguments is strictly compliant with at least one formal argument tuple.static FormalArgsreduceNecessity(FormalArgs fargs, Args args)Argsset(Args other)Creates a new set from this one and another one.intsize()StringtoString()
-
-
-
Field Detail
-
NO_ARGS
public static final Args NO_ARGS
Empty arguments.
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
- Returns:
truewhen there are no arguments.
-
isEmptyOrAllValuesAreNull
public boolean isEmptyOrAllValuesAreNull()
- Returns:
trueif this tuple is empty or all its values arenull.
-
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.
-
getArg
public Arg getArg(String name)
Returns the argument that has a given name ornull.- Parameters:
name- The name.- Returns:
- The argument named
nameornull
-
hasArg
public boolean hasArg(String name)
Returnstrueif this Args contains an argument with a particular name.- Parameters:
name- The name.- Returns:
trueif this args contains an argument namedname.
-
hasArgWithMatchingName
public boolean hasArgWithMatchingName(FormalArg<?> farg)
Returnstrueif this tuple contains an argument whose name matches the name of a formal argument.- Parameters:
farg- The formal argument.- Returns:
trueif this tuple contains an argument whose name matches the name offarg.
-
set
public Args set(Args other)
Creates a new set from this one and another one.Values in
othertake 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,
nullis returned.- Parameters:
name- Name of the retrieved value.- Returns:
- The value (as Object) associated to name or null.
- Throws:
IllegalArgumentException- Whennameisnull.
-
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
fargornull. - Throws:
IllegalArgumentException- Whenfargisnull.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 ornull.- Type Parameters:
T- The formal argument type.- Parameters:
farg- The formal argument.- Returns:
- The value associated to
farg. - Throws:
IllegalArgumentException- Whenfargisnull.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
nameordef. - Throws:
IllegalArgumentException- Whennameofclsisnull.ClassCastException- When the associated value can not be cast tocls.
-
getValue
public <T> T getValue(String name, Class<T> cls)
Returns the value associated to a name, as a type, ornull.If no value is associated to name,
nullis 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
nameornull. - Throws:
IllegalArgumentException- Whennameofclsisnull.ClassCastException- When the associated value can not be cast tocls.
-
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:
trueif this Args is compliant withfargsandstrictness.
-
isLooselyCompliantWith
public boolean isLooselyCompliantWith(FormalArgs fargs)
Returns true when this Args is loosely compliant with formal arguments.- Parameters:
fargs- The formal arguments.- Returns:
trueif this Args is loosely compliant withfargs.
-
isStrictlyCompliantWith
public boolean isStrictlyCompliantWith(FormalArgs fargs)
Returns true when this Args is strictly compliant with formal arguments.- Parameters:
fargs- The formal arguments.- Returns:
trueif this Args is strictly compliant withfargs.
-
isConflictingWith
public boolean isConflictingWith(FormalArgs fargs)
-
isCompliantWithOneOf
public boolean isCompliantWithOneOf(Strictness strictness, Collection<FormalArgs> collection)
Returnstrueif this arguments is compliant with at least one formal argument tuple.- Parameters:
strictness- The compliance strictness.collection- The collection of formal arguments tuples.- Returns:
trueif this arguments is compliant with at least one element ofcollection.
-
isLooselyCompliantWithOneOf
public boolean isLooselyCompliantWithOneOf(Collection<FormalArgs> collection)
Returnstrueif this arguments is loosely compliant with at least one formal argument tuple.- Parameters:
collection- The collection of formal arguments tuples.- Returns:
trueif this arguments is loosely compliant with at least one element ofcollection.
-
isStrictlyCompliantWithOneOf
public boolean isStrictlyCompliantWithOneOf(Collection<FormalArgs> collection)
Returnstrueif this arguments is strictly compliant with at least one formal argument tuple.- Parameters:
collection- The collection of formal arguments tuples.- Returns:
trueif this arguments is strictly compliant with at least one element ofcollection.
-
isCompliantWithOneOf
public boolean isCompliantWithOneOf(Strictness strictness, FormalArgs... array)
Returnstrueif this arguments is compliant with at least one formal argument tuple.- Parameters:
strictness- The compliance strictness.array- The array of formal arguments tuples.- Returns:
trueif this arguments is compliant with at least one element ofarray.
-
isLooselyCompliantWithOneOf
public boolean isLooselyCompliantWithOneOf(FormalArgs... array)
Returnstrueif this arguments is loosely compliant with at least one formal argument tuple.- Parameters:
array- The array of formal arguments tuples.- Returns:
trueif this arguments is loosely compliant with at least one element ofarray.
-
isStrictlyCompliantWithOneOf
public boolean isStrictlyCompliantWithOneOf(FormalArgs... array)
Returnstrueif this arguments is strictly compliant with at least one formal argument tuple.- Parameters:
array- The array of formal arguments tuples.- Returns:
trueif this arguments is strictly compliant with at least one element ofarray.
-
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)
Returnstruewhen an arguments is compliant with a formal arguments.- Parameters:
args- The arguments.fargs- The formal arguments.strictness- The strictness.- Returns:
truewhenargsis compliant withfargs.
-
areLooselyCompliant
public static boolean areLooselyCompliant(Args args, FormalArgs fargs)
Returnstruewhen an arguments is loosely compliant with a formal arguments.- Parameters:
args- The arguments.fargs- The formal arguments.- Returns:
truewhenargsis loosely compliant withfargs.
-
areStrictlyCompliant
public static boolean areStrictlyCompliant(Args args, FormalArgs fargs)
Returnstruewhen an arguments is strictly compliant with a formal arguments.- Parameters:
args- The arguments.fargs- The formal arguments.- Returns:
truewhenargsis strictly compliant withfargs.
-
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)
-
builder
public static Args.Builder builder()
- Returns:
- A new Builder instance.
-
builder
public static Args.Builder builder(FormalArgs fargs)
-
-