Skip to content

Commit bdd4af2

Browse files
authored
Rename Vector class names. (#1595)
JAVA-5710
1 parent 08880c8 commit bdd4af2

27 files changed

+328
-332
lines changed

Diff for: bson/src/main/org/bson/Vector.java renamed to bson/src/main/org/bson/BinaryVector.java

+28-32
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,19 @@
2020
import static org.bson.assertions.Assertions.notNull;
2121

2222
/**
23-
* Represents a vector that is stored and retrieved using the BSON Binary Subtype 9 format.
24-
* This class supports multiple vector {@link DataType}'s and provides static methods to create
25-
* vectors.
26-
* <p>
27-
* Vectors are densely packed arrays of numbers, all the same type, which are stored efficiently
28-
* in BSON using a binary format.
23+
* Binary Vectors are densely packed arrays of numbers, all the same type, which are stored and retrieved efficiently using the BSON Binary
24+
* Subtype 9 format. This class supports multiple vector {@link DataType}'s and provides static methods to create vectors.
2925
* <p>
3026
* <b>NOTE:</b> This class should be treated as <b>sealed</b>: it must not be extended or implemented by consumers of the library.
3127
*
3228
* @mongodb.server.release 6.0
3329
* @see BsonBinary
3430
* @since 5.3
3531
*/
36-
public abstract class Vector {
32+
public abstract class BinaryVector {
3733
private final DataType dataType;
3834

39-
Vector(final DataType dataType) {
35+
BinaryVector(final DataType dataType) {
4036
this.dataType = dataType;
4137
}
4238

@@ -56,18 +52,18 @@ public abstract class Vector {
5652
* </pre>
5753
* <p>
5854
* NOTE: The byte array `data` is not copied; changes to the provided array will be reflected
59-
* in the created {@link PackedBitVector} instance.
55+
* in the created {@link PackedBitBinaryVector} instance.
6056
*
6157
* @param data The byte array representing the packed bit vector data. Each byte can store 8 bits.
6258
* @param padding The number of least-significant bits (0 to 7) to ignore in the final byte of the vector data.
63-
* @return A {@link PackedBitVector} instance with the {@link DataType#PACKED_BIT} data type.
59+
* @return A {@link PackedBitBinaryVector} instance with the {@link DataType#PACKED_BIT} data type.
6460
* @throws IllegalArgumentException If the padding value is greater than 7.
6561
*/
66-
public static PackedBitVector packedBitVector(final byte[] data, final byte padding) {
62+
public static PackedBitBinaryVector packedBitVector(final byte[] data, final byte padding) {
6763
notNull("data", data);
6864
isTrueArgument("Padding must be between 0 and 7 bits. Provided padding: " + padding, padding >= 0 && padding <= 7);
6965
isTrueArgument("Padding must be 0 if vector is empty. Provided padding: " + padding, padding == 0 || data.length > 0);
70-
return new PackedBitVector(data, padding);
66+
return new PackedBitBinaryVector(data, padding);
7167
}
7268

7369
/**
@@ -77,14 +73,14 @@ public static PackedBitVector packedBitVector(final byte[] data, final byte padd
7773
* with values in the range [-128, 127].</p>
7874
* <p>
7975
* NOTE: The byte array `data` is not copied; changes to the provided array will be reflected
80-
* in the created {@link Int8Vector} instance.
76+
* in the created {@link Int8BinaryVector} instance.
8177
*
8278
* @param data The byte array representing the {@link DataType#INT8} vector data.
83-
* @return A {@link Int8Vector} instance with the {@link DataType#INT8} data type.
79+
* @return A {@link Int8BinaryVector} instance with the {@link DataType#INT8} data type.
8480
*/
85-
public static Int8Vector int8Vector(final byte[] data) {
81+
public static Int8BinaryVector int8Vector(final byte[] data) {
8682
notNull("data", data);
87-
return new Int8Vector(data);
83+
return new Int8BinaryVector(data);
8884
}
8985

9086
/**
@@ -93,50 +89,50 @@ public static Int8Vector int8Vector(final byte[] data) {
9389
* A {@link DataType#FLOAT32} vector is a vector of floating-point numbers, where each element in the vector is a float.</p>
9490
* <p>
9591
* NOTE: The float array `data` is not copied; changes to the provided array will be reflected
96-
* in the created {@link Float32Vector} instance.
92+
* in the created {@link Float32BinaryVector} instance.
9793
*
9894
* @param data The float array representing the {@link DataType#FLOAT32} vector data.
99-
* @return A {@link Float32Vector} instance with the {@link DataType#FLOAT32} data type.
95+
* @return A {@link Float32BinaryVector} instance with the {@link DataType#FLOAT32} data type.
10096
*/
101-
public static Float32Vector floatVector(final float[] data) {
97+
public static Float32BinaryVector floatVector(final float[] data) {
10298
notNull("data", data);
103-
return new Float32Vector(data);
99+
return new Float32BinaryVector(data);
104100
}
105101

106102
/**
107-
* Returns the {@link PackedBitVector}.
103+
* Returns the {@link PackedBitBinaryVector}.
108104
*
109-
* @return {@link PackedBitVector}.
105+
* @return {@link PackedBitBinaryVector}.
110106
* @throws IllegalStateException if this vector is not of type {@link DataType#PACKED_BIT}. Use {@link #getDataType()} to check the vector
111107
* type before calling this method.
112108
*/
113-
public PackedBitVector asPackedBitVector() {
109+
public PackedBitBinaryVector asPackedBitVector() {
114110
ensureType(DataType.PACKED_BIT);
115-
return (PackedBitVector) this;
111+
return (PackedBitBinaryVector) this;
116112
}
117113

118114
/**
119-
* Returns the {@link Int8Vector}.
115+
* Returns the {@link Int8BinaryVector}.
120116
*
121-
* @return {@link Int8Vector}.
117+
* @return {@link Int8BinaryVector}.
122118
* @throws IllegalStateException if this vector is not of type {@link DataType#INT8}. Use {@link #getDataType()} to check the vector
123119
* type before calling this method.
124120
*/
125-
public Int8Vector asInt8Vector() {
121+
public Int8BinaryVector asInt8Vector() {
126122
ensureType(DataType.INT8);
127-
return (Int8Vector) this;
123+
return (Int8BinaryVector) this;
128124
}
129125

130126
/**
131-
* Returns the {@link Float32Vector}.
127+
* Returns the {@link Float32BinaryVector}.
132128
*
133-
* @return {@link Float32Vector}.
129+
* @return {@link Float32BinaryVector}.
134130
* @throws IllegalStateException if this vector is not of type {@link DataType#FLOAT32}. Use {@link #getDataType()} to check the vector
135131
* type before calling this method.
136132
*/
137-
public Float32Vector asFloat32Vector() {
133+
public Float32BinaryVector asFloat32Vector() {
138134
ensureType(DataType.FLOAT32);
139-
return (Float32Vector) this;
135+
return (Float32BinaryVector) this;
140136
}
141137

142138
/**

Diff for: bson/src/main/org/bson/BsonBinary.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
import org.bson.assertions.Assertions;
2020
import org.bson.internal.UuidHelper;
21-
import org.bson.internal.vector.VectorHelper;
21+
import org.bson.internal.vector.BinaryVectorHelper;
2222

2323
import java.util.Arrays;
2424
import java.util.UUID;
2525

26-
import static org.bson.internal.vector.VectorHelper.encodeVectorToBinary;
26+
import static org.bson.internal.vector.BinaryVectorHelper.encodeVectorToBinary;
2727

2828
/**
2929
* A representation of the BSON Binary type. Note that for performance reasons instances of this class are not immutable,
@@ -93,12 +93,12 @@ public BsonBinary(final UUID uuid) {
9393
}
9494

9595
/**
96-
* Constructs a {@linkplain BsonBinarySubType#VECTOR subtype 9} {@link BsonBinary} from the given {@link Vector}.
96+
* Constructs a {@linkplain BsonBinarySubType#VECTOR subtype 9} {@link BsonBinary} from the given {@link BinaryVector}.
9797
*
98-
* @param vector the {@link Vector}
98+
* @param vector the {@link BinaryVector}
9999
* @since 5.3
100100
*/
101-
public BsonBinary(final Vector vector) {
101+
public BsonBinary(final BinaryVector vector) {
102102
if (vector == null) {
103103
throw new IllegalArgumentException("Vector must not be null");
104104
}
@@ -145,18 +145,18 @@ public UUID asUuid() {
145145
}
146146

147147
/**
148-
* Returns the binary as a {@link Vector}. The {@linkplain #getType() subtype} must be {@linkplain BsonBinarySubType#VECTOR 9}.
148+
* Returns the binary as a {@link BinaryVector}. The {@linkplain #getType() subtype} must be {@linkplain BsonBinarySubType#VECTOR 9}.
149149
*
150150
* @return the vector
151151
* @throws BsonInvalidOperationException if the binary subtype is not {@link BsonBinarySubType#VECTOR}.
152152
* @since 5.3
153153
*/
154-
public Vector asVector() {
154+
public BinaryVector asVector() {
155155
if (type != BsonBinarySubType.VECTOR.getValue()) {
156156
throw new BsonInvalidOperationException("type must be a Vector subtype.");
157157
}
158158

159-
return VectorHelper.decodeBinaryToVector(this.data);
159+
return BinaryVectorHelper.decodeBinaryToVector(this.data);
160160
}
161161

162162
/**

Diff for: bson/src/main/org/bson/BsonBinarySubType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public enum BsonBinarySubType {
7878
*
7979
* @mongodb.server.release 6.0
8080
* @since 5.3
81-
* @see Vector
81+
* @see BinaryVector
8282
*/
8383
VECTOR((byte) 0x09),
8484

Diff for: bson/src/main/org/bson/Float32Vector.java renamed to bson/src/main/org/bson/Float32BinaryVector.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,30 @@
2323
/**
2424
* Represents a vector of 32-bit floating-point numbers, where each element in the vector is a float.
2525
* <p>
26-
* The {@link Float32Vector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format.
26+
* The {@link Float32BinaryVector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format.
2727
*
2828
* @mongodb.server.release 6.0
29-
* @see Vector#floatVector(float[])
30-
* @see BsonBinary#BsonBinary(Vector)
29+
* @see BinaryVector#floatVector(float[])
30+
* @see BsonBinary#BsonBinary(BinaryVector)
3131
* @see BsonBinary#asVector()
3232
* @since 5.3
3333
*/
34-
public final class Float32Vector extends Vector {
34+
public final class Float32BinaryVector extends BinaryVector {
3535

3636
private final float[] data;
3737

38-
Float32Vector(final float[] vectorData) {
38+
Float32BinaryVector(final float[] vectorData) {
3939
super(DataType.FLOAT32);
4040
this.data = assertNotNull(vectorData);
4141
}
4242

4343
/**
44-
* Retrieve the underlying float array representing this {@link Float32Vector}, where each float
44+
* Retrieve the underlying float array representing this {@link Float32BinaryVector}, where each float
4545
* represents an element of a vector.
4646
* <p>
4747
* NOTE: The underlying float array is not copied; changes to the returned array will be reflected in this instance.
4848
*
49-
* @return the underlying float array representing this {@link Float32Vector} vector.
49+
* @return the underlying float array representing this {@link Float32BinaryVector} vector.
5050
*/
5151
public float[] getData() {
5252
return assertNotNull(data);
@@ -60,7 +60,7 @@ public boolean equals(final Object o) {
6060
if (o == null || getClass() != o.getClass()) {
6161
return false;
6262
}
63-
Float32Vector that = (Float32Vector) o;
63+
Float32BinaryVector that = (Float32BinaryVector) o;
6464
return Arrays.equals(data, that.data);
6565
}
6666

Diff for: bson/src/main/org/bson/Int8Vector.java renamed to bson/src/main/org/bson/Int8BinaryVector.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@
2424
/**
2525
* Represents a vector of 8-bit signed integers, where each element in the vector is a byte.
2626
* <p>
27-
* The {@link Int8Vector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format.
27+
* The {@link Int8BinaryVector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format.
2828
*
2929
* @mongodb.server.release 6.0
30-
* @see Vector#int8Vector(byte[])
31-
* @see BsonBinary#BsonBinary(Vector)
30+
* @see BinaryVector#int8Vector(byte[])
31+
* @see BsonBinary#BsonBinary(BinaryVector)
3232
* @see BsonBinary#asVector()
3333
* @since 5.3
3434
*/
35-
public final class Int8Vector extends Vector {
35+
public final class Int8BinaryVector extends BinaryVector {
3636

3737
private byte[] data;
3838

39-
Int8Vector(final byte[] data) {
39+
Int8BinaryVector(final byte[] data) {
4040
super(DataType.INT8);
4141
this.data = assertNotNull(data);
4242
}
4343

4444
/**
45-
* Retrieve the underlying byte array representing this {@link Int8Vector} vector, where each byte represents
45+
* Retrieve the underlying byte array representing this {@link Int8BinaryVector} vector, where each byte represents
4646
* an element of a vector.
4747
* <p>
4848
* NOTE: The underlying byte array is not copied; changes to the returned array will be reflected in this instance.
4949
*
50-
* @return the underlying byte array representing this {@link Int8Vector} vector.
50+
* @return the underlying byte array representing this {@link Int8BinaryVector} vector.
5151
*/
5252
public byte[] getData() {
5353
return assertNotNull(data);
@@ -61,7 +61,7 @@ public boolean equals(final Object o) {
6161
if (o == null || getClass() != o.getClass()) {
6262
return false;
6363
}
64-
Int8Vector that = (Int8Vector) o;
64+
Int8BinaryVector that = (Int8BinaryVector) o;
6565
return Objects.deepEquals(data, that.data);
6666
}
6767

Diff for: bson/src/main/org/bson/PackedBitVector.java renamed to bson/src/main/org/bson/PackedBitBinaryVector.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,33 @@
2424
/**
2525
* Represents a packed bit vector, where each element of the vector is represented by a single bit (0 or 1).
2626
* <p>
27-
* The {@link PackedBitVector} is used to store data efficiently using the BSON Binary Subtype 9 format.
27+
* The {@link PackedBitBinaryVector} is used to store data efficiently using the BSON Binary Subtype 9 format.
2828
*
2929
* @mongodb.server.release 6.0
30-
* @see Vector#packedBitVector(byte[], byte)
31-
* @see BsonBinary#BsonBinary(Vector)
30+
* @see BinaryVector#packedBitVector(byte[], byte)
31+
* @see BsonBinary#BsonBinary(BinaryVector)
3232
* @see BsonBinary#asVector()
3333
* @since 5.3
3434
*/
35-
public final class PackedBitVector extends Vector {
35+
public final class PackedBitBinaryVector extends BinaryVector {
3636

3737
private final byte padding;
3838
private final byte[] data;
3939

40-
PackedBitVector(final byte[] data, final byte padding) {
40+
PackedBitBinaryVector(final byte[] data, final byte padding) {
4141
super(DataType.PACKED_BIT);
4242
this.data = assertNotNull(data);
4343
this.padding = padding;
4444
}
4545

4646
/**
47-
* Retrieve the underlying byte array representing this {@link PackedBitVector} vector, where
47+
* Retrieve the underlying byte array representing this {@link PackedBitBinaryVector} vector, where
4848
* each bit represents an element of the vector (either 0 or 1).
4949
* <p>
5050
* Note that the {@linkplain #getPadding() padding value} should be considered when interpreting the final byte of the array,
5151
* as it indicates how many least-significant bits are to be ignored.
5252
*
53-
* @return the underlying byte array representing this {@link PackedBitVector} vector.
53+
* @return the underlying byte array representing this {@link PackedBitBinaryVector} vector.
5454
* @see #getPadding()
5555
*/
5656
public byte[] getData() {
@@ -81,7 +81,7 @@ public boolean equals(final Object o) {
8181
if (o == null || getClass() != o.getClass()) {
8282
return false;
8383
}
84-
PackedBitVector that = (PackedBitVector) o;
84+
PackedBitBinaryVector that = (PackedBitBinaryVector) o;
8585
return padding == that.padding && Arrays.equals(data, that.data);
8686
}
8787

Diff for: bson/src/main/org/bson/codecs/VectorCodec.java renamed to bson/src/main/org/bson/codecs/BinaryVectorCodec.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
import org.bson.BsonInvalidOperationException;
2222
import org.bson.BsonReader;
2323
import org.bson.BsonWriter;
24-
import org.bson.Vector;
24+
import org.bson.BinaryVector;
2525

2626
/**
27-
* Encodes and decodes {@link Vector} objects.
27+
* Encodes and decodes {@link BinaryVector} objects.
2828
*
2929
*/
30-
final class VectorCodec implements Codec<Vector> {
30+
final class BinaryVectorCodec implements Codec<BinaryVector> {
3131

3232
@Override
33-
public void encode(final BsonWriter writer, final Vector vectorToEncode, final EncoderContext encoderContext) {
33+
public void encode(final BsonWriter writer, final BinaryVector vectorToEncode, final EncoderContext encoderContext) {
3434
writer.writeBinaryData(new BsonBinary(vectorToEncode));
3535
}
3636

3737
@Override
38-
public Vector decode(final BsonReader reader, final DecoderContext decoderContext) {
38+
public BinaryVector decode(final BsonReader reader, final DecoderContext decoderContext) {
3939
byte subType = reader.peekBinarySubType();
4040

4141
if (subType != BsonBinarySubType.VECTOR.getValue()) {
@@ -48,8 +48,8 @@ public Vector decode(final BsonReader reader, final DecoderContext decoderContex
4848
}
4949

5050
@Override
51-
public Class<Vector> getEncoderClass() {
52-
return Vector.class;
51+
public Class<BinaryVector> getEncoderClass() {
52+
return BinaryVector.class;
5353
}
5454
}
5555

Diff for: bson/src/main/org/bson/codecs/ContainerCodecHelper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.bson.BsonType;
2222
import org.bson.Transformer;
2323
import org.bson.UuidRepresentation;
24-
import org.bson.Vector;
24+
import org.bson.BinaryVector;
2525
import org.bson.codecs.configuration.CodecConfigurationException;
2626
import org.bson.codecs.configuration.CodecRegistry;
2727

@@ -68,7 +68,7 @@ private static Codec<?> getBinarySubTypeCodec(final BsonReader reader,
6868
final Codec<?> binaryTypeCodec) {
6969

7070
if (binarySubType == BsonBinarySubType.VECTOR.getValue()) {
71-
Codec<Vector> vectorCodec = registry.get(Vector.class, registry);
71+
Codec<BinaryVector> vectorCodec = registry.get(BinaryVector.class, registry);
7272
if (vectorCodec != null) {
7373
return vectorCodec;
7474
}

0 commit comments

Comments
 (0)