Class VersionFactory


  • public class VersionFactory
    extends Object
    The utility class used to create version instances.
    • 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 is null
      • isLegal

        public static boolean isLegal​(Scheme scheme,
                                      String s)
        Returns true if the given string is a legal version which, for example, can be parsed using valueOf(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 to 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)
        Returns true if the given string is a legal version which, for example, can be parsed using valueOf(Scheme, String, boolean) without exceptions using the implementation selected by the given scheme.
        This method is different than isLegal(Scheme, String, String) as it also sanitizes extra characters in the body of the version identifier instead of just an optional prefix (when sanitize is true).
        Parameters:
        scheme - the scheme to check against.
        s - the string version to check.
        lenient - when true 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)
        Returns true if the given string is a legal version which, for example, can be parsed using valueOf(Scheme, String, boolean) without exceptions using the implementation selected by the given scheme.
        This method is different than isLegal(Scheme, String, boolean) as it only tolerates a prefix, while isLegal(Scheme, String, boolean) is more lenient as it also sanitizes extra characters in the body of the version identifier (when sanitize is true).
        Parameters:
        scheme - the scheme to 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 be null 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 to
        s - 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 is null
        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.
        If sanitize is true 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 than valueOf(Scheme, String, String) as it also sanitizes extra characters in the body of the version identifier instead of just an optional prefix (when sanitize is true).
        Parameters:
        scheme - the scheme the version belongs to
        s - the string to parse
        sanitize - 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 is null
        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 than valueOf(Scheme, String, boolean) as it only tolerates a prefix, while valueOf(Scheme, String, boolean) is more lenient as it also sanitizes extra characters in the body of the version identifier (when sanitize is true).
        Parameters:
        scheme - the scheme the version belongs to
        s - the string to parse
        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 be null 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 is null
        IllegalArgumentException - if the given string doesn't represent a legal version, according to the selected scheme