Package gov.nasa.worldwind.util
Class CompoundVecBuffer
- java.lang.Object
-
- gov.nasa.worldwind.util.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 lengthVecBuffer
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, invokesubBufferSize(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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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
Fields Modifier and Type Field Description protected static boolean
ALLOCATE_DIRECT_BUFFERS
protected int
capacity
protected int
count
protected static int
DEFAULT_INITIAL_CAPACITY
protected java.nio.IntBuffer
lengths
protected java.nio.IntBuffer
offsets
-
Constructor Summary
Constructors Modifier Constructor Description CompoundVecBuffer()
Constructs a CompoundVecBuffer with the default initial capacity.CompoundVecBuffer(int capacity)
Constructs a CompoundVecBuffer with the specified initial capacity.protected
CompoundVecBuffer(CompoundVecBuffer that, int[] indices, int offset, int length)
protected
CompoundVecBuffer(CompoundVecBuffer that, int beginIndex, int endIndex)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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)
java.lang.Iterable<double[]>
getCoords()
Returns an iterator over this buffer's logical vectors, as double[] coordinate arrays.java.lang.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.java.lang.Iterable<? extends LatLon>
getLocations()
Returns an iterator over this buffer's logical vectors, as LatLon locations.java.lang.Iterable<? extends Position>
getPositions()
Returns an iterator over this buffer's logical vectors, as geographic Positions.java.lang.Iterable<double[]>
getReverseCoords(int minCoordsPerVec)
Returns a reverse iterator over this buffer's logical vectors, as double[] coordinate arrays.java.lang.Iterable<? extends LatLon>
getReverseLocations()
Returns a reverse iterator over this buffer's logical vectors, as LatLon locations.java.lang.Iterable<? extends Position>
getReversePositions()
Returns a reverse iterator over this buffer's logical vectors, as geographic Positions.java.lang.Iterable<? extends Vec4>
getReverseVectors()
Returns a reverse iterator over this buffer's logical vectors, as Vec4 references.java.lang.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 aVecBuffer
.abstract int
subBufferSize(int index)
Returns the size in logical vectors of the VecBuffer with the specified index.
-
-
-
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 aVecBuffer
.- 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 lengthendIndex - beginIndex + 1
and references this buffer's contents starting atbeginIndex
, and ending atendIndex
. 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 specifiedlength
, and contains this buffer's contents for each index inindices
. 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 ofindices
, and contains this buffer's contents for each index inindices
. 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.
-
-