NASA World Wind

gov.nasa.worldwind.util
Class CompoundVecBuffer

java.lang.Object
  extended by gov.nasa.worldwind.util.CompoundVecBuffer
Direct Known Subclasses:
CompoundVecBuffer.EmptyCompoundVecBuffer, VecBufferBlocks, VecBufferSequence

public abstract class CompoundVecBuffer
extends 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:


Nested Class Summary
protected  class CompoundVecBuffer.CompoundIterator<T>
           
protected  class CompoundVecBuffer.CoordIterable
           
protected static class CompoundVecBuffer.EmptyCompoundVecBuffer
           
protected  class CompoundVecBuffer.LocationIterable
           
protected  class CompoundVecBuffer.PositionIterable
           
protected  class CompoundVecBuffer.ReverseCompoundIterator<T>
           
protected static interface CompoundVecBuffer.SubBufferIterable<T>
           
protected  class CompoundVecBuffer.VectorIterable
           
 
Field Summary
protected static boolean ALLOCATE_DIRECT_BUFFERS
           
protected  int capacity
           
protected  int count
           
protected static int DEFAULT_INITIAL_CAPACITY
           
protected  IntBuffer lengths
           
protected  IntBuffer offsets
           
 
Constructor Summary
  CompoundVecBuffer()
          Constructs a CompoundVecBuffer with the default initial capacity.
protected CompoundVecBuffer(CompoundVecBuffer that, int[] indices, int offset, int length)
           
protected CompoundVecBuffer(CompoundVecBuffer that, int beginIndex, int endIndex)
           
  CompoundVecBuffer(int capacity)
          Constructs a CompoundVecBuffer with the specified initial capacity.
 
Method Summary
protected  int addSubBuffer(int offset, int length)
           
 void clear()
          Sets the number sub-buffers to zero.
protected abstract  CompoundVecBuffer createSlice(int[] indices, int offset, int length)
           
protected abstract  CompoundVecBuffer createSlice(int beginIndex, int endIndex)
           
protected abstract  VecBuffer createSubBuffer(int offset, int length)
           
static CompoundVecBuffer emptyCompoundVecBuffer(int coordsPerVec)
          Returns an empty CompoundVecBuffer.
protected  void expandCapacity(int minCapacity)
           
 Iterable<double[]> getCoords()
          Returns an iterator over this buffer's logical vectors, as double[] coordinate arrays.
 Iterable<double[]> getCoords(int minCoordsPerVec)
          Returns an iterator over this buffer's logical vectors, as double[] coordinate arrays.
abstract  int getCoordsPerVec()
          Returns the number of coordinates per logical vector element.
 Iterable<? extends LatLon> getLocations()
          Returns an iterator over this buffer's logical vectors, as LatLon locations.
 Iterable<? extends Position> getPositions()
          Returns an iterator over this buffer's logical vectors, as geographic Positions.
 Iterable<double[]> getReverseCoords(int minCoordsPerVec)
          Returns a reverse iterator over this buffer's logical vectors, as double[] coordinate arrays.
 Iterable<? extends LatLon> getReverseLocations()
          Returns a reverse iterator over this buffer's logical vectors, as LatLon locations.
 Iterable<? extends Position> getReversePositions()
          Returns a reverse iterator over this buffer's logical vectors, as geographic Positions.
 Iterable<? extends Vec4> getReverseVectors()
          Returns a reverse iterator over this buffer's logical vectors, as Vec4 references.
 Iterable<? extends Vec4> getVectors()
          Returns an iterator over this buffer's logical vectors, as Vec4 references.
 int size()
          Returns the number of VecBuffers stored in this CompoundVecBuffer.
 CompoundVecBuffer slice(int[] indices)
          Returns a new logical view of this CompoundVecBuffer.
 CompoundVecBuffer slice(int[] indices, int offset, int length)
          Returns a new logical view of this CompoundVecBuffer.
 CompoundVecBuffer slice(int beginIndex, int endIndex)
          Returns a new logical view of this CompoundVecBuffer.
 VecBuffer subBuffer(int index)
          Returns the sub-buffer at the specified index as a VecBuffer.
abstract  int subBufferSize(int index)
          Returns the size in logical vectors of the VecBuffer with the specified index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALLOCATE_DIRECT_BUFFERS

protected static final boolean ALLOCATE_DIRECT_BUFFERS
See Also:
Constant Field Values

capacity

protected int capacity

count

protected int count

DEFAULT_INITIAL_CAPACITY

protected static final int DEFAULT_INITIAL_CAPACITY
See Also:
Constant Field Values

lengths

protected IntBuffer lengths

offsets

protected IntBuffer offsets
Constructor Detail

CompoundVecBuffer

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


CompoundVecBuffer

protected CompoundVecBuffer(CompoundVecBuffer that,
                            int[] indices,
                            int offset,
                            int length)

CompoundVecBuffer

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

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:
IllegalArgumentException - if the capacity is less than 1.
Method Detail

addSubBuffer

protected int addSubBuffer(int offset,
                           int length)

clear

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


createSlice

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

createSlice

protected abstract CompoundVecBuffer createSlice(int beginIndex,
                                                 int endIndex)

createSubBuffer

protected abstract VecBuffer createSubBuffer(int offset,
                                             int length)

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.

expandCapacity

protected void expandCapacity(int minCapacity)

getCoords

public 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 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.

getCoordsPerVec

public abstract int getCoordsPerVec()
Returns the number of coordinates per logical vector element.

Returns:
the cardinality of a logical vector element.

getLocations

public 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.

getPositions

public 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.

getReverseCoords

public 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.

getReverseLocations

public 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.

getReversePositions

public 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.

getReverseVectors

public 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.

getVectors

public 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.

size

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

Returns:
the number of VecBuffers in this CompoundVecBuffer.

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:
IllegalArgumentException - if the array of indices is null, or if any of the indices is out of range.

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:
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 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:
IllegalArgumentException - if beginIndex is out of range, if endIndex is out of range, or if beginIndex > endIndex.

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:
IllegalArgumentException - if the index is out of range.

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:
IllegalArgumentException - if the index is out of range.

NASA World Wind