Class CompoundVecBuffer

  • Direct Known Subclasses:
    CompoundVecBuffer.EmptyCompoundVecBuffer, VecBufferBlocks, VecBufferSequence

    public abstract class CompoundVecBuffer
    extends java.lang.Object
    CompoundVecBuffer defines an interface for storing and retrieving a collection of variable length VecBuffer objects. Each VecBuffer is retrieved via an index. The range of valid indices in a CompoundVecBuffer is [0, size() - 1], inclusive. Implementations of CompoundVecBuffer define how each VecBuffer is stored and retrieved according to its index.

    To retrieve a single VecBuffer given an index, invoke subBuffer(int). To retrieve a VecBuffer's size, in number of logical tuples, invoke subBufferSize(int).

    To create a new view of this CompoundVecBuffer from one or many VecBuffers, invoke one of the slice methods:

    • slice(int, int) creates a view of this CompoundVecbufer given a contiguous sequence of VecBuffer indices.
    • slice(int[], int, int) creates a view of this CompoundVecBuffer given an array of VecBuffer indices.
    • Field Detail

      • DEFAULT_INITIAL_CAPACITY

        protected static final int DEFAULT_INITIAL_CAPACITY
        See Also:
        Constant Field Values
      • ALLOCATE_DIRECT_BUFFERS

        protected static final boolean ALLOCATE_DIRECT_BUFFERS
        See Also:
        Constant Field Values
      • count

        protected int count
      • capacity

        protected int capacity
      • offsets

        protected java.nio.IntBuffer offsets
      • lengths

        protected java.nio.IntBuffer lengths
    • Constructor Detail

      • CompoundVecBuffer

        public CompoundVecBuffer​(int capacity)
        Constructs a CompoundVecBuffer with the specified initial capacity.
        Parameters:
        capacity - the CompoundVecBuffer's initial capacity, in number of sub-buffers.
        Throws:
        java.lang.IllegalArgumentException - if the capacity is less than 1.
      • CompoundVecBuffer

        public CompoundVecBuffer()
        Constructs a CompoundVecBuffer with the default initial capacity.
      • CompoundVecBuffer

        protected CompoundVecBuffer​(CompoundVecBuffer that,
                                    int beginIndex,
                                    int endIndex)
      • CompoundVecBuffer

        protected CompoundVecBuffer​(CompoundVecBuffer that,
                                    int[] indices,
                                    int offset,
                                    int length)
    • Method Detail

      • emptyCompoundVecBuffer

        public static CompoundVecBuffer emptyCompoundVecBuffer​(int coordsPerVec)
        Returns an empty CompoundVecBuffer. The returned CompoundVecBuffer has a size of zero and contains no sub-buffers.
        Parameters:
        coordsPerVec - the number of coordinates per logical vector.
        Returns:
        the empty CompoundVecBuffer.
      • size

        public int size()
        Returns the number of VecBuffers stored in this CompoundVecBuffer.
        Returns:
        the number of VecBuffers in this CompoundVecBuffer.
      • subBufferSize

        public abstract int subBufferSize​(int index)
        Returns the size in logical vectors of the VecBuffer with the specified index.
        Parameters:
        index - the index for the VecBuffer who's size is returned.
        Returns:
        the size of the specified VecBuffer.
        Throws:
        java.lang.IllegalArgumentException - if the index is out of range.
      • subBuffer

        public VecBuffer subBuffer​(int index)
        Returns the sub-buffer at the specified index as a VecBuffer.
        Parameters:
        index - the index of the VecBuffer to return.
        Returns:
        the VecBuffer at the specified index.
        Throws:
        java.lang.IllegalArgumentException - if the index is out of range.
      • slice

        public CompoundVecBuffer slice​(int beginIndex,
                                       int endIndex)
        Returns a new logical view of this CompoundVecBuffer. The returned buffer has length endIndex - beginIndex + 1 and references this buffer's contents starting at beginIndex, and ending at endIndex. The returned buffer shares this buffers's backing data. Changes to this buffer are reflected in the returned buffer, and vice versa.
        Parameters:
        beginIndex - the index of the first sub-buffer to include in the subset.
        endIndex - the index of the last sub-buffer to include in the subset.
        Returns:
        a new CompoundVecBuffer representing a subset of this CompoundVecBuffer.
        Throws:
        java.lang.IllegalArgumentException - if beginIndex is out of range, if endIndex is out of range, or if beginIndex > endIndex.
      • slice

        public CompoundVecBuffer slice​(int[] indices,
                                       int offset,
                                       int length)
        Returns a new logical view of this CompoundVecBuffer. The returned buffer's length is equal to the specified length, and contains this buffer's contents for each index in indices. The returned buffer shares this buffers's backing data. Changes to this buffer are reflected in the returned buffer, and vice versa.
        Parameters:
        indices - an array containing the indices include in the subset.
        offset - the array starting index.
        length - the number of array values to use.
        Returns:
        a new CompoundVecBuffer representing a subset of this CompoundVecBuffer.
        Throws:
        java.lang.IllegalArgumentException - if the array of indices is null, if the offset or length are invalid, or if any of the indices is out of range.
      • slice

        public CompoundVecBuffer slice​(int[] indices)
        Returns a new logical view of this CompoundVecBuffer. The returned buffer's length is equal to the length of indices, and contains this buffer's contents for each index in indices. The returned buffer shares this buffers's backing data. Changes to this buffer are reflected in the returned buffer, and vice versa.
        Parameters:
        indices - an array containing the indices include in the subset.
        Returns:
        a new CompoundVecBuffer representing a subset of this CompoundVecBuffer.
        Throws:
        java.lang.IllegalArgumentException - if the array of indices is null, or if any of the indices is out of range.
      • clear

        public void clear()
        Sets the number sub-buffers to zero. This does not free any memory associated with this CompoundVecBuffer.
      • getCoordsPerVec

        public abstract int getCoordsPerVec()
        Returns the number of coordinates per logical vector element.
        Returns:
        the cardinality of a logical vector element.
      • createSubBuffer

        protected abstract VecBuffer createSubBuffer​(int offset,
                                                     int length)
      • createSlice

        protected abstract CompoundVecBuffer createSlice​(int[] indices,
                                                         int offset,
                                                         int length)
      • createSlice

        protected abstract CompoundVecBuffer createSlice​(int beginIndex,
                                                         int endIndex)
      • addSubBuffer

        protected int addSubBuffer​(int offset,
                                   int length)
      • expandCapacity

        protected void expandCapacity​(int minCapacity)
      • getCoords

        public java.lang.Iterable<double[]> getCoords()
        Returns an iterator over this buffer's logical vectors, as double[] coordinate arrays. The array returned from each call to Iterator.next() will be newly allocated, and will have length equal to coordsPerVec.
        Returns:
        iterator over this buffer's vectors, as double[] arrays.
      • getCoords

        public java.lang.Iterable<double[]> getCoords​(int minCoordsPerVec)
        Returns an iterator over this buffer's logical vectors, as double[] coordinate arrays. The array returned from a call to Iterator.next() will be newly allocated, and will have length equal to coordsPerVec or minCoordsPerVec, whichever is larger. If minCoordsPerVec is larger than coordsPerVec, then the elements in the returned array will after index "coordsPerVec - 1" will be undefined.
        Parameters:
        minCoordsPerVec - the minimum number of coordinates returned in each double[] array.
        Returns:
        iterator over this buffer's vectors, as double[] arrays.
      • getReverseCoords

        public java.lang.Iterable<double[]> getReverseCoords​(int minCoordsPerVec)
        Returns a reverse iterator over this buffer's logical vectors, as double[] coordinate arrays. The array returned from a call to Iterator.next() will be newly allocated, and will have length equal to coordsPerVec or minCoordsPerVec, whichever is larger. If minCoordsPerVec is larger than coordsPerVec, then the elements in the returned array will after index "coordsPerVec - 1" will be undefined.
        Parameters:
        minCoordsPerVec - the minimum number of coordinates returned in each double[] array.
        Returns:
        reverse iterator over this buffer's vectors, as double[] arrays.
      • getVectors

        public java.lang.Iterable<? extends Vec4> getVectors()
        Returns an iterator over this buffer's logical vectors, as Vec4 references.
        Returns:
        iterator over this buffer's vectors, as Vec4 references.
      • getReverseVectors

        public java.lang.Iterable<? extends Vec4> getReverseVectors()
        Returns a reverse iterator over this buffer's logical vectors, as Vec4 references.
        Returns:
        reverse iterator over this buffer's vectors, as Vec4 references.
      • getLocations

        public java.lang.Iterable<? extends LatLon> getLocations()
        Returns an iterator over this buffer's logical vectors, as LatLon locations.
        Returns:
        iterator over this buffer's vectors, as LatLon locations.
      • getReverseLocations

        public java.lang.Iterable<? extends LatLon> getReverseLocations()
        Returns a reverse iterator over this buffer's logical vectors, as LatLon locations.
        Returns:
        reverse iterator over this buffer's vectors, as LatLon locations.
      • getPositions

        public java.lang.Iterable<? extends Position> getPositions()
        Returns an iterator over this buffer's logical vectors, as geographic Positions.
        Returns:
        iterator over this buffer's vectors, as geographic Positions.
      • getReversePositions

        public java.lang.Iterable<? extends Position> getReversePositions()
        Returns a reverse iterator over this buffer's logical vectors, as geographic Positions.
        Returns:
        reverse iterator over this buffer's vectors, as geographic Positions.