Package cdc.args
Class FormalArg<T>
java.lang.Object
cdc.args.FormalArg<T>
- Type Parameters:
T- Type of the formal argument.
- Direct Known Subclasses:
CompositeFormalArg,MapFormalArg
Class used to describe a formal argument.
A formal argument has a name, a type and may be optional or mandatory.
- Author:
- Damien Carbonne
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> FormalArg.Builder<T>static voidChecks a name.booleanfinal Stringfinal StringgetName()final NecessitygetType()inthashCode()final booleanhasWeakerNecessity(Necessity other) Returnstrueif the necessity of this formal argument is weaker than (or equal to) another necessity.final booleanhasWeakerType(Class<?> other) Returnstrueif the (wrapped) type of this formal argument can be assigned by another type.final booleanisCompliantWith(Object value) Returns whether a value is compliant with this formal argument.final booleanfinal booleanstatic booleanReturns true when a string can be used as a valid name.final booleanisWeakerThan(FormalArg<?> other) Returnstrueif this formal argument is weaker than another one.final booleanmatchesName(String other) Returnstrueif the name of this formal argument equals another name.static FormalArg<?>Merges 2 formal arguments.toString()
-
Constructor Details
-
FormalArg
Creates a formal argument.- Parameters:
name- The formal argument name.type- The formal argument type.necessity- The formal argument necessity.- Throws:
IllegalArgumentException- whennameis invalid, or whentypeornecessityisnull.
-
FormalArg
Creates a MANDATORY formal argument.- Parameters:
name- The formal argument name.type- The formal argument type.- Throws:
IllegalArgumentException- whennameis invalid, or whentypeisnull.
-
-
Method Details
-
isValidName
Returns true when a string can be used as a valid name.Rules are very relaxed: only
nullnames are forbidden.
Stronger rules should be applied.- Parameters:
s- The string- Returns:
- True when
sis a valid name.
-
checkName
Checks a name.- Parameters:
name- The name- Throws:
IllegalArgumentException- whennameis invalid.
-
getName
- Returns:
- The formal argument name.
-
getType
- Returns:
- The formal argument type.
-
getDescription
- Returns:
- The formal argument description.
-
getWrappedType
- Returns:
- The formal argument wrapped type.
-
getNecessity
- Returns:
- The formal argument necessity.
-
isMandatory
public final boolean isMandatory()- Returns:
trueif this formal argument is mandatory.
-
isOptional
public final boolean isOptional()- Returns:
trueif this formal argument is optional.
-
isCompliantWith
Returns whether a value is compliant with this formal argument.If
valueis null, then this formal argument must be optional.
Otherwise,valuemust be assignable towrappedTypeof the formal argument.- Parameters:
value- The value to check.- Returns:
- Whether
valueis compliant with this formal argument.
-
matchesName
Returnstrueif the name of this formal argument equals another name.- Parameters:
other- The other name.- Returns:
trueif the name of this formal argument equalsother.
-
hasWeakerType
Returnstrueif the (wrapped) type of this formal argument can be assigned by another type.- Parameters:
other- The other type.- Returns:
trueif the (wrapped) type of this formal argument can be assigned byother.
-
hasWeakerNecessity
Returnstrueif the necessity of this formal argument is weaker than (or equal to) another necessity.- Parameters:
other- The other necessity.- Returns:
trueif the necessity of this formal argument is weaker than (or equal to)other.
-
isWeakerThan
Returnstrueif this formal argument is weaker than another one.This is the case when any argument that is compliant with
otheris compliant with this formal argument.It must have:
- The same name.
- A weaker necessity.
- A weaker (more general) type.
- Parameters:
other- The other formal argument.- Returns:
trueif this formal argument is weaker thanother.
-
merge
Merges 2 formal arguments.This is possible if one of them is
null, or they have same name and compliant types.
In that case, if necessity are different, the resulting necessity is MANDATORY.
When types are compliant, the most specialized one is chosen.For example:
merge(null, null) = nullmerge(null, w) = xmerge(x, null) = xmerge((name1, ...), (name2, ...)) throws IllegalArgumentExceptionmerge((name, String.class, OPTIONAL), (name, Object, OPTIONAL)) = (name, String.class, OPTIONAL)merge((name, String.class, OPTIONAL), (name, Object, MANDATORY)) = (name, String.class, MANDATORY)merge((name, String.class, OPTIONAL), (name, Integer, OPTIONAL)) = throws IllegalArgumentException
- Parameters:
farg1- The first formal argument (possiblynull).farg2- The second formal argument (possiblynull).privileged- The privileged necessity.- Returns:
- The merge of
farg1andfarg2. - Throws:
IllegalArgumentException- When merge is impossible (names conflict or types conflict).
-
hashCode
public int hashCode() -
equals
-
toString
-
builder
-