public interface GettableByIndexData
Modifier and Type | Method and Description |
---|---|
<T> T |
get(int i,
Class<T> targetClass)
Returns the
i th value converted to the given Java type. |
<T> T |
get(int i,
TypeCodec<T> codec)
Returns the
i th value converted using the given TypeCodec . |
<T> T |
get(int i,
com.google.common.reflect.TypeToken<T> targetType)
Returns the
i th value converted to the given Java type. |
boolean |
getBool(int i)
Returns the
i th value as a boolean. |
byte |
getByte(int i)
Returns the
i th value as a byte. |
ByteBuffer |
getBytes(int i)
Returns the
i th value as a byte array. |
ByteBuffer |
getBytesUnsafe(int i)
Returns the
i th value as a ByteBuffer. |
LocalDate |
getDate(int i)
Returns the
i th value as a date (without time). |
BigDecimal |
getDecimal(int i)
Returns the
i th value as a variable length decimal. |
double |
getDouble(int i)
Returns the
i th value as a double. |
float |
getFloat(int i)
Returns the
i th value as a float. |
InetAddress |
getInet(int i)
Returns the
i th value as an InetAddress. |
int |
getInt(int i)
Returns the
i th value as an integer. |
<T> List<T> |
getList(int i,
Class<T> elementsClass)
Returns the
i th value as a list. |
<T> List<T> |
getList(int i,
com.google.common.reflect.TypeToken<T> elementsType)
Returns the
i th value as a list. |
long |
getLong(int i)
Returns the
i th value as a long. |
<K,V> Map<K,V> |
getMap(int i,
Class<K> keysClass,
Class<V> valuesClass)
Returns the
i th value as a map. |
<K,V> Map<K,V> |
getMap(int i,
com.google.common.reflect.TypeToken<K> keysType,
com.google.common.reflect.TypeToken<V> valuesType)
Returns the
i th value as a map. |
Object |
getObject(int i)
Returns the
i th value as the Java type matching its CQL type. |
<T> Set<T> |
getSet(int i,
Class<T> elementsClass)
Returns the
i th value as a set. |
<T> Set<T> |
getSet(int i,
com.google.common.reflect.TypeToken<T> elementsType)
Returns the
i th value as a set. |
short |
getShort(int i)
Returns the
i th value as a short. |
String |
getString(int i)
Returns the
i th value as a string. |
long |
getTime(int i)
Returns the
i th value as a long in nanoseconds since midnight. |
Date |
getTimestamp(int i)
Returns the
i th value as a date. |
TupleValue |
getTupleValue(int i)
Return the
i th value as a tuple value. |
UDTValue |
getUDTValue(int i)
Return the
i th value as a UDT value. |
UUID |
getUUID(int i)
Returns the
i th value as a UUID. |
BigInteger |
getVarint(int i)
Returns the
i th value as a variable length integer. |
boolean |
isNull(int i)
Returns whether the
i th value is NULL. |
boolean isNull(int i)
i
th value is NULL.i
- the index (0 <= i < size()
) of the value to check.i
th value is NULL.IndexOutOfBoundsException
- if i
is not a valid index for
this object.boolean getBool(int i)
i
th value as a boolean.i
- the index (0 <= i < size()
) to retrieve.i
th element. If the
value is NULL, false
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type BOOLEAN.byte getByte(int i)
i
th value as a byte.i
- the index (0 <= i < size()
) to retrieve.i
th element as a byte. If the
value is NULL, 0
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type TINYINT.short getShort(int i)
i
th value as a short.i
- the index (0 <= i < size()
) to retrieve.i
th element as a short. If the
value is NULL, 0
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type SMALLINT.int getInt(int i)
i
th value as an integer.i
- the index (0 <= i < size()
) to retrieve.i
th element as an integer. If the
value is NULL, 0
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type INT.long getLong(int i)
i
th value as a long.i
- the index (0 <= i < size()
) to retrieve.i
th element as a long. If the
value is NULL, 0L
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type BIGINT or COUNTER.Date getTimestamp(int i)
i
th value as a date.i
- the index (0 <= i < size()
) to retrieve.i
th element as a data. If the
value is NULL, null
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type TIMESTAMP.LocalDate getDate(int i)
i
th value as a date (without time).i
- the index (0 <= i < size()
) to retrieve.i
th element as an date. If the
value is NULL, null
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type DATE.long getTime(int i)
i
th value as a long in nanoseconds since midnight.i
- the index (0 <= i < size()
) to retrieve.i
th element as a long. If the
value is NULL, 0L
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type TIME.float getFloat(int i)
i
th value as a float.i
- the index (0 <= i < size()
) to retrieve.i
th element as a float. If the
value is NULL, 0.0f
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type FLOAT.double getDouble(int i)
i
th value as a double.i
- the index (0 <= i < size()
) to retrieve.i
th element as a double. If the
value is NULL, 0.0
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type DOUBLE.ByteBuffer getBytesUnsafe(int i)
i
th value as a ByteBuffer.
Note: this method always return the bytes composing the value, even if
the column is not of type BLOB. That is, this method never throw an
InvalidTypeException. However, if the type is not BLOB, it is up to the
caller to handle the returned value correctly.i
- the index (0 <= i < size()
) to retrieve.i
th element as a ByteBuffer. If the
value is NULL, null
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.ByteBuffer getBytes(int i)
i
th value as a byte array.
Note that this method validate that the column is of type BLOB. If you want to retrieve
the bytes for any type, use getBytesUnsafe(int)
instead.
i
- the index (0 <= i < size()
) to retrieve.i
th element as a byte array. If the
value is NULL, null
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
type is not of type BLOB.String getString(int i)
i
th value as a string.i
- the index (0 <= i < size()
) to retrieve.i
th element as a string. If the
value is NULL, null
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
type is none of:
VARCHAR, TEXT or ASCII.BigInteger getVarint(int i)
i
th value as a variable length integer.i
- the index (0 <= i < size()
) to retrieve.i
th element as a variable
length integer. If the value is NULL, null
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type VARINT.BigDecimal getDecimal(int i)
i
th value as a variable length decimal.i
- the index (0 <= i < size()
) to retrieve.i
th element as a variable
length decimal. If the value is NULL, null
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type DECIMAL.UUID getUUID(int i)
i
th value as a UUID.i
- the index (0 <= i < size()
) to retrieve.i
th element as a UUID.
If the value is NULL, null
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type UUID
or TIMEUUID.InetAddress getInet(int i)
i
th value as an InetAddress.i
- the index (0 <= i < size()
) to retrieve.i
th element as an InetAddress.
If the value is NULL, null
is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not of type INET.<T> List<T> getList(int i, Class<T> elementsClass)
i
th value as a list.
If the type of the elements is generic, use getList(int, TypeToken)
.
i
- the index (0 <= i < size()
) to retrieve.elementsClass
- the class for the elements of the list to retrieve.i
th element as a list of
T
objects. If the value is NULL, an empty list is
returned (note that Cassandra makes no difference between an empty list
and column of type list that is not set). The returned list is immutable.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not a list or if its
elements are not of class T
.<T> List<T> getList(int i, com.google.common.reflect.TypeToken<T> elementsType)
i
th value as a list.
Use this variant with nested collections, which produce a generic element type:
List<List<String>> l = row.getList(1, new TypeToken<List<String>>() {});
i
- the index (0 <= i < size()
) to retrieve.elementsType
- the type of the elements of the list to retrieve.i
th element as a list of
T
objects. If the value is NULL, an empty list is
returned (note that Cassandra makes no difference between an empty list
and column of type list that is not set). The returned list is immutable.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not a list or if its
elements are not of class T
.<T> Set<T> getSet(int i, Class<T> elementsClass)
i
th value as a set.
If the type of the elements is generic, use getSet(int, TypeToken)
.
i
- the index (0 <= i < size()
) to retrieve.elementsClass
- the class for the elements of the set to retrieve.i
th element as a set of
T
objects. If the value is NULL, an empty set is
returned (note that Cassandra makes no difference between an empty set
and column of type set that is not set). The returned set is immutable.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not a set or if its
elements are not of class T
.<T> Set<T> getSet(int i, com.google.common.reflect.TypeToken<T> elementsType)
i
th value as a set.
Use this variant with nested collections, which produce a generic element type:
Set<List<String>> l = row.getSet(1, new TypeToken<List<String>>() {});
i
- the index (0 <= i < size()
) to retrieve.elementsType
- the type for the elements of the set to retrieve.i
th element as a set of
T
objects. If the value is NULL, an empty set is
returned (note that Cassandra makes no difference between an empty set
and column of type set that is not set). The returned set is immutable.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not a set or if its
elements are not of class T
.<K,V> Map<K,V> getMap(int i, Class<K> keysClass, Class<V> valuesClass)
i
th value as a map.
If the type of the keys and/or values is generic, use getMap(int, TypeToken, TypeToken)
.
i
- the index (0 <= i < size()
) to retrieve.keysClass
- the class for the keys of the map to retrieve.valuesClass
- the class for the values of the map to retrieve.i
th element as a map of
K
to V
objects. If the value is NULL,
an empty map is returned (note that Cassandra makes no difference
between an empty map and column of type map that is not set). The
returned map is immutable.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not a map, if its
keys are not of class K
or if its values are not of
class V
.<K,V> Map<K,V> getMap(int i, com.google.common.reflect.TypeToken<K> keysType, com.google.common.reflect.TypeToken<V> valuesType)
i
th value as a map.
Use this variant with nested collections, which produce a generic element type:
Map<Int, List<String>> l = row.getMap(1, TypeToken.of(Integer.class), new TypeToken<List<String>>() {});
i
- the index (0 <= i < size()
) to retrieve.keysType
- the type for the keys of the map to retrieve.valuesType
- the type for the values of the map to retrieve.i
th element as a map of
K
to V
objects. If the value is NULL,
an empty map is returned (note that Cassandra makes no difference
between an empty map and column of type map that is not set). The
returned map is immutable.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not a map, if its
keys are not of class K
or if its values are not of
class V
.UDTValue getUDTValue(int i)
i
th value as a UDT value.i
- the index (0 <= i < size()
) to retrieve.i
th element as a UDT value. If the value is NULL,
then null
will be returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not a UDT value.TupleValue getTupleValue(int i)
i
th value as a tuple value.i
- the index (0 <= i < size()
) to retrieve.i
th element as a tuple value. If the value is NULL,
then null
will be returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.InvalidTypeException
- if value i
is not a tuple value.Object getObject(int i)
i
th value as the Java type matching its CQL type.
This method uses the default codec for the underlying CQL type
to perform deserialization, and is safe to be used
as long as only default codecs are in use.
If a second, custom codec for the same CQL type is registered, which one will
be used is unspecified; in such cases, it is preferable to use
the more deterministic methods get(int, Class)
or get(int, TypeToken)
instead.
i
- the index to retrieve.i
th value as the Java type matching its CQL type.
If the value is NULL and is a simple type, UDT or tuple, null
is returned.
If it is NULL and is a collection type, an empty (immutable) collection is returned.IndexOutOfBoundsException
- if i
is not a valid index for this object.<T> T get(int i, Class<T> targetClass)
i
th value converted to the given Java type.
A suitable TypeCodec
instance for the underlying CQL type and targetClass
must
have been previously registered with the CodecRegistry
currently in use.
This method should be used instead of getObject(int)
in cases
where more than one codec is registered for the same CQL type; specifying the Java class
allows the CodecRegistry
to narrow down the search and return only an exactly-matching codec (if any),
thus avoiding any risk of ambiguity.
i
- the index to retrieve.targetClass
- The Java type the value should be converted to.i
th value converted to the given Java type.
If the CQL value is NULL
, this method will return null
for a simple type, UDT or tuple, and an empty (immutable) collection for collection types.IndexOutOfBoundsException
- if i
is not a valid index for this object.CodecNotFoundException
- if no TypeCodec
instance for targetClass
could be found
by the CodecRegistry
currently in use.<T> T get(int i, com.google.common.reflect.TypeToken<T> targetType)
i
th value converted to the given Java type.
A suitable TypeCodec
instance for the underlying CQL type and targetType
must
have been previously registered with the CodecRegistry
currently in use.
This method should be used instead of getObject(int)
in cases
where more than one codec is registered for the same CQL type; specifying the Java class
allows the CodecRegistry
to narrow down the search and return only an exactly-matching codec (if any),
thus avoiding any risk of ambiguity.
i
- the index to retrieve.targetType
- The Java type the value should be converted to.i
th value converted to the given Java type.
If the CQL value is NULL
, the default set of codecs will return null
for a simple type, UDT or tuple, and an empty (immutable) collection for collection types.IndexOutOfBoundsException
- if i
is not a valid index for this object.CodecNotFoundException
- if no TypeCodec
instance for targetType
could be found
by the CodecRegistry
currently in use.<T> T get(int i, TypeCodec<T> codec)
i
th value converted using the given TypeCodec
.
Note that this method allows to entirely bypass the CodecRegistry
currently in use
and forces the driver to use the given codec instead.
It is the caller's responsibility to ensure that the given codec accepts
the underlying CQL type; failing to do so may result in InvalidTypeException
s being thrown.
i
- the index to retrieve.codec
- The TypeCodec
to use to deserialize the value; may not be null
.i
th value converted using the given TypeCodec
.InvalidTypeException
- if the given codec does not accept
the underlying CQL type.IndexOutOfBoundsException
- if i
is not a valid index for this object.Copyright © 2012–2015. All rights reserved.