Package adams.core

Class AbstractDataBackedRange<T>

    • Field Detail

      • m_Data

        protected T m_Data
        the underlying dataset.
      • m_Names

        protected List<String> m_Names
        the names to replace.
    • Constructor Detail

      • AbstractDataBackedRange

        public AbstractDataBackedRange()
        Initializes with no range.
      • AbstractDataBackedRange

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

        public AbstractDataBackedRange​(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()
        For initializing the object.
        Overrides:
        initialize in class Range
      • reset

        protected void reset()
        Resets the object.
        Overrides:
        reset in class Range
      • setData

        public void setData​(T value)
        Sets the data to use for interpreting the names.
        Parameters:
        value - the data to use, can be null
      • getData

        public T getData()
        Returns the underlying data.
        Returns:
        the underlying data, null if none set
      • getIndices

        public HashMap<String,​Integer> getIndices​(T data)
        Returns the indices in use. Uses on a clone of itself as not to keep a reference to the data.
        Parameters:
        data - the data to use for the indices
        Returns:
        the indices
      • getIntIndices

        public int[] getIntIndices​(T data)
        Returns the integer indices. Gets always generated on-the-fly! Uses on a clone of itself as not to keep a reference to the data.
        Parameters:
        data - the data to use for the indices
        Returns:
        the indices, 0-length array if not possible
      • getIntSegments

        public int[][] getIntSegments​(T data)
        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! Uses on a clone of itself as not to keep a reference to the data.
        Parameters:
        data - the data to use for the indices
        Returns:
        the segments
      • isInRange

        public boolean isInRange​(T data,
                                 int index)
        Checks whether the provided 0-based index is within the range. Uses on a clone of itself as not to keep a reference to the data.
        Parameters:
        data - the data to use for the indices
        index - the index to check
        Returns:
        true if in range
      • getNumNames

        protected abstract int getNumNames​(T data)
        Returns the number of names the data has.
        Parameters:
        data - the data to retrieve the number of names
      • getName

        protected abstract String getName​(T data,
                                          int colIndex)
        Returns the name at the specified index.
        Parameters:
        data - the data to use
        colIndex - the name index
        Returns:
        the name
      • initLookUp

        protected void initLookUp()
        Initializes the lookup tables.
      • getNames

        protected List<String> getNames()
        Returns the names.
        Returns:
        the names
      • getIndices

        public HashMap<String,​Integer> getIndices()
        Returns the indices in use.
        Returns:
        the indices
      • isName

        protected boolean isName​(String s)
        Checks whether the strings represents a name.
        Parameters:
        s - the string to process
        Returns:
        true if string is a name
      • canReplaceInvalidChars

        protected boolean canReplaceInvalidChars()
        Returns whether invalid characters should get removed.
        Overrides:
        canReplaceInvalidChars in class Range
        Returns:
        true if to replace invalid chars
      • splitRange

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

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

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

        public static String escapeName​(String col)
        Escapes the name, if necessary.
        Parameters:
        col - the name to (potentially) escape
        Returns:
        the processed name
      • unescapeName

        public static String unescapeName​(String col)
        Unescapes the name, if necessary.
        Parameters:
        col - the name to (potentially) unescape
        Returns:
        the processed name