Class RepeatedVector
- All Implemented Interfaces:
Serializable
,Iterable<Number>
,Collection<Number>
,List<Number>
,RandomAccess
,SequencedCollection<Number>
Vector.compress(double)
.
The intent is to handle the cases found in netCDF files where localization grids
(e.g. the "longitude"
variable storing longitude values of all points in a grid)
contains a lot of repetitions.
cycleLength
is usually the length of the base vector, but not necessarily.
If occurrences
= 1 and cycleLength
= 4 for example, then this class handles repetitions like below:
occurrences
> 1, then this class handles repetitions in a different way
(in this example, cycleLength
is still 4):
- Since:
- 1.0
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Vector
The vector on which this vector is derived from.private final int
Length of the sequence of values to repeat, after conversion to base vector indices.private final int
Number of times that each base element appears in a row before to move to the nextbase
element.private static final long
For cross-version compatibility.private final int
The size of this vector.Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsConstructorDescriptionRepeatedVector
(Vector base, int[] repetitions, double tolerance) Creates a vector of repeated data from the result of a call toVector.repetitions(int...)
.RepeatedVector
(Vector base, int occurrences, int cycleLength, int size) Creates a new vector of repeated data. -
Method Summary
Modifier and TypeMethodDescription(package private) final Vector
InformsVector.pick(int...)
that this vector is backed by another vector.final byte
byteValue
(int i) Returns the value at the given index as abyte
.compress
(double tolerance) Returnsthis
since this vector is considered already compressed.(package private) Vector
createSubSampling
(int first, int step, int length) Implementation ofVector.subSampling(int,int,int)
.final double
doubleValue
(int i) Returns the value at the given index as adouble
.final float
floatValue
(int i) Returns the value at the given index as afloat
.final Number
get
(int i) Returns the number at the given index, ornull
if none.Returns the type of values, which is inherited from the base vector.final Number
increment
(double tolerance) Returnsnull
since the repetition of a sequence of numbers implies that there is no regular increment.final int
intValue
(int i) Returns the value at the given index as anint
.final boolean
Forwards to the base vector.final boolean
Returnstrue
if this vector contains only integer values.final boolean
isNaN
(int i) Returnstrue
if the value at the given index isnull
orNaN
.final boolean
Returnstrue
if values in this vector can be casted to single-precision floating point numbers (float
) without precision lost.final boolean
Returnstrue
if integer values shall be interpreted as unsigned values.final long
longValue
(int i) Returns the value at the given index as along
.final NumberRange
<?> range()
The range of values in this vector is the range of values in the base vector if we use all its data.(package private) final NumberRange
<?> range
(IntSupplier indices, int count) Overridden for efficiency in casebase
itself overrides that method.repeat
(boolean eachValue, int count) Returns a vector whose value is the content of this vector repeated count times.int[]
repetitions
(int... candidates) Returns the parameters used by thisRepeatedVector
instance on the assumption that they are the result of a previous invocation toVector.repetitions(int...)
.final Number
Do not allow setting values.final short
shortValue
(int i) Returns the value at the given index as ashort
.final int
size()
Returns the number of elements in this vector.final String
stringValue
(int i) Returns a string representation of the value at the given index.(package private) final int[]
toBacking
(int[] indices) Converts an array of indexes used by this vector to the indexes used by the backing vector.private int
toBase
(int index) Converts the given index from this vector domain to an index in the base vector.Methods inherited from class org.apache.sis.math.Vector
buffer, concatenate, copy, create, create, createConcatenate, createForDecimal, createSequence, createSequence, createTransform, doubleValues, equals, equals, fill, floatValues, hashCode, indexOf, pick, reverse, subList, subSampling, subtract, toString, transform, warning
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
base
The vector on which this vector is derived from. -
occurrences
private final int occurrencesNumber of times that each base element appears in a row before to move to the nextbase
element. See class javadoc for more information. -
cycleLength
private final int cycleLengthLength of the sequence of values to repeat, after conversion to base vector indices. Usually equals to the length of the base vector but can also be smaller. Shall not be greater thanbase.size()
. See class javadoc for more information. -
size
private final int sizeThe size of this vector. This is oftencycleLength
×occurrences
, but not necessarily.
-
-
Constructor Details
-
RepeatedVector
RepeatedVector(Vector base, int occurrences, int cycleLength, int size) Creates a new vector of repeated data.- Parameters:
base
- the vector on which this vector is derived from.occurrences
- number of time that each element is repeated.cycleLength
- length of the sequence of values to repeat.size
- this vector size, usuallybase.size() * repetition
.
-
RepeatedVector
RepeatedVector(Vector base, int[] repetitions, double tolerance) Creates a vector of repeated data from the result of a call toVector.repetitions(int...)
.- Parameters:
base
- the vector on which this vector is derived from.repetitions
- results ofVector.repetitions(int...)
. Must be non-empty.tolerance
- tolerance factor for compression of the base vector.
-
-
Method Details
-
toBase
private int toBase(int index) Converts the given index from this vector domain to an index in the base vector. -
getElementType
Returns the type of values, which is inherited from the base vector.- Specified by:
getElementType
in classVector
- Returns:
- the type of elements in this vector.
- See Also:
-
isEmptyOrNaN
public final boolean isEmptyOrNaN()Forwards to the base vector.- Overrides:
isEmptyOrNaN
in classVector
- Returns:
- whether this vector is empty or contains only
NaN
values.
-
isSinglePrecision
public final boolean isSinglePrecision()Description copied from class:Vector
Returnstrue
if values in this vector can be casted to single-precision floating point numbers (float
) without precision lost. In case of doubt, this method conservatively returnsfalse
.- Overrides:
isSinglePrecision
in classVector
- Returns:
- whether values in this vector can be casted to
float
primitive type. - See Also:
-
isInteger
public final boolean isInteger()Description copied from class:Vector
Returnstrue
if this vector contains only integer values. This method may iterate over all values for performing this verification. -
isUnsigned
public final boolean isUnsigned()Description copied from class:Vector
Returnstrue
if integer values shall be interpreted as unsigned values. This method may returntrue
for data stored inbyte[]
,short[]
,int[]
orlong[]
arrays, but never for data stored infloat[]
anddouble[]
arrays. The default implementation returnsfalse
.Unless otherwise noticed in Javadoc, users do not need to care about this information since
Vector
methods will perform automatically the operations needed for unsigned integers.- Overrides:
isUnsigned
in classVector
- Returns:
true
if the integer values shall be interpreted as unsigned values.
-
size
public final int size()Description copied from class:Vector
Returns the number of elements in this vector. -
isNaN
public final boolean isNaN(int i) Description copied from class:Vector
Returnstrue
if the value at the given index isnull
orNaN
. -
doubleValue
public final double doubleValue(int i) Description copied from class:Vector
Returns the value at the given index as adouble
. This is the safest method since all primitive types supported byVector
are convertible to thedouble
type.- Specified by:
doubleValue
in classVector
- Parameters:
i
- the index in the [0 … size-1] range.- Returns:
- the value at the given index.
- See Also:
-
floatValue
public final float floatValue(int i) Description copied from class:Vector
Returns the value at the given index as afloat
. This method may result in a lost of precision if this vector stores or computes its values with thedouble
type.The default implementation delegates to
Vector.doubleValue(int)
and cast the result tofloat
.- Overrides:
floatValue
in classVector
- Parameters:
i
- the index in the [0 … size-1] range.- Returns:
- the value at the given index.
- See Also:
-
longValue
public final long longValue(int i) Description copied from class:Vector
Returns the value at the given index as along
. If this vector uses floating point values, the value is rounded to the nearest integer.The default implementation delegates to
Vector.doubleValue(int)
and verifies if the result can be rounded to along
with an error not greater than 0.5. Subclasses that store or compute their values with an integer type should override this method. -
intValue
public final int intValue(int i) Description copied from class:Vector
Returns the value at the given index as anint
. If this vector uses floating point values, the value is rounded to the nearest integer.The default implementation delegates to
Vector.longValue(int)
and verifies if the result fits in theint
type. Subclasses that store or compute their values with theint
,short
orbyte
type should override this method. -
shortValue
public final short shortValue(int i) Description copied from class:Vector
Returns the value at the given index as ashort
. If this vector uses floating point values, the value is rounded to the nearest integer.The default implementation delegates to
Vector.longValue(int)
and verifies if the result fits in theshort
type. Subclasses that store or compute their values with theshort
orbyte
type should override this method.- Overrides:
shortValue
in classVector
- Parameters:
i
- the index in the [0 … size-1] range.- Returns:
- the value at the given index.
-
byteValue
public final byte byteValue(int i) Description copied from class:Vector
Returns the value at the given index as abyte
. If this vector uses floating point values, the value is rounded to the nearest integer.The default implementation delegates to
Vector.longValue(int)
and verifies if the result fits in thebyte
type. Subclasses that store or compute their values with thebyte
type should override this method. -
stringValue
Description copied from class:Vector
Returns a string representation of the value at the given index. Invoking this method is generally equivalent to invokingString.valueOf(get(index))
except if the values are unsigned integers.- Specified by:
stringValue
in classVector
- Parameters:
i
- the index in the [0 … size-1] range.- Returns:
- a string representation of the value at the given index (may be
null
). - See Also:
-
get
Description copied from class:Vector
Returns the number at the given index, ornull
if none. The object returned by this method is usually an instance of the class returned byVector.getElementType()
, but may also be an instance of a wider type if this is necessary for representing the values.Example: ifThe class of returned objects should be stable. For example, this method should not use different types for different range of values. This stability is recommended but not guaranteed becauseVector.getElementType()
returnsByte.class
butVector.isUnsigned()
returnstrue
, then this method will rather return instances ofShort
because that type is the smallest Java primitive type capable to hold byte values in the [0 … 255] range. But the elements are still stored internally asbyte
, and the vector cannot accept values outside the [0 … 255] range even if they are validShort
values.Vector
can also wrap arbitraryNumber[]
arrays. -
range
The range of values in this vector is the range of values in the base vector if we use all its data. -
range
Overridden for efficiency in casebase
itself overrides that method. Overriding that method is optional; the default implementation would have worked. -
set
Do not allow setting values. -
repetitions
public int[] repetitions(int... candidates) Returns the parameters used by thisRepeatedVector
instance on the assumption that they are the result of a previous invocation toVector.repetitions(int...)
.- Overrides:
repetitions
in classVector
- Parameters:
candidates
- probable values, ornull
or an empty array if unknown. If non-empty, those values will be used for narrowing the search, which may improve performances. There is no guarantee that the values returned by this method will be among the given candidates.- Returns:
- the number of times that entities (numbers, or group of numbers) appears consecutively with identical values. If no such repetition is found, an empty array.
- See Also:
-
repeat
Returns a vector whose value is the content of this vector repeated count times. -
increment
Returnsnull
since the repetition of a sequence of numbers implies that there is no regular increment. An exception to this rule would be if the base vector contains a constant value or if the repetition is exactly 1, but we should not have created aRepeatedVector
in such cases. -
compress
Returnsthis
since this vector is considered already compressed. Actually it may be possible to compress more if the base vector has been modified afterRepeatedVector
construction. But it should not happen since this vector is read-only andVector.compress(double)
recommends to not keep reference to the original vector. -
backingVector
InformsVector.pick(int...)
that this vector is backed by another vector.- Overrides:
backingVector
in classVector
-
toBacking
final int[] toBacking(int[] indices) Converts an array of indexes used by this vector to the indexes used by the backing vector. This method must also check index validity. -
createSubSampling
Implementation ofVector.subSampling(int,int,int)
. Arguments validity has been verified by the caller.- Overrides:
createSubSampling
in classVector
- Parameters:
first
- index of the first value to be included in the returned view.step
- the index increment in this vector between two consecutive values in the returned vector. Can be positive, zero or negative.length
- the length of the vector to be returned. Cannot be greater than the length of this vector, except if thestep
is zero.
-