public class CqlVector<T extends Number> extends Object implements Iterable<T>, Serializable
A CQL vector is a fixed-length array of non-null numeric values. These properties don't map cleanly to an existing class in the standard JDK Collections hierarchy so we provide this value object instead. Like other value object collections returned by the driver instances of this class are not immutable; think of these value objects as a representation of a vector stored in the database as an initial step in some additional computation.
While we don't implement any Collection APIs we do implement Iterable. We also attempt to play
nice with the Streams API in order to better facilitate integration with data pipelines. Finally,
where possible we've tried to make the API of this class similar to the equivalent methods on
List
.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
static <V extends Number> |
from(String str,
TypeCodec<V> subtypeCodec)
Create a new CqlVector instance from the specified string representation.
|
T |
get(int idx)
Retrieve the value at the specified index.
|
int |
hashCode() |
boolean |
isEmpty()
Return a boolean indicating whether the vector is empty.
|
Iterator<T> |
iterator()
Create an
Iterator for this vector |
static <V extends Number> |
newInstance(List<V> list)
Create a new CqlVector that "wraps" an existing ArrayList.
|
static <V extends Number> |
newInstance(V... vals)
Create a new CqlVector containing the specified values.
|
T |
set(int idx,
T val)
Update the value at the specified index.
|
int |
size()
Return the size of this vector.
|
Stream<T> |
stream()
Create a
Stream of the values in this vector |
CqlVector<T> |
subVector(int from,
int to)
Return a CqlVector consisting of the contents of a portion of this vector.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static <V extends Number> CqlVector<V> newInstance(V... vals)
vals
- the collection of values to wrap.public static <V extends Number> CqlVector<V> newInstance(List<V> list)
list
- the collection of values to wrap.public static <V extends Number> CqlVector<V> from(@NonNull String str, @NonNull TypeCodec<V> subtypeCodec)
toString()
; passing this method the output from a toString
call on some CqlVector should return a CqlVector that is equal to the origin instance.str
- a String representation of a CqlVectorsubtypeCodec
- public T get(int idx)
List.get(int)
idx
- the index to retrievepublic T set(int idx, T val)
List.set(int, Object)
idx
- the index to setval
- the new value for the specified indexpublic int size()
List.size()
public CqlVector<T> subVector(int from, int to)
List.subList(int, int)
from
- the index to start from (inclusive)to
- the index to end on (exclusive)public boolean isEmpty()
List.isEmpty()
public Stream<T> stream()
Stream
of the values in this vectorCopyright © 2017–2023. All rights reserved.