Interface VersionIterator

  • All Known Implementing Classes:
    AbstractVersionIterator

    public interface VersionIterator
    An iterator over the parts of a version. The iterator starts off in the "initial" position. Use the hasNext() and next() methods to move the cursor to each segment of the version string in turn.
    • Method Detail

      • hasNext

        boolean hasNext()
        Determine whether a subsequent token exists in this version.
        Returns:
        true if more tokens remain, false otherwise
      • length

        int length()
        Get the length of the current token. If there is no current token, zero is returned.
        Returns:
        the length of the current token
      • isSeparator

        default boolean isSeparator()
        Determine if the current token is some kind of separator (a character or a zero-length alphabetical-to-numeric or numeric-to-alphabetical transition).
        Returns:
        true if the token is a separator, false otherwise
      • isPart

        default boolean isPart()
        Determine if the current token is some kind of part (alphabetical or numeric).
        Returns:
        true if the token is a part, false otherwise
      • isEmptySeparator

        boolean isEmptySeparator()
        Determine if the current token is an empty (or zero-length alphabetical-to-numeric or numeric-to-alphabetical) separator. Note that some version schemes do not have empty separators.
        Returns:
        true if the token is an empty separator, false otherwise
      • isNonEmptySeparator

        boolean isNonEmptySeparator()
        Determine if the current token is a non-empty separator.
        Returns:
        true if the token is a non-empty separator, false otherwise
      • getSeparatorCodePoint

        int getSeparatorCodePoint()
        Get the code point of the current separator. If the iterator is not positioned on a non-empty separator (i.e. isNonEmptySeparator() returns false), then an exception is thrown.
        Returns:
        the code point of the current separator
        Throws:
        IllegalStateException - if the current token is not a non-empty separator
      • isAlphaPart

        boolean isAlphaPart()
        Determine if the current token is an alphabetical part.
        Returns:
        true if the token is an alphabetical part, false otherwise
      • isNumberPart

        boolean isNumberPart()
        Determine if the current token is a numeric part.
        Returns:
        true if the token is a numeric part, false otherwise
      • getAlphaPart

        String getAlphaPart()
                     throws IllegalStateException
        Get the current alphabetical part. If the iterator is not positioned on an alphabetical part (i.e. isAlphaPart() returns false), then an exception is thrown.
        Returns:
        the current alphabetical part
        Throws:
        IllegalStateException - if the current token is not an alphabetical part
      • appendAlphaPartTo

        StringBuilder appendAlphaPartTo​(StringBuilder target)
                                 throws IllegalStateException
        Append the current alphabetical part to the given string builder. If the iterator is not positioned on an alphabetical part (i.e. isAlphaPart() returns false), then an exception is thrown.
        Parameters:
        target - the StringBuilder to append
        Returns:
        the current alphabetical part
        Throws:
        IllegalStateException - if the current token is not an alphabetical part
      • alphaPartEquals

        default boolean alphaPartEquals​(String str,
                                        boolean ignoreCase)
                                 throws IllegalStateException
        Determine whether the current alphabetical part is equal to the given test string. If the iterator is not positioned on an alphabetical part (i.e. isAlphaPart() returns false), then an exception is thrown.
        Parameters:
        str - the string to compare (must not be null)
        ignoreCase - true to perform a case-insensitive comparison, or false to perform a case-sensitive comparison
        Returns:
        true if the segment matches the given string; false otherwise
        Throws:
        IllegalStateException - if the current token is not an alphabetical part
      • alphaPartEquals

        default boolean alphaPartEquals​(String str,
                                        int offs,
                                        int len,
                                        boolean ignoreCase)
                                 throws IllegalStateException,
                                        StringIndexOutOfBoundsException
        Determine whether the current alphabetical part is equal to the given test string. If the iterator is not positioned on an alphabetical part (i.e. isAlphaPart() returns false), then an exception is thrown.
        Parameters:
        str - the string to compare (must not be null)
        offs - the offset into the string to compare
        len - the length to compare
        ignoreCase - true to perform a case-insensitive comparison, or false to perform a case-sensitive comparison
        Returns:
        true if the segment matches the given string; false otherwise
        Throws:
        IllegalStateException - if the current token is not an alphabetical part
        StringIndexOutOfBoundsException - if the given offset or length fall outside of the string
      • compareAlphaPart

        default int compareAlphaPart​(String str,
                                     boolean ignoreCase)
                              throws IllegalStateException
        Compare two alphabetical parts lexicographically. This iterator must be positioned at an alphabetical part or an exception is thrown.
        Parameters:
        str - the string to compare against (must not be null)
        ignoreCase - true to perform a case-insensitive comparison, or false to perform a case-sensitive comparison
        Returns:
        -1, 0, or 1 if this segment is less than, equal to, or greater than the given string
        Throws:
        IllegalStateException - if this iterator is not positioned on an alphabetical part
      • compareAlphaPart

        int compareAlphaPart​(String str,
                             int offs,
                             int len,
                             boolean ignoreCase)
                      throws IllegalStateException,
                             StringIndexOutOfBoundsException
        Compare two alphabetical parts lexicographically. This iterator must be positioned at an alphabetical part or an exception is thrown.
        Parameters:
        str - the string to compare against (must not be null)
        offs - the offset into the string to compare
        len - the length to compare
        ignoreCase - true to perform a case-insensitive comparison, or false to perform a case-sensitive comparison
        Returns:
        -1, 0, or 1 if this segment is less than, equal to, or greater than the given string
        Throws:
        IllegalStateException - if this iterator is not positioned on an alphabetical part
        StringIndexOutOfBoundsException - if the given offset or length fall outside of the string
      • compareAlphaPart

        int compareAlphaPart​(VersionIterator other,
                             boolean ignoreCase)
                      throws IllegalStateException
        Compare two alphabetical parts lexicographically. Both this and the other iterator must be positioned at alphabetical parts or an exception is thrown.
        Parameters:
        other - the other iterator (must not be null)
        ignoreCase - a boolean to ignore case in the compare
        Returns:
        -1, 0, or 1 if this segment is less than, equal to, or greater than the other iterator's part
        Throws:
        IllegalStateException - if this or the other iterator are not positioned on an alphabetical part
      • getNumberPartAsString

        default String getNumberPartAsString()
                                      throws IllegalStateException
        Get the current numeric part, as a String. If the iterator is not positioned on a numeric part (i.e. isNumberPart() returns false), then an exception is thrown. Any redundant leading zeros are removed.
        Returns:
        the current numeric part as a String
        Throws:
        IllegalStateException - if the current token is not a numeric part
      • appendNumberPartTo

        StringBuilder appendNumberPartTo​(StringBuilder target)
                                  throws IllegalStateException
        Get the current numeric part, appending it to the given builder. If the iterator is not positioned on a numeric part (i.e. isNumberPart() returns false), then an exception is thrown. Any redundant leading zeros are removed.
        Parameters:
        target - the StringBuilder to append
        Returns:
        the current numeric part as a String
        Throws:
        IllegalStateException - if the current token is not a numeric part
      • getNumberPartAsLong

        long getNumberPartAsLong()
                          throws IllegalStateException
        Get the current numeric part, as a long. If the iterator is not positioned on a numeric part (i.e. isNumberPart() returns false), then an exception is thrown. If the value overflows the maximum value for a long, then only the low-order 64 bits of the version number value are returned.
        Returns:
        the current numeric part as a long
        Throws:
        IllegalStateException - if the current token is not a numeric part
      • getNumberPartAsInt

        int getNumberPartAsInt()
                        throws IllegalStateException
        Get the current numeric part, as an int. If the iterator is not positioned on a numeric part (i.e. isNumberPart() returns false), then an exception is thrown. If the value overflows the maximum value for an int, then only the low-order 32 bits of the version number value are returned.
        Returns:
        the current numeric part as an int
        Throws:
        IllegalStateException - if the current token is not a numeric part
      • getNumberPartAsBigInteger

        default BigInteger getNumberPartAsBigInteger()
                                              throws IllegalStateException
        Get the current numeric part, as a BigInteger. If the iterator is not positioned on a numeric part (i.e. isNumberPart() returns false), then an exception is thrown.
        Returns:
        the current numeric part as a BigInteger
        Throws:
        IllegalStateException - if the current token is not a numeric part
      • numberPartEquals

        default boolean numberPartEquals​(int value)
                                  throws IllegalStateException
        Determine whether the current numeric part equals the given value (which is treated as unsigned).
        Parameters:
        value - the unsigned value
        Returns:
        true if the values are equal, or false otherwise
        Throws:
        IllegalStateException - if the current token is not a numeric part
      • numberPartEquals

        default boolean numberPartEquals​(long value)
                                  throws IllegalStateException
        Determine whether the current numeric part equals the given value (which is treated as unsigned).
        Parameters:
        value - the unsigned value
        Returns:
        true if the values are equal, or false otherwise
        Throws:
        IllegalStateException - if the current token is not a numeric part
      • compareNumberPart

        int compareNumberPart​(int value)
                       throws IllegalStateException
        Compare two numerical parts (using an unsigned comparison). This iterator must be positioned at a numerical part or an exception is thrown.
        Parameters:
        value - the number to compare against
        Returns:
        -1, 0, or 1 if this segment is less than, equal to, or greater than the given value
        Throws:
        IllegalStateException - if this iterator is not positioned on a numeric part
      • compareNumberPart

        int compareNumberPart​(long value)
                       throws IllegalStateException
        Compare two numerical parts (using an unsigned comparison). This iterator must be positioned at a numerical part or an exception is thrown.
        Parameters:
        value - the number to compare against
        Returns:
        -1, 0, or 1 if this segment is less than, equal to, or greater than the given value
        Throws:
        IllegalStateException - if this iterator is not positioned on a numeric part
      • compareNumberPart

        default int compareNumberPart​(String value)
                               throws IllegalStateException
        Compare two numerical parts (using an unsigned comparison). This iterator must be positioned at a numerical part or an exception is thrown. The given string must be numeric according to the rules of this iterator or an exception is thrown.
        Parameters:
        value - the number to compare against
        Returns:
        -1, 0, or 1 if this segment is less than, equal to, or greater than the given value
        Throws:
        IllegalStateException - if this iterator is not positioned on a numeric part
        IllegalArgumentException - if the given string is not numeric according to the rules of this iterator
      • compareNumberPart

        int compareNumberPart​(String value,
                              int offs,
                              int len)
                       throws IllegalStateException
        Compare two numerical parts (using an unsigned comparison). This iterator must be positioned at a numerical part or an exception is thrown. The given string must be numeric according to the rules of this iterator or an exception is thrown.
        Parameters:
        value - the number to compare against
        offs - the offset into the string to compare
        len - the length to compare
        Returns:
        -1, 0, or 1 if this segment is less than, equal to, or greater than the given value
        Throws:
        IllegalStateException - if this iterator is not positioned on a numeric part
        IllegalArgumentException - if the given string is not numeric according to the rules of this iterator
      • compareNumberPart

        int compareNumberPart​(VersionIterator other)
        Compare two numerical parts (using an unsigned comparison). Both iterators must be positioned at a numerical part or an exception is thrown.
        Parameters:
        other - the other iterator (must not be null)
        Returns:
        -1, 0, or 1 if this segment is less than, equal to, or greater than the other iterator's part
        Throws:
        IllegalStateException - if this or the other iterator are not positioned on an numerical part
      • appendPartTo

        StringBuilder appendPartTo​(StringBuilder b)
        Append this version part to the given string builder. This is used to produce a canonical representation of an input string.
        Parameters:
        b - the string builder (must not be null)
        Returns:
        the same string builder (not null)