Class RepeatedVector
- All Implemented Interfaces:
Serializable,Iterable<Number>,Collection<Number>,List<Number>,RandomAccess
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 VectorThe vector on which this vector is derived from.private final intLength of the sequence of values to repeat, after conversion to base vector indices.private final intNumber of times that each base element appears in a row before to move to the nextbaseelement.private static final longFor cross-version compatibility.private final intThe 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 VectorInformsVector.pick(int...)that this vector is backed by another vector.final bytebyteValue(int i) Returns the value at the given index as abyte.compress(double tolerance) Returnsthissince this vector is considered already compressed.(package private) VectorcreateSubSampling(int first, int step, int length) Implementation ofVector.subSampling(int,int,int).final doubledoubleValue(int i) Returns the value at the given index as adouble.final floatfloatValue(int i) Returns the value at the given index as afloat.final Numberget(int i) Returns the number at the given index, ornullif none.Returns the type of values, which is inherited from the base vector.final Numberincrement(double tolerance) Returnsnullsince the repetition of a sequence of numbers implies that there is no regular increment.final intintValue(int i) Returns the value at the given index as anint.final booleanForwards to the base vector.final booleanReturnstrueif this vector contains only integer values.final booleanisNaN(int i) Returnstrueif the value at the given index isnullorNaN.final booleanReturnstrueif values in this vector can be casted to single-precision floating point numbers (float) without precision lost.final booleanReturnstrueif integer values shall be interpreted as unsigned values.final longlongValue(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 casebaseitself 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 thisRepeatedVectorinstance on the assumption that they are the result of a previous invocation toVector.repetitions(int...).final NumberDo not allow setting values.final shortshortValue(int i) Returns the value at the given index as ashort.final intsize()Returns the number of elements in this vector.final StringstringValue(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 inttoBase(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, warningMethods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRangeMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, streamMethods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, 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 nextbaseelement. 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:
getElementTypein classVector- Returns:
- the type of elements in this vector.
- See Also:
-
isEmptyOrNaN
public final boolean isEmptyOrNaN()Forwards to the base vector.- Overrides:
isEmptyOrNaNin classVector- Returns:
- whether this vector is empty or contains only
NaNvalues.
-
isSinglePrecision
public final boolean isSinglePrecision()Description copied from class:VectorReturnstrueif 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:
isSinglePrecisionin classVector- Returns:
- whether values in this vector can be casted to
floatprimitive type. - See Also:
-
isInteger
public final boolean isInteger()Description copied from class:VectorReturnstrueif 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:VectorReturnstrueif integer values shall be interpreted as unsigned values. This method may returntruefor 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
Vectormethods will perform automatically the operations needed for unsigned integers.- Overrides:
isUnsignedin classVector- Returns:
trueif the integer values shall be interpreted as unsigned values.
-
size
public final int size()Description copied from class:VectorReturns the number of elements in this vector. -
isNaN
public final boolean isNaN(int i) Description copied from class:VectorReturnstrueif the value at the given index isnullorNaN. -
doubleValue
public final double doubleValue(int i) Description copied from class:VectorReturns the value at the given index as adouble. This is the safest method since all primitive types supported byVectorare convertible to thedoubletype.- Specified by:
doubleValuein 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:VectorReturns 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 thedoubletype.The default implementation delegates to
Vector.doubleValue(int)and cast the result tofloat.- Overrides:
floatValuein 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:VectorReturns 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 alongwith 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:VectorReturns 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 theinttype. Subclasses that store or compute their values with theint,shortorbytetype should override this method. -
shortValue
public final short shortValue(int i) Description copied from class:VectorReturns 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 theshorttype. Subclasses that store or compute their values with theshortorbytetype should override this method.- Overrides:
shortValuein 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:VectorReturns 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 thebytetype. Subclasses that store or compute their values with thebytetype should override this method. -
stringValue
Description copied from class:VectorReturns 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:
stringValuein 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:VectorReturns the number at the given index, ornullif 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.classbutVector.isUnsigned()returnstrue, then this method will rather return instances ofShortbecause 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 validShortvalues.Vectorcan 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 casebaseitself 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 thisRepeatedVectorinstance on the assumption that they are the result of a previous invocation toVector.repetitions(int...).- Overrides:
repetitionsin classVector- Parameters:
candidates- probable values, ornullor 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
Returnsnullsince 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 aRepeatedVectorin such cases. -
compress
Returnsthissince this vector is considered already compressed. Actually it may be possible to compress more if the base vector has been modified afterRepeatedVectorconstruction. 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:
backingVectorin 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:
createSubSamplingin 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 thestepis zero.
-