Class AbstractVersionIterator

  • All Implemented Interfaces:
    VersionIterator

    public abstract class AbstractVersionIterator
    extends Object
    implements VersionIterator
    A version scheme iterator base class that provides useful utilities and mechanisms. The iterator does not support version strings which are greater than 4095 characters in length.
    • Field Detail

      • string

        protected final String string
    • Constructor Detail

      • AbstractVersionIterator

        protected AbstractVersionIterator​(String string)
        Construct a new instance.
        Parameters:
        string - the version string (must not be null)
    • Method Detail

      • changeType

        protected void changeType​(AbstractVersionIterator.TokenType newType)
        Change the current token type.
        Parameters:
        newType - the new type (must not be null)
      • insertEmptyAlpha

        protected void insertEmptyAlpha()
        Insert an empty part into the current position.
      • insertEmptySeparator

        protected void insertEmptySeparator()
        Insert an empty separator into the current position.
      • insertEmptyNumber

        protected void insertEmptyNumber()
        Insert an empty (zero) number into the current position.
      • setCurrentToken

        protected void setCurrentToken​(AbstractVersionIterator.TokenType tokenType,
                                       int startIndex,
                                       int endIndex,
                                       int extraBits)
        Set the current token.
        Parameters:
        tokenType - the token type (must not be null)
        startIndex - the start index
        endIndex - the end index
        extraBits - extra implementation-specific state bits
      • mark

        protected long mark()
        Mark the current iteration position and state.
        Returns:
        the current iteration cookie
      • reset

        protected void reset​(long mark)
        Restore the iteration position to a previous mark() state.
        Parameters:
        mark - the mark to restore to
      • getStartIndex

        protected int getStartIndex()
        Get the start index of the current token.
        Returns:
        the index into the version string
      • getEndIndex

        protected int getEndIndex()
        Get the end index (exclusive) of the current token. The length
        Returns:
        the index into the version string
      • getExtraBits

        protected int getExtraBits()
        Get the extra implementation-specific state bits.
        Returns:
        the extra bits
      • compareAlphaPart

        public int compareAlphaPart​(String str,
                                    int offs,
                                    int len,
                                    boolean ignoreCase)
                             throws IllegalStateException,
                                    StringIndexOutOfBoundsException
        Description copied from interface: VersionIterator
        Compare two alphabetical parts lexicographically. This iterator must be positioned at an alphabetical part or an exception is thrown.
        Specified by:
        compareAlphaPart in interface VersionIterator
        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

        public int compareAlphaPart​(VersionIterator other,
                                    boolean ignoreCase)
                             throws IllegalStateException
        Description copied from interface: VersionIterator
        Compare two alphabetical parts lexicographically. Both this and the other iterator must be positioned at alphabetical parts or an exception is thrown.
        Specified by:
        compareAlphaPart in interface VersionIterator
        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
      • length

        public int length()
        Description copied from interface: VersionIterator
        Get the length of the current token. If there is no current token, zero is returned.
        Specified by:
        length in interface VersionIterator
        Returns:
        the length of the current token
      • getNumberPartAsInt

        public int getNumberPartAsInt()
        Description copied from interface: VersionIterator
        Get the current numeric part, as an int. If the iterator is not positioned on a numeric part (i.e. VersionIterator.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.
        Specified by:
        getNumberPartAsInt in interface VersionIterator
        Returns:
        the current numeric part as an int
      • getNumberPartAsLong

        public long getNumberPartAsLong()
        Description copied from interface: VersionIterator
        Get the current numeric part, as a long. If the iterator is not positioned on a numeric part (i.e. VersionIterator.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.
        Specified by:
        getNumberPartAsLong in interface VersionIterator
        Returns:
        the current numeric part as a long
      • compareNumberPart

        public int compareNumberPart​(int value)
                              throws IllegalStateException
        Description copied from interface: VersionIterator
        Compare two numerical parts (using an unsigned comparison). This iterator must be positioned at a numerical part or an exception is thrown.
        Specified by:
        compareNumberPart in interface VersionIterator
        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

        public int compareNumberPart​(long value)
                              throws IllegalStateException
        Description copied from interface: VersionIterator
        Compare two numerical parts (using an unsigned comparison). This iterator must be positioned at a numerical part or an exception is thrown.
        Specified by:
        compareNumberPart in interface VersionIterator
        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

        public int compareNumberPart​(String value,
                                     int offs,
                                     int len)
                              throws IllegalStateException
        Description copied from interface: VersionIterator
        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.
        Specified by:
        compareNumberPart in interface VersionIterator
        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
      • compareNumberPart

        public int compareNumberPart​(VersionIterator other)
        Description copied from interface: VersionIterator
        Compare two numerical parts (using an unsigned comparison). Both iterators must be positioned at a numerical part or an exception is thrown.
        Specified by:
        compareNumberPart in interface VersionIterator
        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
      • isPart

        public boolean isPart()
        Description copied from interface: VersionIterator
        Determine if the current token is some kind of part (alphabetical or numeric).
        Specified by:
        isPart in interface VersionIterator
        Returns:
        true if the token is a part, false otherwise
      • isSeparator

        public boolean isSeparator()
        Description copied from interface: VersionIterator
        Determine if the current token is some kind of separator (a character or a zero-length alphabetical-to-numeric or numeric-to-alphabetical transition).
        Specified by:
        isSeparator in interface VersionIterator
        Returns:
        true if the token is a separator, false otherwise
      • isEmptySeparator

        public boolean isEmptySeparator()
        Description copied from interface: VersionIterator
        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.
        Specified by:
        isEmptySeparator in interface VersionIterator
        Returns:
        true if the token is an empty separator, false otherwise
      • isNonEmptySeparator

        public boolean isNonEmptySeparator()
        Description copied from interface: VersionIterator
        Determine if the current token is a non-empty separator.
        Specified by:
        isNonEmptySeparator in interface VersionIterator
        Returns:
        true if the token is a non-empty separator, false otherwise
      • isAlphaPart

        public boolean isAlphaPart()
        Description copied from interface: VersionIterator
        Determine if the current token is an alphabetical part.
        Specified by:
        isAlphaPart in interface VersionIterator
        Returns:
        true if the token is an alphabetical part, false otherwise
      • isNumberPart

        public boolean isNumberPart()
        Description copied from interface: VersionIterator
        Determine if the current token is a numeric part.
        Specified by:
        isNumberPart in interface VersionIterator
        Returns:
        true if the token is a numeric part, false otherwise
      • appendPartTo

        public StringBuilder appendPartTo​(StringBuilder target)
        Description copied from interface: VersionIterator
        Append this version part to the given string builder. This is used to produce a canonical representation of an input string.
        Specified by:
        appendPartTo in interface VersionIterator
        Parameters:
        target - the string builder (must not be null)
        Returns:
        the same string builder (not null)
      • hasNext

        public boolean hasNext()
        A basic implementation of VersionIterator.hasNext() which returns true if there are more characters after the current token. Subclasses should generally override this basic behavior but may delegate to this implementation for convenience.
        Specified by:
        hasNext in interface VersionIterator
        Returns:
        true if there are more characters after the current token, false otherwise
      • isSeparatorCodePoint

        protected boolean isSeparatorCodePoint​(int cp)
        Determine whether the given code point is a valid separator according to the current scheme. This basic implementation returns true for '.', '-', '+', and '_'. Subclasses may override this method to recognize a different set of separators.
        Parameters:
        cp - the code point to test
        Returns:
        true if the code point is a separator, or false otherwise
      • numericCodePointValue

        protected int numericCodePointValue​(int cp)
        Determine whether the given code point is a valid numeric code point according to the current scheme, and if so, what the digit's numerical value is. This basic implementation delegates to Character.digit(int, int) with a radix value of 10. Subclasses may override this method to recognize a different set of numeric code points.
        Parameters:
        cp - the code point to test
        Returns:
        the numerical value of the given code point, or -1 if the code point is not a valid numerical digit for this version scheme
      • isAlphaCodePoint

        protected boolean isAlphaCodePoint​(int cp)
        Determine whether the given code point is a valid alpha code point according to the current scheme. This basic implementation returns true for any character whose general category is in the set recognized by Character.isLetter(int). Subclasses may override this method to recognize a different set of alpha code points.
        Parameters:
        cp - the code point to test
        Returns:
        true if the code point is a valid letter, or false otherwise