Class BaseSizeSequence

  • All Implemented Interfaces:
    Serializable

    public class BaseSizeSequence
    extends SizeSequence
    implements Serializable
    Specialized size sequence that can handle mixed row sizes.
    Version:
    $Revision$
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      BaseSizeSequence()
      Creates a new BaseSizeSequence object that contains no entries.
      BaseSizeSequence​(int numEntries)
      Creates a new BaseSizeSequence object that contains the specified number of entries, all initialized to have size 0.
      BaseSizeSequence​(int[] sizes)
      Creates a new BaseSizeSequence object that contains the specified sizes.
      BaseSizeSequence​(int numEntries, int value)
      Creates a new BaseSizeSequence object that contains the specified number of entries, all initialized to have size value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getIndex​(int position)
      Returns the index of the entry that corresponds to the specified position.
      int getPosition​(int index)
      Returns the start position for the specified entry.
      int getSize​(int index)
      Returns the size of the specified entry.
      int[] getSizes()
      Returns the size of all entries.
      void insertEntries​(int start, int length, int value)
      Adds a contiguous group of entries to this BaseSizeSequence.
      void removeEntries​(int start, int length)
      Removes a contiguous group of entries from this BaseSizeSequence.
      void setSize​(int index, int size)
      Sets the size of the specified entry.
      void setSizes​(int[] sizes)
      Resets this BaseSizeSequence object, using the data in the sizes argument.
      protected void updatePositions​(int start)
      Updates the positions based on the current sizes.
    • Constructor Detail

      • BaseSizeSequence

        public BaseSizeSequence()
        Creates a new BaseSizeSequence object that contains no entries. To add entries, you can use insertEntries or setSizes.
      • BaseSizeSequence

        public BaseSizeSequence​(int numEntries)
        Creates a new BaseSizeSequence object that contains the specified number of entries, all initialized to have size 0.
        Parameters:
        numEntries - the number of sizes to track
        Throws:
        NegativeArraySizeException - if numEntries < 0
      • BaseSizeSequence

        public BaseSizeSequence​(int numEntries,
                                int value)
        Creates a new BaseSizeSequence object that contains the specified number of entries, all initialized to have size value.
        Parameters:
        numEntries - the number of sizes to track
        value - the initial value of each size
      • BaseSizeSequence

        public BaseSizeSequence​(int[] sizes)
        Creates a new BaseSizeSequence object that contains the specified sizes.
        Parameters:
        sizes - the array of sizes to be contained in the BaseSizeSequence
    • Method Detail

      • setSizes

        public void setSizes​(int[] sizes)
        Resets this BaseSizeSequence object, using the data in the sizes argument. This method reinitializes this object so that it contains as many entries as the sizes array. Each entry's size is initialized to the value of the corresponding item in sizes.
        Overrides:
        setSizes in class SizeSequence
        Parameters:
        sizes - the array of sizes to be contained in this BaseSizeSequence
      • getSizes

        public int[] getSizes()
        Returns the size of all entries.
        Overrides:
        getSizes in class SizeSequence
        Returns:
        a new array containing the sizes in this object
      • getPosition

        public int getPosition​(int index)
        Returns the start position for the specified entry. For example, getPosition(0) returns 0, getPosition(1) is equal to getSize(0), getPosition(2) is equal to getSize(0) + getSize(1), and so on.

        Note that if index is greater than length the value returned may be meaningless.

        Overrides:
        getPosition in class SizeSequence
        Parameters:
        index - the index of the entry whose position is desired
        Returns:
        the starting position of the specified entry
      • getIndex

        public int getIndex​(int position)
        Returns the index of the entry that corresponds to the specified position. For example, getIndex(0) is 0, since the first entry always starts at position 0.
        Overrides:
        getIndex in class SizeSequence
        Parameters:
        position - the position of the entry
        Returns:
        the index of the entry that occupies the specified position
      • getSize

        public int getSize​(int index)
        Returns the size of the specified entry. If index is out of the range (0 <= index < getSizes().length) the behavior is unspecified.
        Overrides:
        getSize in class SizeSequence
        Parameters:
        index - the index corresponding to the entry
        Returns:
        the size of the entry, -1 if outside boundaries
      • setSize

        public void setSize​(int index,
                            int size)
        Sets the size of the specified entry. Note that if the value of index does not fall in the range: (0 <= index < getSizes().length) the behavior is unspecified.
        Overrides:
        setSize in class SizeSequence
        Parameters:
        index - the index corresponding to the entry
        size - the size of the entry
      • insertEntries

        public void insertEntries​(int start,
                                  int length,
                                  int value)
        Adds a contiguous group of entries to this BaseSizeSequence. Note that the values of start and length must satisfy the following conditions: (0 <= start < getSizes().length) AND (length >= 0). If these conditions are not met, the behavior is unspecified and an exception may be thrown.
        Overrides:
        insertEntries in class SizeSequence
        Parameters:
        start - the index to be assigned to the first entry in the group
        length - the number of entries in the group
        value - the size to be assigned to each new entry
        Throws:
        ArrayIndexOutOfBoundsException - if the parameters are outside of the range: (0 <= start < (getSizes().length)) AND (length >= 0)
      • removeEntries

        public void removeEntries​(int start,
                                  int length)
        Removes a contiguous group of entries from this BaseSizeSequence. Note that the values of start and length must satisfy the following conditions: (0 <= start < getSizes().length) AND (length >= 0). If these conditions are not met, the behavior is unspecified and an exception may be thrown.
        Overrides:
        removeEntries in class SizeSequence
        Parameters:
        start - the index of the first entry to be removed
        length - the number of entries to be removed
      • updatePositions

        protected void updatePositions​(int start)
        Updates the positions based on the current sizes.
        Parameters:
        start - the starting index