Skip to content

Commit 3bbd519

Browse files
committed
Refactor CqlVector to generic type
1 parent 1a3c314 commit 3bbd519

File tree

13 files changed

+24
-30
lines changed

13 files changed

+24
-30
lines changed

core/src/main/java/com/datastax/oss/driver/api/core/data/CqlVector.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@
5252
* where possible we've tried to make the API of this class similar to the equivalent methods on
5353
* {@link List}.
5454
*/
55-
public class CqlVector<T extends Number> implements Iterable<T>, Serializable {
55+
public class CqlVector<T> implements Iterable<T>, Serializable {
5656

5757
/**
5858
* Create a new CqlVector containing the specified values.
5959
*
6060
* @param vals the collection of values to wrap.
6161
* @return a CqlVector wrapping those values
6262
*/
63-
public static <V extends Number> CqlVector<V> newInstance(V... vals) {
63+
public static <V> CqlVector<V> newInstance(V... vals) {
6464

6565
// Note that Array.asList() guarantees the return of an array which implements RandomAccess
6666
return new CqlVector(Arrays.asList(vals));
@@ -73,7 +73,7 @@ public static <V extends Number> CqlVector<V> newInstance(V... vals) {
7373
* @param list the collection of values to wrap.
7474
* @return a CqlVector wrapping those values
7575
*/
76-
public static <V extends Number> CqlVector<V> newInstance(List<V> list) {
76+
public static <V> CqlVector<V> newInstance(List<V> list) {
7777
Preconditions.checkArgument(list != null, "Input list should not be null");
7878
return new CqlVector(list);
7979
}
@@ -87,8 +87,7 @@ public static <V extends Number> CqlVector<V> newInstance(List<V> list) {
8787
* @param subtypeCodec
8888
* @return a new CqlVector built from the String representation
8989
*/
90-
public static <V extends Number> CqlVector<V> from(
91-
@NonNull String str, @NonNull TypeCodec<V> subtypeCodec) {
90+
public static <V> CqlVector<V> from(@NonNull String str, @NonNull TypeCodec<V> subtypeCodec) {
9291
Preconditions.checkArgument(str != null, "Cannot create CqlVector from null string");
9392
Preconditions.checkArgument(!str.isEmpty(), "Cannot create CqlVector from empty string");
9493
ArrayList<V> vals =
@@ -205,7 +204,7 @@ public String toString() {
205204
*
206205
* @param <T> inner type of CqlVector, assume Number is always Serializable.
207206
*/
208-
private static class SerializationProxy<T extends Number> implements Serializable {
207+
private static class SerializationProxy<T> implements Serializable {
209208

210209
private static final long serialVersionUID = 1;
211210

core/src/main/java/com/datastax/oss/driver/api/core/data/GettableById.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ default CqlDuration getCqlDuration(@NonNull CqlIdentifier id) {
531531
* @throws IllegalArgumentException if the id is invalid.
532532
*/
533533
@Nullable
534-
default <ElementT extends Number> CqlVector<ElementT> getVector(
534+
default <ElementT> CqlVector<ElementT> getVector(
535535
@NonNull CqlIdentifier id, @NonNull Class<ElementT> elementsClass) {
536536
return getVector(firstIndexOf(id), elementsClass);
537537
}

core/src/main/java/com/datastax/oss/driver/api/core/data/GettableByIndex.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ default CqlDuration getCqlDuration(int i) {
446446
* @throws IndexOutOfBoundsException if the index is invalid.
447447
*/
448448
@Nullable
449-
default <ElementT extends Number> CqlVector<ElementT> getVector(
450-
int i, @NonNull Class<ElementT> elementsClass) {
449+
default <ElementT> CqlVector<ElementT> getVector(int i, @NonNull Class<ElementT> elementsClass) {
451450
return get(i, GenericType.vectorOf(elementsClass));
452451
}
453452

core/src/main/java/com/datastax/oss/driver/api/core/data/GettableByName.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ default CqlDuration getCqlDuration(@NonNull String name) {
527527
* @throws IllegalArgumentException if the name is invalid.
528528
*/
529529
@Nullable
530-
default <ElementT extends Number> CqlVector<ElementT> getVector(
530+
default <ElementT> CqlVector<ElementT> getVector(
531531
@NonNull String name, @NonNull Class<ElementT> elementsClass) {
532532
return getVector(firstIndexOf(name), elementsClass);
533533
}

core/src/main/java/com/datastax/oss/driver/api/core/data/SettableById.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ default SelfT setCqlDuration(@NonNull CqlIdentifier id, @Nullable CqlDuration v)
573573
*/
574574
@NonNull
575575
@CheckReturnValue
576-
default <ElementT extends Number> SelfT setVector(
576+
default <ElementT> SelfT setVector(
577577
@NonNull CqlIdentifier id,
578578
@Nullable CqlVector<ElementT> v,
579579
@NonNull Class<ElementT> elementsClass) {

core/src/main/java/com/datastax/oss/driver/api/core/data/SettableByIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ default SelfT setCqlDuration(int i, @Nullable CqlDuration v) {
425425
*/
426426
@NonNull
427427
@CheckReturnValue
428-
default <ElementT extends Number> SelfT setVector(
428+
default <ElementT> SelfT setVector(
429429
int i, @Nullable CqlVector<ElementT> v, @NonNull Class<ElementT> elementsClass) {
430430
return set(i, v, GenericType.vectorOf(elementsClass));
431431
}

core/src/main/java/com/datastax/oss/driver/api/core/data/SettableByName.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ default SelfT setCqlDuration(@NonNull String name, @Nullable CqlDuration v) {
572572
*/
573573
@NonNull
574574
@CheckReturnValue
575-
default <ElementT extends Number> SelfT setVector(
575+
default <ElementT> SelfT setVector(
576576
@NonNull String name,
577577
@Nullable CqlVector<ElementT> v,
578578
@NonNull Class<ElementT> elementsClass) {

core/src/main/java/com/datastax/oss/driver/api/core/type/codec/TypeCodecs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ public static TypeCodec<TupleValue> tupleOf(@NonNull TupleType cqlType) {
210210
return new TupleCodec(cqlType);
211211
}
212212

213-
public static <SubtypeT extends Number> TypeCodec<CqlVector<SubtypeT>> vectorOf(
213+
public static <SubtypeT> TypeCodec<CqlVector<SubtypeT>> vectorOf(
214214
@NonNull VectorType type, @NonNull TypeCodec<SubtypeT> subtypeCodec) {
215215
return new VectorCodec(
216216
DataTypes.vectorOf(subtypeCodec.getCqlType(), type.getDimensions()), subtypeCodec);
217217
}
218218

219-
public static <SubtypeT extends Number> TypeCodec<CqlVector<SubtypeT>> vectorOf(
219+
public static <SubtypeT> TypeCodec<CqlVector<SubtypeT>> vectorOf(
220220
int dimensions, @NonNull TypeCodec<SubtypeT> subtypeCodec) {
221221
return new VectorCodec(DataTypes.vectorOf(subtypeCodec.getCqlType(), dimensions), subtypeCodec);
222222
}

core/src/main/java/com/datastax/oss/driver/api/core/type/reflect/GenericType.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,15 @@ public static <T> GenericType<Set<T>> setOf(@NonNull GenericType<T> elementType)
151151
}
152152

153153
@NonNull
154-
public static <T extends Number> GenericType<CqlVector<T>> vectorOf(
155-
@NonNull Class<T> elementType) {
154+
public static <T> GenericType<CqlVector<T>> vectorOf(@NonNull Class<T> elementType) {
156155
TypeToken<CqlVector<T>> token =
157156
new TypeToken<CqlVector<T>>() {}.where(
158157
new TypeParameter<T>() {}, TypeToken.of(elementType));
159158
return new GenericType<>(token);
160159
}
161160

162161
@NonNull
163-
public static <T extends Number> GenericType<CqlVector<T>> vectorOf(
164-
@NonNull GenericType<T> elementType) {
162+
public static <T> GenericType<CqlVector<T>> vectorOf(@NonNull GenericType<T> elementType) {
165163
TypeToken<CqlVector<T>> token =
166164
new TypeToken<CqlVector<T>>() {}.where(new TypeParameter<T>() {}, elementType.token);
167165
return new GenericType<>(token);

core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/VectorCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import java.util.List;
3434
import java.util.NoSuchElementException;
3535

36-
public class VectorCodec<SubtypeT extends Number> implements TypeCodec<CqlVector<SubtypeT>> {
36+
public class VectorCodec<SubtypeT extends DataType> implements TypeCodec<CqlVector<SubtypeT>> {
3737

3838
private final VectorType cqlType;
3939
private final GenericType<CqlVector<SubtypeT>> javaType;

0 commit comments

Comments
 (0)