Package jahuwaldt.js.param
Class ParameterVector<Q extends javax.measure.quantity.Quantity>
- java.lang.Object
-
- org.jscience.mathematics.vector.Vector<Parameter<Q>>
-
- jahuwaldt.js.param.AbstractParamVector<Q,ParameterVector<Q>>
-
- jahuwaldt.js.param.ParameterVector<Q>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<javax.measure.Measurable<Q>>
,javax.measure.Measurable<Q>
,javolution.lang.Immutable
,javolution.lang.Realtime
,javolution.lang.ValueType
,javolution.xml.XMLSerializable
,GroupAdditive<Vector<Parameter<Q>>>
,Structure<Vector<Parameter<Q>>>
,VectorSpace<Vector<Parameter<Q>>,Parameter<Q>>
,VectorSpaceNormed<Vector<Parameter<Q>>,Parameter<Q>>
public class ParameterVector<Q extends javax.measure.quantity.Quantity> extends AbstractParamVector<Q,ParameterVector<Q>> implements javolution.lang.ValueType, javolution.xml.XMLSerializable
This class represents an n-dimensional
vector
ofParameter
elements sharing the same units.Modified by: Joseph A. Huwaldt
- Version:
- March 1, 2014
- Author:
- Joseph A. Huwaldt Date: March 27, 2009
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends javax.measure.quantity.Quantity>
ParameterVector<T>asType(java.lang.Class<T> type)
Casts this ParameterVector to a parameterized unit of specified nature or throw aClassCastException
if the dimension of the specified quantity and this parameter's unit dimension do not match.ParameterVector<Q>
copy()
Returns a copy of this vectorallocated
by the calling thread (possibly on the stack).ParameterVector
cross(Vector that)
Returns the cross product of two vectors.ParameterVector<?>
divide(Parameter<?> that)
Returns this vector with each element divided by the specified divisor.boolean
equals(java.lang.Object obj)
Compares this ParameterVector against the specified object for strict equality (same values and same units).ParameterVector<Q>
fromVector3D(Vector3D<Q> vector)
Return the specifiedVector3D
object as aParameterVector
instance.Parameter<Q>
get(int i)
Returns the value of a Parameter from this vector.int
getDimension()
Returns the number of elements held by this vector.javax.measure.unit.Unit<Q>
getUnit()
Returns the unit in which thevalues
in this vector are stated in.double
getValue(int i)
Returns the value of the Parameter in this vector as adouble
, stated in this vector'sunit
.int
hashCode()
Returns the hash code for this parameter.static void
main(java.lang.String[] args)
Tests the methods in this class.ParameterVector<Q>
minus(Parameter<Q> that)
Subtracts the supplied Parameter from each element of this vector and returns the result.ParameterVector<Q>
minus(Vector<Parameter<Q>> that)
Returns the difference between this vector and the one specified.double
normValue()
Returns theAbstractParamVector.norm()
, magnitude, or length value of this vector.ParameterVector<Q>
opposite()
Returns the negation of this vector.ParameterVector<Q>
plus(Parameter<Q> that)
Returns the sum of this vector with the parameter specified.ParameterVector<Q>
plus(Vector<Parameter<Q>> that)
Returns the sum of this vector with the one specified.ParameterVector<Q>
times(double k)
Returns the product of this vector with the specified coefficient.ParameterVector
times(Parameter k)
Returns the product of this vector with the specified coefficient.Parameter
times(Vector that)
Returns the dot product of this vector with the one specified.ParameterVector
timesEBE(Vector that)
Returns the element-by-element product of this vector with the one specified.<R extends javax.measure.quantity.Quantity>
ParameterVector<R>to(javax.measure.unit.Unit<R> unit)
Returns the equivalent to this vector but stated in the specified unit.Float64Vector
toFloat64Vector()
Returns the values stored in this vector, stated in this vector'sunit
, as a Float64Vector.ParameterVector<javax.measure.quantity.Dimensionless>
toUnitVector()
Returns this vector converted to a unit vector by dividing all the vector's elements by the length (AbstractParamVector.norm()
) of this vector.Vector3D<Q>
toVector3D()
Returns a Vector3D representation of this vector if possible.static <Q extends javax.measure.quantity.Quantity>
ParameterVector<Q>valueOf(double x, double y, double z, javax.measure.unit.Unit<Q> unit)
Returns aParameterVector
instance holding the specifieddouble
values stated in the specified units.static <Q extends javax.measure.quantity.Quantity>
ParameterVector<Q>valueOf(double x, double y, javax.measure.unit.Unit<Q> unit)
Returns a 2DParameterVector
instance holding the specifieddouble
values stated in the specified units.static <Q extends javax.measure.quantity.Quantity>
ParameterVector<Q>valueOf(Parameter<Q>... values)
Returns aParameterVector
instance holding the specifiedParameter
values.static <Q extends javax.measure.quantity.Quantity>
ParameterVector<Q>valueOf(Parameter<Q> x, Parameter<Q> y, Parameter<Q> z)
Returns aParameterVector
instance holding the specifiedParameter
values.static <Q extends javax.measure.quantity.Quantity>
ParameterVector<Q>valueOf(java.util.List<Parameter<Q>> values)
Returns aParameterVector
instance holding the specifiedParameter
values.static <Q extends javax.measure.quantity.Quantity>
ParameterVector<Q>valueOf(javax.measure.unit.Unit<Q> unit, double... values)
Returns aParameterVector
instance holding the specifieddouble
values stated in the specified units.static <Q extends javax.measure.quantity.Quantity>
ParameterVector<Q>valueOf(Vector<Parameter<Q>> vector)
Returns aParameterVector
instance containing the specified vector of Parameter values with compatible units.static <Q extends javax.measure.quantity.Quantity>
ParameterVector<Q>valueOf(Vector<Float64> vector, javax.measure.unit.Unit<Q> unit)
Returns aParameterVector
instance containing the specified vector of Float64 values stated in the specified units.
-
-
-
Field Detail
-
X
public static final int X
Constant used to identify the X (0) coordinate in the vector.- See Also:
- Constant Field Values
-
Y
public static final int Y
Constant used to identify the Y (1) coordinate in the vector.- See Also:
- Constant Field Values
-
Z
public static final int Z
Constant used to identify the Z (2) coordinate in the vector.- See Also:
- Constant Field Values
-
-
Method Detail
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> ParameterVector<Q> valueOf(double x, double y, javax.measure.unit.Unit<Q> unit)
Returns a 2DParameterVector
instance holding the specifieddouble
values stated in the specified units.- Parameters:
x
- the x value stated in the specified unit.y
- the y value stated in the specified unit.unit
- the unit in which the coordinates are stated.- Returns:
- the vector having the specified values.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> ParameterVector<Q> valueOf(double x, double y, double z, javax.measure.unit.Unit<Q> unit)
Returns aParameterVector
instance holding the specifieddouble
values stated in the specified units.- Parameters:
x
- the x value stated in the specified unit.y
- the y value stated in the specified unit.z
- the z value stated in the specified unit.unit
- the unit in which the coordinates are stated.- Returns:
- the vector having the specified values.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> ParameterVector<Q> valueOf(javax.measure.unit.Unit<Q> unit, double... values)
Returns aParameterVector
instance holding the specifieddouble
values stated in the specified units.- Parameters:
unit
- the unit in which the coordinates are stated.values
- A list of values to store in the vector.- Returns:
- the vector having the specified values.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> ParameterVector<Q> valueOf(Parameter<Q> x, Parameter<Q> y, Parameter<Q> z)
Returns aParameterVector
instance holding the specifiedParameter
values. All the values are converted to the same units as the x value.- Parameters:
x
- the x value.y
- the y value.z
- the z value.- Returns:
- the vector having the specified values in the units of x.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> ParameterVector<Q> valueOf(java.util.List<Parameter<Q>> values)
Returns aParameterVector
instance holding the specifiedParameter
values. All the values are converted to the same units as the first value.- Parameters:
values
- A list of values to store in the vector.- Returns:
- the vector having the specified values in the units of x.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> ParameterVector<Q> valueOf(Parameter<Q>... values)
Returns aParameterVector
instance holding the specifiedParameter
values. All the values are converted to the same units as the first value.- Parameters:
values
- A list of values to store in the vector.- Returns:
- the vector having the specified values in the units of x.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> ParameterVector<Q> valueOf(Vector<Float64> vector, javax.measure.unit.Unit<Q> unit)
Returns aParameterVector
instance containing the specified vector of Float64 values stated in the specified units.- Parameters:
vector
- the vector of Float64 values stated in the specified unit.unit
- the unit in which the coordinates are stated.- Returns:
- the vector having the specified values.
-
valueOf
public static <Q extends javax.measure.quantity.Quantity> ParameterVector<Q> valueOf(Vector<Parameter<Q>> vector)
Returns aParameterVector
instance containing the specified vector of Parameter values with compatible units. All the values are converted to the same units as the 1st value.- Parameters:
vector
- the vector of Parameter values stated in the specified unit.- Returns:
- the vector having the specified values.
-
toVector3D
public Vector3D<Q> toVector3D()
Returns a Vector3D representation of this vector if possible.- Specified by:
toVector3D
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,ParameterVector<Q extends javax.measure.quantity.Quantity>>
- Returns:
- A Vector3D that is equivalent to this vector
- Throws:
DimensionException
- if this vector has any number of dimensions other than 3.
-
fromVector3D
public ParameterVector<Q> fromVector3D(Vector3D<Q> vector)
Return the specifiedVector3D
object as aParameterVector
instance.- Specified by:
fromVector3D
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,ParameterVector<Q extends javax.measure.quantity.Quantity>>
- Parameters:
vector
- TheVector3D
object to be converted to aParameterVector
.- Returns:
- A
ParameterVector
instance that is equivalent to the suppliedVector3D
object.
-
getDimension
public int getDimension()
Returns the number of elements held by this vector.- Specified by:
getDimension
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Returns:
- this vector dimension.
-
getValue
public double getValue(int i)
Returns the value of the Parameter in this vector as adouble
, stated in this vector'sunit
.- Overrides:
getValue
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,ParameterVector<Q extends javax.measure.quantity.Quantity>>
- Parameters:
i
- the dimension index.- Returns:
- the value of the Parameter at
i
. - Throws:
java.lang.IndexOutOfBoundsException
-(i < 0) || (i >= dimension())
-
normValue
public double normValue()
Returns theAbstractParamVector.norm()
, magnitude, or length value of this vector.- Specified by:
normValue
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,ParameterVector<Q extends javax.measure.quantity.Quantity>>
- Returns:
this.norm().doubleValue()
.
-
opposite
public ParameterVector<Q> opposite()
Returns the negation of this vector.
-
plus
public ParameterVector<Q> plus(Vector<Parameter<Q>> that)
Returns the sum of this vector with the one specified. The unit of the output vector will be the units of this vector.- Specified by:
plus
in interfaceGroupAdditive<Q extends javax.measure.quantity.Quantity>
- Specified by:
plus
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the vector to be added.- Returns:
this + that
.- Throws:
DimensionException
- if vector dimensions are different.javax.measure.converter.ConversionException
- if the input vector is not in units consistent with this vector.
-
plus
public ParameterVector<Q> plus(Parameter<Q> that)
Returns the sum of this vector with the parameter specified. The input parameter is added to each component of this vector. The unit of the output vector will be the units of this vector.- Specified by:
plus
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,ParameterVector<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the parameter to be added to each element of this vector.- Returns:
this + that
.
-
minus
public ParameterVector<Q> minus(Vector<Parameter<Q>> that)
Returns the difference between this vector and the one specified. The unit of the output vector will be the units of this vector.- Overrides:
minus
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the vector to be subtracted.- Returns:
this - that
.- Throws:
DimensionException
- if vector dimensions are different.javax.measure.converter.ConversionException
- if the input vector is not in units consistent with this vector.
-
minus
public ParameterVector<Q> minus(Parameter<Q> that)
Subtracts the supplied Parameter from each element of this vector and returns the result. The unit of the output vector will be the units of this vector.- Specified by:
minus
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,ParameterVector<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the Parameter to be subtracted from each element of this vector.- Returns:
this - that
.
-
times
public ParameterVector times(Parameter k)
Returns the product of this vector with the specified coefficient.- Specified by:
times
in interfaceVectorSpace<Vector<Parameter<Q extends javax.measure.quantity.Quantity>>,Parameter<Q extends javax.measure.quantity.Quantity>>
- Specified by:
times
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
k
- the coefficient multiplier.- Returns:
this times k
-
times
public ParameterVector<Q> times(double k)
Returns the product of this vector with the specified coefficient.- Specified by:
times
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,ParameterVector<Q extends javax.measure.quantity.Quantity>>
- Parameters:
k
- the coefficient multiplier.- Returns:
this times k
-
times
public Parameter times(Vector that)
Returns the dot product of this vector with the one specified.- Specified by:
times
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the vector multiplier.- Returns:
this times that
- Throws:
DimensionException
- ifthis.dimension() != that.dimension()
- See Also:
- Wikipedia: Dot Product
-
timesEBE
public ParameterVector timesEBE(Vector that)
Returns the element-by-element product of this vector with the one specified.- Parameters:
that
- the vector multiplier.- Returns:
this .* that
- Throws:
DimensionException
- ifthis.dimension() != that.dimension()
-
cross
public ParameterVector cross(Vector that)
Returns the cross product of two vectors.- Overrides:
cross
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Parameters:
that
- the vector multiplier.- Returns:
this x that
- Throws:
DimensionException
- if(that.getDimension() != this.getDimension())
- See Also:
- Wikipedia: Cross Product
-
divide
public ParameterVector<?> divide(Parameter<?> that)
Returns this vector with each element divided by the specified divisor.- Parameters:
that
- the divisor.- Returns:
this / that
.
-
toUnitVector
public ParameterVector<javax.measure.quantity.Dimensionless> toUnitVector()
Returns this vector converted to a unit vector by dividing all the vector's elements by the length (AbstractParamVector.norm()
) of this vector.
-
copy
public ParameterVector<Q> copy()
Returns a copy of this vectorallocated
by the calling thread (possibly on the stack).
-
getUnit
public javax.measure.unit.Unit<Q> getUnit()
Returns the unit in which thevalues
in this vector are stated in.- Specified by:
getUnit
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,ParameterVector<Q extends javax.measure.quantity.Quantity>>
- Returns:
- The unit in which the values in this vector are stated
-
to
public <R extends javax.measure.quantity.Quantity> ParameterVector<R> to(javax.measure.unit.Unit<R> unit)
Returns the equivalent to this vector but stated in the specified unit.- Specified by:
to
in classAbstractParamVector<Q extends javax.measure.quantity.Quantity,ParameterVector<Q extends javax.measure.quantity.Quantity>>
- Type Parameters:
R
- The Quantity (unit type) of the vector being output.- Parameters:
unit
- the unit of the vector to be returned.- Returns:
- a vector equivalent to this vector but stated in the specified unit.
- Throws:
javax.measure.converter.ConversionException
- if the current model does not allows for conversion to the specified unit.
-
asType
public <T extends javax.measure.quantity.Quantity> ParameterVector<T> asType(java.lang.Class<T> type) throws java.lang.ClassCastException
Casts this ParameterVector to a parameterized unit of specified nature or throw aClassCastException
if the dimension of the specified quantity and this parameter's unit dimension do not match.- Parameters:
type
- the quantity class identifying the nature of the unit.- Returns:
- this ParameterVector parameterized with the specified type.
- Throws:
java.lang.ClassCastException
- if the dimension of this parameter's unit is different from the specified quantity dimension.java.lang.UnsupportedOperationException
- if the specified quantity class does not have a public static field named "UNIT" holding the standard unit for the quantity.
-
toFloat64Vector
public Float64Vector toFloat64Vector()
Returns the values stored in this vector, stated in this vector'sunit
, as a Float64Vector.
-
equals
public boolean equals(java.lang.Object obj)
Compares this ParameterVector against the specified object for strict equality (same values and same units).
-
hashCode
public int hashCode()
Returns the hash code for this parameter.- Overrides:
hashCode
in classVector<Parameter<Q extends javax.measure.quantity.Quantity>>
- Returns:
- the hash code value.
- See Also:
Vector.equals(org.jscience.mathematics.vector.Vector<F>, java.util.Comparator<F>)
-
main
public static void main(java.lang.String[] args)
Tests the methods in this class.
-
-