Package adams.core

Class Range

    • Constructor Detail

      • Range

        public Range()
        Initializes with no range.
      • Range

        public Range​(String range)
        Initializes with the given range, but no maximum.
        Parameters:
        range - the range to use
      • Range

        public Range​(String range,
                     int max)
        Initializes with the given range and maximum.
        Parameters:
        range - the range to use
        max - the maximum of the 1-based index (e.g., use "10" to allow "1-10" or -1 for uninitialized)
    • Method Detail

      • initialize

        protected void initialize()
        Initializes the object.
      • reset

        protected void reset()
        Resets the object.
      • setRange

        public void setRange​(String value)
        Sets the range.
        Parameters:
        value - the range to use
      • setIndices

        public void setIndices​(Integer[] indices)
        Sets the selected indices. Generates a range string out of the array.
        Parameters:
        indices - the indices (0-based)
      • setIndices

        public void setIndices​(int[] indices)
        Sets the selected indices. Generates a range string out of the array.
        Parameters:
        indices - the indices (0-based)
      • isInverted

        public boolean isInverted()
        Checks whether the range is inverted.
        Returns:
        true if inverted
      • setInverted

        public void setInverted​(boolean value)
        Sets whether the range is inverted or not.
        Parameters:
        value - if true then the range is inverted
      • getRange

        public String getRange()
        Returns the currently set range.
        Returns:
        the range in use
      • getActualRange

        protected String getActualRange()
        Returns the actual range, without inversion.
        Returns:
        the actual range
      • setMax

        public void setMax​(int value)
        Sets the maximum (1-max will be allowed).
        Parameters:
        value - the maximum for the 1-based index
      • getMax

        public int getMax()
        Returns the maximum.
        Returns:
        the maximum for the 1-based index
      • hasRange

        public boolean hasRange()
        Checks whether a valid range has been supplied.
        Returns:
        true if a valid range is available
      • canReplaceInvalidChars

        protected boolean canReplaceInvalidChars()
        Returns whether invalid characters should get removed.

        Default implementation always returns true.
        Returns:
        true if to replace invalid chars
      • splitList

        protected String[] splitList​(String s)
        Attempts to split a list into the parts resembling it.
        Parameters:
        s - the string to split
        Returns:
        the parts (single array element if no list)
      • splitRange

        protected String[] splitRange​(String s)
        Attempts to split a range into the parts resembling it.
        Parameters:
        s - the string to split
        Returns:
        the parts (single array element if no range)
      • clean

        protected String clean​(String s)
        Cleanses the given string.
        Parameters:
        s - the string to clean
        Returns:
        the cleansed string, "" if invalid one provided
      • isPlaceholder

        protected boolean isPlaceholder​(String s)
        Checks whether the string represents a placeholder.
        Parameters:
        s - the string to check
        Returns:
        true if a placeholder
      • parsePlaceholder

        protected int parsePlaceholder​(String s,
                                       int max)
        Parses the placeholder.
        Parameters:
        s - the placeholder to parse
        max - the max to use
        Returns:
        the placeholder's integer equivalent, -1 if not a placeholder
      • parse

        protected int parse​(String s,
                            int max)
        Parses the 1-based index, 'first' and 'last' are accepted as well.
        Parameters:
        s - the string to parse
        max - the maximum value to use
        Returns:
        the 0-based index
      • parse

        protected int parse​(String s)
        Parses the 1-based index, 'first' and 'last' are accepted as well.
        Parameters:
        s - the string to parse
        Returns:
        the 0-based index
      • parse

        protected List<Range.SubRange> parse​(StringBuilder errors)
        Parses the string and generates the sub-ranges.
        Parameters:
        errors - for adding errors to it
        Returns:
        the parsed sub-ranges
      • getSubRanges

        protected List<Range.SubRange> getSubRanges()
        Returns the sub-ranges, initializes them if necessary. NB: Does not check for inverted flag!
        Returns:
        the sub-ranges
      • isInRange

        public boolean isInRange​(int index)
        Checks whether the provided 0-based index is within the range.
        Parameters:
        index - the index to check
        Returns:
        true if in range
      • getIntIndices

        public int[] getIntIndices()
        Returns the integer indices. Gets always generated on-the-fly!
        Returns:
        the indices, 0-length array if not possible
      • getIntSegments

        public int[][] getIntSegments()
        Turns the range into a list of from-to segements. The indices are 0-based. In case a subrange consists only of a single index, the second one is the same. NB: Does not check for inverted flag!
        Returns:
        the segments
      • isAllRange

        public boolean isAllRange()
        Returns whether the range encompasses all.
        Returns:
        true if ALL
        See Also:
        ALL
      • isEmpty

        public boolean isEmpty()
        Returns whether the range is empty.
        Returns:
        true if empty
      • compareTo

        public int compareTo​(Range o)
        Compares this subrange with the specified subrange for order. Returns a negative integer, zero, or a positive integer as this subrange is less than, equal to, or greater than the specified subrange. Uses the "from" as point of comparison and if those are equal, then the "to" (if available).
        Specified by:
        compareTo in interface Comparable<Range>
        Parameters:
        o - the subrange to be compared.
        Returns:
        a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      • equals

        public boolean equals​(Object obj)
        Indicates whether some other object is "equal to" this one.
        Overrides:
        equals in class Object
        Parameters:
        obj - the reference object with which to compare.
        Returns:
        true if this object is the same as the obj argument; false otherwise.
      • hashCode

        public int hashCode()
        Hashcode so can be used as hashtable key. Returns the hashcode of the range string.
        Overrides:
        hashCode in class Object
        Returns:
        the hashcode
      • toString

        public String toString()
        Returns a string representation of the range.
        Overrides:
        toString in class Object
        Returns:
        the representation
      • toExplicitRange

        public String toExplicitRange()
        Returns the explicit range, i.e., just comma-separated (1-based) indices.
        Returns:
        the string
      • getHelpURL

        public String getHelpURL()
        Returns a URL with additional information.
        Specified by:
        getHelpURL in interface HelpProvider
        Returns:
        the URL, null if not available
      • getHelpDescription

        public String getHelpDescription()
        Returns a long help description, e.g., used in tiptexts.
        Specified by:
        getHelpDescription in interface HelpProvider
        Returns:
        the help text, null if not available
      • getHelpTitle

        public String getHelpTitle()
        Returns a short title for the help, e.g., used for buttons.
        Specified by:
        getHelpTitle in interface HelpProvider
        Returns:
        the short title, null if not available
      • getHelpIcon

        public String getHelpIcon()
        Returns the name of a help icon, e.g., used for buttons.
        Specified by:
        getHelpIcon in interface HelpProvider
        Returns:
        the icon name, null if not available
      • toRange

        public static Range toRange​(int[] indices)
        Turns the integer indices into a range object.
        Parameters:
        indices - the 0-based indices
        Returns:
        the generated range
      • isValid

        public static boolean isValid​(String s,
                                      int max)
        Returns whether the range string is valid.
        Parameters:
        s - the range to check
        max - the maximum
        Returns:
        true if a valid range string