Skip to content

Rename Vector class names. #1595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
* @see BsonBinary
* @since 5.3
*/
public abstract class Vector {
public abstract class BinaryVector {
private final DataType dataType;

Vector(final DataType dataType) {
BinaryVector(final DataType dataType) {
this.dataType = dataType;
}

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

/**
Expand All @@ -77,14 +77,14 @@ public static PackedBitVector packedBitVector(final byte[] data, final byte padd
* with values in the range [-128, 127].</p>
* <p>
* NOTE: The byte array `data` is not copied; changes to the provided array will be reflected
* in the created {@link Int8Vector} instance.
* in the created {@link Int8BinaryVector} instance.
*
* @param data The byte array representing the {@link DataType#INT8} vector data.
* @return A {@link Int8Vector} instance with the {@link DataType#INT8} data type.
* @return A {@link Int8BinaryVector} instance with the {@link DataType#INT8} data type.
*/
public static Int8Vector int8Vector(final byte[] data) {
public static Int8BinaryVector int8Vector(final byte[] data) {
notNull("data", data);
return new Int8Vector(data);
return new Int8BinaryVector(data);
}

/**
Expand All @@ -93,50 +93,50 @@ public static Int8Vector int8Vector(final byte[] data) {
* A {@link DataType#FLOAT32} vector is a vector of floating-point numbers, where each element in the vector is a float.</p>
* <p>
* NOTE: The float array `data` is not copied; changes to the provided array will be reflected
* in the created {@link Float32Vector} instance.
* in the created {@link Float32BinaryVector} instance.
*
* @param data The float array representing the {@link DataType#FLOAT32} vector data.
* @return A {@link Float32Vector} instance with the {@link DataType#FLOAT32} data type.
* @return A {@link Float32BinaryVector} instance with the {@link DataType#FLOAT32} data type.
*/
public static Float32Vector floatVector(final float[] data) {
public static Float32BinaryVector floatVector(final float[] data) {
notNull("data", data);
return new Float32Vector(data);
return new Float32BinaryVector(data);
}

/**
* Returns the {@link PackedBitVector}.
* Returns the {@link PackedBitBinaryVector}.
*
* @return {@link PackedBitVector}.
* @return {@link PackedBitBinaryVector}.
* @throws IllegalStateException if this vector is not of type {@link DataType#PACKED_BIT}. Use {@link #getDataType()} to check the vector
* type before calling this method.
*/
public PackedBitVector asPackedBitVector() {
public PackedBitBinaryVector asPackedBitVector() {
ensureType(DataType.PACKED_BIT);
return (PackedBitVector) this;
return (PackedBitBinaryVector) this;
}

/**
* Returns the {@link Int8Vector}.
* Returns the {@link Int8BinaryVector}.
*
* @return {@link Int8Vector}.
* @return {@link Int8BinaryVector}.
* @throws IllegalStateException if this vector is not of type {@link DataType#INT8}. Use {@link #getDataType()} to check the vector
* type before calling this method.
*/
public Int8Vector asInt8Vector() {
public Int8BinaryVector asInt8Vector() {
ensureType(DataType.INT8);
return (Int8Vector) this;
return (Int8BinaryVector) this;
}

/**
* Returns the {@link Float32Vector}.
* Returns the {@link Float32BinaryVector}.
*
* @return {@link Float32Vector}.
* @return {@link Float32BinaryVector}.
* @throws IllegalStateException if this vector is not of type {@link DataType#FLOAT32}. Use {@link #getDataType()} to check the vector
* type before calling this method.
*/
public Float32Vector asFloat32Vector() {
public Float32BinaryVector asFloat32Vector() {
ensureType(DataType.FLOAT32);
return (Float32Vector) this;
return (Float32BinaryVector) this;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions bson/src/main/org/bson/BsonBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ public BsonBinary(final UUID uuid) {
}

/**
* Constructs a {@linkplain BsonBinarySubType#VECTOR subtype 9} {@link BsonBinary} from the given {@link Vector}.
* Constructs a {@linkplain BsonBinarySubType#VECTOR subtype 9} {@link BsonBinary} from the given {@link BinaryVector}.
*
* @param vector the {@link Vector}
* @param vector the {@link BinaryVector}
* @since 5.3
*/
public BsonBinary(final Vector vector) {
public BsonBinary(final BinaryVector vector) {
if (vector == null) {
throw new IllegalArgumentException("Vector must not be null");
}
Expand Down Expand Up @@ -145,13 +145,13 @@ public UUID asUuid() {
}

/**
* Returns the binary as a {@link Vector}. The {@linkplain #getType() subtype} must be {@linkplain BsonBinarySubType#VECTOR 9}.
* Returns the binary as a {@link BinaryVector}. The {@linkplain #getType() subtype} must be {@linkplain BsonBinarySubType#VECTOR 9}.
*
* @return the vector
* @throws BsonInvalidOperationException if the binary subtype is not {@link BsonBinarySubType#VECTOR}.
* @since 5.3
*/
public Vector asVector() {
public BinaryVector asVector() {
if (type != BsonBinarySubType.VECTOR.getValue()) {
throw new BsonInvalidOperationException("type must be a Vector subtype.");
}
Expand Down
2 changes: 1 addition & 1 deletion bson/src/main/org/bson/BsonBinarySubType.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public enum BsonBinarySubType {
*
* @mongodb.server.release 6.0
* @since 5.3
* @see Vector
* @see BinaryVector
*/
VECTOR((byte) 0x09),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@
/**
* Represents a vector of 32-bit floating-point numbers, where each element in the vector is a float.
* <p>
* The {@link Float32Vector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format.
* The {@link Float32BinaryVector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format.
*
* @mongodb.server.release 6.0
* @see Vector#floatVector(float[])
* @see BsonBinary#BsonBinary(Vector)
* @see BinaryVector#floatVector(float[])
* @see BsonBinary#BsonBinary(BinaryVector)
* @see BsonBinary#asVector()
* @since 5.3
*/
public final class Float32Vector extends Vector {
public final class Float32BinaryVector extends BinaryVector {

private final float[] data;

Float32Vector(final float[] vectorData) {
Float32BinaryVector(final float[] vectorData) {
super(DataType.FLOAT32);
this.data = assertNotNull(vectorData);
}

/**
* Retrieve the underlying float array representing this {@link Float32Vector}, where each float
* Retrieve the underlying float array representing this {@link Float32BinaryVector}, where each float
* represents an element of a vector.
* <p>
* NOTE: The underlying float array is not copied; changes to the returned array will be reflected in this instance.
*
* @return the underlying float array representing this {@link Float32Vector} vector.
* @return the underlying float array representing this {@link Float32BinaryVector} vector.
*/
public float[] getData() {
return assertNotNull(data);
Expand All @@ -60,7 +60,7 @@ public boolean equals(final Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
Float32Vector that = (Float32Vector) o;
Float32BinaryVector that = (Float32BinaryVector) o;
return Arrays.equals(data, that.data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@
/**
* Represents a vector of 8-bit signed integers, where each element in the vector is a byte.
* <p>
* The {@link Int8Vector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format.
* The {@link Int8BinaryVector} is used to store and retrieve data efficiently using the BSON Binary Subtype 9 format.
*
* @mongodb.server.release 6.0
* @see Vector#int8Vector(byte[])
* @see BsonBinary#BsonBinary(Vector)
* @see BinaryVector#int8Vector(byte[])
* @see BsonBinary#BsonBinary(BinaryVector)
* @see BsonBinary#asVector()
* @since 5.3
*/
public final class Int8Vector extends Vector {
public final class Int8BinaryVector extends BinaryVector {

private byte[] data;

Int8Vector(final byte[] data) {
Int8BinaryVector(final byte[] data) {
super(DataType.INT8);
this.data = assertNotNull(data);
}

/**
* Retrieve the underlying byte array representing this {@link Int8Vector} vector, where each byte represents
* Retrieve the underlying byte array representing this {@link Int8BinaryVector} vector, where each byte represents
* an element of a vector.
* <p>
* NOTE: The underlying byte array is not copied; changes to the returned array will be reflected in this instance.
*
* @return the underlying byte array representing this {@link Int8Vector} vector.
* @return the underlying byte array representing this {@link Int8BinaryVector} vector.
*/
public byte[] getData() {
return assertNotNull(data);
Expand All @@ -61,7 +61,7 @@ public boolean equals(final Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
Int8Vector that = (Int8Vector) o;
Int8BinaryVector that = (Int8BinaryVector) o;
return Objects.deepEquals(data, that.data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@
/**
* Represents a packed bit vector, where each element of the vector is represented by a single bit (0 or 1).
* <p>
* The {@link PackedBitVector} is used to store data efficiently using the BSON Binary Subtype 9 format.
* The {@link PackedBitBinaryVector} is used to store data efficiently using the BSON Binary Subtype 9 format.
*
* @mongodb.server.release 6.0
* @see Vector#packedBitVector(byte[], byte)
* @see BsonBinary#BsonBinary(Vector)
* @see BinaryVector#packedBitVector(byte[], byte)
* @see BsonBinary#BsonBinary(BinaryVector)
* @see BsonBinary#asVector()
* @since 5.3
*/
public final class PackedBitVector extends Vector {
public final class PackedBitBinaryVector extends BinaryVector {

private final byte padding;
private final byte[] data;

PackedBitVector(final byte[] data, final byte padding) {
PackedBitBinaryVector(final byte[] data, final byte padding) {
super(DataType.PACKED_BIT);
this.data = assertNotNull(data);
this.padding = padding;
}

/**
* Retrieve the underlying byte array representing this {@link PackedBitVector} vector, where
* Retrieve the underlying byte array representing this {@link PackedBitBinaryVector} vector, where
* each bit represents an element of the vector (either 0 or 1).
* <p>
* Note that the {@linkplain #getPadding() padding value} should be considered when interpreting the final byte of the array,
* as it indicates how many least-significant bits are to be ignored.
*
* @return the underlying byte array representing this {@link PackedBitVector} vector.
* @return the underlying byte array representing this {@link PackedBitBinaryVector} vector.
* @see #getPadding()
*/
public byte[] getData() {
Expand Down Expand Up @@ -81,7 +81,7 @@ public boolean equals(final Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
PackedBitVector that = (PackedBitVector) o;
PackedBitBinaryVector that = (PackedBitBinaryVector) o;
return padding == that.padding && Arrays.equals(data, that.data);
}

Expand Down
4 changes: 2 additions & 2 deletions bson/src/main/org/bson/codecs/ContainerCodecHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.bson.BsonType;
import org.bson.Transformer;
import org.bson.UuidRepresentation;
import org.bson.Vector;
import org.bson.BinaryVector;
import org.bson.codecs.configuration.CodecConfigurationException;
import org.bson.codecs.configuration.CodecRegistry;

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

if (binarySubType == BsonBinarySubType.VECTOR.getValue()) {
Codec<Vector> vectorCodec = registry.get(Vector.class, registry);
Codec<BinaryVector> vectorCodec = registry.get(BinaryVector.class, registry);
if (vectorCodec != null) {
return vectorCodec;
}
Expand Down
14 changes: 7 additions & 7 deletions bson/src/main/org/bson/codecs/Float32VectorCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
import org.bson.BsonInvalidOperationException;
import org.bson.BsonReader;
import org.bson.BsonWriter;
import org.bson.Float32Vector;
import org.bson.Float32BinaryVector;

/**
* Encodes and decodes {@link Float32Vector} objects.
* Encodes and decodes {@link Float32BinaryVector} objects.
*
*/
final class Float32VectorCodec implements Codec<Float32Vector> {
final class Float32VectorCodec implements Codec<Float32BinaryVector> {

@Override
public void encode(final BsonWriter writer, final Float32Vector vectorToEncode, final EncoderContext encoderContext) {
public void encode(final BsonWriter writer, final Float32BinaryVector vectorToEncode, final EncoderContext encoderContext) {
writer.writeBinaryData(new BsonBinary(vectorToEncode));
}

@Override
public Float32Vector decode(final BsonReader reader, final DecoderContext decoderContext) {
public Float32BinaryVector decode(final BsonReader reader, final DecoderContext decoderContext) {
byte subType = reader.peekBinarySubType();

if (subType != BsonBinarySubType.VECTOR.getValue()) {
Expand All @@ -49,8 +49,8 @@ public Float32Vector decode(final BsonReader reader, final DecoderContext decode
}

@Override
public Class<Float32Vector> getEncoderClass() {
return Float32Vector.class;
public Class<Float32BinaryVector> getEncoderClass() {
return Float32BinaryVector.class;
}
}

Loading