Class Vector
- java.lang.Object
-
- org.hansken.plugin.extraction.api.Vector
-
public final class Vector extends Object
An opaque vector of floating point values.- Author:
- Netherlands Forensic Institute
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
asBinary()
Returns the binary representation of the Vector.static Vector
asVector(byte[] bytes)
Creates a vector from a binary representation.boolean
equals(Object obj)
int
hashCode()
static Vector
of(float... values)
Creates a Vector from an array of floating point values.static Vector
of(Collection<Float> values)
Creates a Vector from a collection of numbers.static Vector
ofBase64(String base64)
Creates a Vector from a base64 encoded string.int
size()
Returns the number of dimensions of the vector.String
toBase64()
Returns a base64 encoded string of the Vector.String
toString()
float[]
values()
Returns the values of the Vector as an array of floats.
-
-
-
Method Detail
-
of
public static Vector of(float... values)
Creates a Vector from an array of floating point values.- Parameters:
values
- the values to use- Returns:
- a vector
-
of
public static Vector of(Collection<Float> values)
Creates a Vector from a collection of numbers. Note that all numbers are converted to floats internally, so loss of precision may occur when doubles or longs are offered.- Parameters:
values
- the values to use- Returns:
- a vector
-
ofBase64
public static Vector ofBase64(String base64)
Creates a Vector from a base64 encoded string.- Parameters:
base64
- the base64 encoded string to use- Returns:
- a vector
-
asVector
public static Vector asVector(byte[] bytes)
Creates a vector from a binary representation.Vector.asBinary()
can be used to obtain a binary representation. Note that this directly sets the internal state of the Vector, use {code asVector(bytes.clone()} to store a safe, immutable copy.- Parameters:
bytes
- the bytes to convert to a vector.- Returns:
- a vector
-
asBinary
public byte[] asBinary()
Returns the binary representation of the Vector.Vector.asVector(byte[])
can be used to convert the binary representation back to the original vector. The format of the returned bytes is a sequence of the floating point values of the vector, stored as big-endian IEEE 754 encoded 32-bit floating point values. Note that this exposes the internal state of the Vector, use {code asBinary().clone()} to obtain a safely mutable copy.- Returns:
- a binary representation of the vector.
-
size
public int size()
Returns the number of dimensions of the vector.- Returns:
- the number of dimensions of the vector.
-
values
public float[] values()
Returns the values of the Vector as an array of floats.- Returns:
- the values of the Vector as an array of floats.
-
toBase64
public String toBase64()
Returns a base64 encoded string of the Vector.Vector.ofBase64()
can be used to convert the return base64 encoded string back to a Vector.- Returns:
- a base64 encoded string of the Vector.
-
-