Package com.mooltiverse.oss.nyx.version
Class VersionFactory
- java.lang.Object
-
- com.mooltiverse.oss.nyx.version.VersionFactory
-
public class VersionFactory extends Object
The utility class used to create version instances.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Version
defaultInitial(Scheme scheme)
Returns a Version instance representing the default initial value to use for the given scheme.static boolean
isLegal(Scheme scheme, String s)
Returnstrue
if the given string is a legal version which, for example, can be parsed usingvalueOf(Scheme, String)
without exceptions using the implementation selected by the given scheme.static boolean
isLegal(Scheme scheme, String s, boolean lenient)
Returnstrue
if the given string is a legal version which, for example, can be parsed usingvalueOf(Scheme, String, boolean)
without exceptions using the implementation selected by the given scheme.static boolean
isLegal(Scheme scheme, String s, String prefix)
Returnstrue
if the given string is a legal version which, for example, can be parsed usingvalueOf(Scheme, String, boolean)
without exceptions using the implementation selected by the given scheme.static Version
valueOf(Scheme scheme, String s)
Returns a Version instance representing the specified String value.static Version
valueOf(Scheme scheme, String s, boolean sanitize)
Returns a Version instance representing the specified String value.static Version
valueOf(Scheme scheme, String s, String prefix)
Returns a Version instance representing the specified String value.
-
-
-
Method Detail
-
defaultInitial
public static final Version defaultInitial(Scheme scheme)
Returns a Version instance representing the default initial value to use for the given scheme.- Parameters:
scheme
- the scheme to get the initial version for- Returns:
- the new Version instance representing the default initial value. The concrete class depends on the given
scheme
- Throws:
NullPointerException
- if the given arguument isnull
-
isLegal
public static boolean isLegal(Scheme scheme, String s)
Returnstrue
if the given string is a legal version which, for example, can be parsed usingvalueOf(Scheme, String)
without exceptions using the implementation selected by the given scheme.
This method uses a strict criteria, without trying to sanitize the given string.- Parameters:
scheme
- the scheme the check against.s
- the string version to check.- Returns:
true
if the given string represents a legal version sing the implementation selected by the given scheme,false
otherwise.- See Also:
valueOf(Scheme, String)
-
isLegal
public static boolean isLegal(Scheme scheme, String s, boolean lenient)
Returnstrue
if the given string is a legal version which, for example, can be parsed usingvalueOf(Scheme, String, boolean)
without exceptions using the implementation selected by the given scheme.
This method is different thanisLegal(Scheme, String, String)
as it also sanitizes extra characters in the body of the version identifier instead of just an optional prefix (whensanitize
istrue
).- Parameters:
scheme
- the scheme the check against.s
- the string version to check.lenient
- whentrue
prefixes and non critical extra characters are tolerated even if they are not strictly legal from the version scheme specification perspective.- Returns:
true
if the given string represents a legal version sing the implementation selected by the given scheme,false
otherwise.- See Also:
valueOf(Scheme, String, boolean)
-
isLegal
public static boolean isLegal(Scheme scheme, String s, String prefix)
Returnstrue
if the given string is a legal version which, for example, can be parsed usingvalueOf(Scheme, String, boolean)
without exceptions using the implementation selected by the given scheme.
This method is different thanisLegal(Scheme, String, boolean)
as it only tolerates a prefix, whileisLegal(Scheme, String, boolean)
is more lenient as it also sanitizes extra characters in the body of the version identifier (whensanitize
istrue
).- Parameters:
scheme
- the scheme the check against.s
- the string version to check.prefix
- the initial string that is used for the version prefix. This will be stripped off from the given string representation of the version. It can benull
or empty, in which case it's ignored. If not empty and the given version string doesn't start with this prefix, this prefix is ignored.- Returns:
true
if the given string represents a legal version sing the implementation selected by the given scheme,false
otherwise.- See Also:
valueOf(Scheme, String, boolean)
-
valueOf
public static final Version valueOf(Scheme scheme, String s)
Returns a Version instance representing the specified String value. No sanitization attempt is done.- Parameters:
scheme
- the scheme the version belongs tos
- the string to parse- Returns:
- the new Version instance representing the given string. The concrete class depends on the given
scheme
- Throws:
NullPointerException
- if a given arguument isnull
IllegalArgumentException
- if the given string doesn't represent a legal version, according to the selected scheme
-
valueOf
public static final Version valueOf(Scheme scheme, String s, boolean sanitize)
Returns a Version instance representing the specified String value. No sanitization attempt is done.
Ifsanitize
istrue
this method will try to sanitize the given string before parsing so that if there are illegal characters like a prefix or leading zeroes in numeric identifiers they are removed.
When sanitization is enabled on a string that actually needs sanitization the string representation of the returned object will not exactly match the input value.
This method is different thanvalueOf(Scheme, String, String)
as it also sanitizes extra characters in the body of the version identifier instead of just an optional prefix (whensanitize
istrue
).- Parameters:
scheme
- the scheme the version belongs tos
- the string to parsesanitize
- optionally enables sanitization before parsing- Returns:
- the new Version instance representing the given string. The concrete class depends on the given
scheme
- Throws:
NullPointerException
- if a given arguument isnull
IllegalArgumentException
- if the given string doesn't represent a legal version, according to the selected scheme
-
valueOf
public static final Version valueOf(Scheme scheme, String s, String prefix)
Returns a Version instance representing the specified String value.
This method is different thanvalueOf(Scheme, String, boolean)
as it only tolerates a prefix, whilevalueOf(Scheme, String, boolean)
is more lenient as it also sanitizes extra characters in the body of the version identifier (whensanitize
istrue
).- Parameters:
scheme
- the scheme the version belongs tos
- the string to parseprefix
- the initial string that is used for the version prefix. This will be stripped off from the given string representation of the version. It can benull
or empty, in which case it's ignored. If not empty and the given version string doesn't start with this prefix, this prefix is ignored.- Returns:
- the new Version instance representing the given string. The concrete class depends on the given
scheme
- Throws:
NullPointerException
- if a given arguument isnull
IllegalArgumentException
- if the given string doesn't represent a legal version, according to the selected scheme
-
-