Package org.apache.sis.math
Class LinearlyDerivedVector
- All Implemented Interfaces:
Serializable,Iterable<Number>,Collection<Number>,List<Number>,RandomAccess
A vector derived from another vector by application of a scale factor and an offset.
This is used for example when data in a netCDF file are packed as integer values.
Several methods in this implementation requires a bijective relationship between this and base.
This is mostly the case if coefficients are finite and scale is non-zero, as asserted at construction time.
- Since:
- 1.0
- Version:
- 1.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final VectorThe vector on which this vector is derived from.private final doubleThe offset to apply after the scale factor.private final doubleThe scale factor to apply.private static final longFor cross-version compatibility.Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionLinearlyDerivedVector(Vector base, double scale, double offset) Creates a new vector of derived data. -
Method Summary
Modifier and TypeMethodDescriptionprivate NumberApplies the linear relationship on the given value.private NumberRange<?>convert(NumberRange<?> range) Converts the given range.(package private) final VectorcreateConcatenate(Vector toAppend) Returns the concatenation of this vector with the given one.(package private) final VectorcreateTransform(double s, double t) Concatenates the given transformation with the current transform.doubledoubleValue(int index) Returns the value at the given index as adouble.double[]Copies all values in an array of double precision floating point numbers.(package private) booleanOptimization ofequalsmethod for the case where the other object is anotherLinearlyDerivedVectorusing the same linear relationship.booleanOptimization ofequalsmethod for the case where the other object is anotherLinearlyDerivedVectorusing the same linear relationship.voidSets a range of elements to the given number.get(int index) Returns the number at the given index as aDouble.Returns the type of values resulting from the linear conversion applied by this vector.increment(double tolerance) Returns the increment between all consecutive values if this increment is constant, ornullotherwise.(package private) final intindexOf(int toSearch, int index, boolean equality) Returns the index of a search based one values at given indices (see javadoc in parent class for details).private NumberApplies the inverse linear function on the given value.booleanReturnstrueif this vector is empty or contains onlyNaNvalues.booleanReturnstrueif this vector contains only integer values.booleanisNaN(int index) Returnstrueif the value at the given index isnullorNaN.booleanDouble-precision values are not guaranteed to be convertible to single-precision floating point type.pick(int... indices) Returns a view which contains the values of this vector at the given indexes.NumberRange<?>range()Returns the minimal and maximal values found in this vector.(package private) final NumberRange<?>range(IntSupplier indices, int n) Computes the range of values at the indices provided by the given supplier.int[]repetitions(int... candidates) Detects repetition patterns in the values contained in this vector.Sets the number at the given index.intsize()Returns the number of elements in this vector.stringValue(int index) Returns a string representation of the value at the given index.subSampling(int first, int step, int length) Returns a view which contain the values of this vector in a given index range.Methods inherited from class org.apache.sis.math.Vector
backingVector, buffer, byteValue, compress, concatenate, copy, create, create, createForDecimal, createSequence, createSequence, createSubSampling, floatValue, floatValues, hashCode, intValue, isUnsigned, longValue, repeat, reverse, shortValue, subList, subtract, toBacking, 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. -
scale
private final double scaleThe scale factor to apply. -
offset
private final double offsetThe offset to apply after the scale factor.
-
-
Constructor Details
-
LinearlyDerivedVector
LinearlyDerivedVector(Vector base, double scale, double offset) Creates a new vector of derived data.
-
-
Method Details
-
getElementType
Returns the type of values resulting from the linear conversion applied by this vector. Note that it does not means that this vector can store all values of that type.- Specified by:
getElementTypein classVector- Returns:
- the type of elements in this vector.
- See Also:
-
isSinglePrecision
public boolean isSinglePrecision()Double-precision values are not guaranteed to be convertible to single-precision floating point type.- Overrides:
isSinglePrecisionin classVector- Returns:
- whether values in this vector can be casted to
floatprimitive type. - See Also:
-
isInteger
public boolean isInteger()Returnstrueif this vector contains only integer values. This implementation delegates to the base vector if coefficients are integers, or scans all values otherwise. -
size
public int size()Returns the number of elements in this vector. This is taken directly from the base vector. -
isEmptyOrNaN
public boolean isEmptyOrNaN()Returnstrueif this vector is empty or contains onlyNaNvalues. The implementation delegates to the base vector since linear relationship does not change whether values are NaN.- Overrides:
isEmptyOrNaNin classVector- Returns:
- whether this vector is empty or contains only
NaNvalues.
-
isNaN
public boolean isNaN(int index) Returnstrueif the value at the given index isnullorNaN. The implementation delegates to the base vector since linear relationship does not change whether a value is NaN. -
doubleValue
public double doubleValue(int index) Returns the value at the given index as adouble. This method is invoked by all othersfooValue().- Specified by:
doubleValuein classVector- Parameters:
index- the index in the [0 … size-1] range.- Returns:
- the value at the given index.
- See Also:
-
stringValue
Returns a string representation of the value at the given index. This implementation uses thedoublerepresentation.- Specified by:
stringValuein classVector- Parameters:
index- 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
Returns the number at the given index as aDouble. -
set
Sets the number at the given index. This action is likely to loose precision if the base vector stores values using integer primitive type. -
fill
Sets a range of elements to the given number. This action is likely to loose precision if the base vector stores values using integer primitive type. -
indexOf
final int indexOf(int toSearch, int index, boolean equality) Returns the index of a search based one values at given indices (see javadoc in parent class for details). This implementation forwards to backing vector on the assumption that thethis↔︎baserelationship is bijective.- Overrides:
indexOfin classVector- Parameters:
toSearch- index of the value to search.index- index of the first value where to start the search.equality- whether we search the first equal value, or the first different value.- Returns:
- index of the value found, or the vector size if the value has not been found.
-
repetitions
public int[] repetitions(int... candidates) Detects repetition patterns in the values contained in this vector. This implementation forwards to backing vector on the assumption that thethis↔︎baserelationship is bijective.- 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:
-
increment
Returns the increment between all consecutive values if this increment is constant, ornullotherwise. This implementation converts the value computed by the backing vector on the assumption that thethis↔︎baserelationship is a linear. -
convert
Applies the linear relationship on the given value.- Parameters:
value- the number to convert, ornull.- Returns:
- the converted number (may be
null).
-
inverse
Applies the inverse linear function on the given value.- Parameters:
value- the number to inverse convert, ornull.- Returns:
- the inverse converted number (may be
null).
-
convert
Converts the given range. This is used for delegating range calculation to the base vector on the assumption that is will be more efficient than iterating ourselves on all values.- Parameters:
range- the range to convert, ornull.- Returns:
- the converted range, or
nullif the given range was null.
-
range
Returns the minimal and maximal values found in this vector. This implementation delegates to the base vector (which may provide fast implementation) then convert the result. -
range
Computes the range of values at the indices provided by the given supplier. This implementation delegates to the base vector (which may provide fast implementation) then convert the result. -
subSampling
Returns a view which contain the values of this vector in a given index range. This implementation delegates to base vector and wraps again.- Overrides:
subSamplingin classVector- Parameters:
first- index of the first value in this vector to be included in the returned view.step- the index increment between values in this vector to be included in the returned view. Can be positive, zero or negative.length- the length of the view to be returned. Cannot be greater than the length of this vector, except if thestepis zero.- Returns:
- a view of this vector containing values in the given index range.
-
pick
Returns a view which contains the values of this vector at the given indexes. This implementation delegates to base vector and wraps again. -
createConcatenate
Returns the concatenation of this vector with the given one. This implementation potentially delegate to base vector.- Overrides:
createConcatenatein classVector
-
createTransform
Concatenates the given transformation with the current transform.- Overrides:
createTransformin classVector
-
doubleValues
public double[] doubleValues()Copies all values in an array of double precision floating point numbers. We override this method for efficiency. We do not override thefloatversions for accuracy reasons.- Overrides:
doubleValuesin classVector- Returns:
- a copy of all floating point values in this vector.
- See Also:
-
equals
Optimization ofequalsmethod for the case where the other object is anotherLinearlyDerivedVectorusing the same linear relationship. -
equals
Optimization ofequalsmethod for the case where the other object is anotherLinearlyDerivedVectorusing the same linear relationship.- Overrides:
equalsin classVector- Parameters:
lower- index of the first value to compare in this vector, inclusive.upper- index after the last value to compare in this vector.other- the other vector to compare values with this vector. May bethis.otherOffset- index of the first element to compare in the other vector.- Returns:
- whether values over the specified range of the two vectors are equal.
-