Skip to content

Commit 6df2d8a

Browse files
committed
Fix formatting
1 parent 8163c95 commit 6df2d8a

File tree

10 files changed

+222
-196
lines changed

10 files changed

+222
-196
lines changed

google-cloud-datastore/src/main/java/com/google/cloud/datastore/FindNearest.java

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@
1818

1919
import com.google.common.base.MoreObjects;
2020
import com.google.common.base.MoreObjects.ToStringHelper;
21-
import com.google.protobuf.ByteString;
2221
import com.google.protobuf.DoubleValue;
2322
import com.google.protobuf.Int32Value;
24-
2523
import java.io.Serializable;
2624
import java.util.Objects;
27-
2825
import javax.annotation.Nullable;
2926

30-
3127
/**
32-
* A query that finds the entities whose vector fields are closest to a certain query vector.
33-
* Create an instance of `FindNearest` with {@link Query#findNearest}.
28+
* A query that finds the entities whose vector fields are closest to a certain query vector. Create
29+
* an instance of `FindNearest` with {@link Query#findNearest}.
3430
*/
3531
public final class FindNearest implements Serializable {
3632

@@ -48,7 +44,13 @@ public final class FindNearest implements Serializable {
4844
private static final long serialVersionUID = 4688656124180403551L;
4945

5046
/** Creates a VectorQuery */
51-
public FindNearest(String vectorProperty, VectorValue queryVector, DistanceMeasure measure, int limit, @Nullable String distanceResultField,@Nullable Double distanceThreshold) {
47+
public FindNearest(
48+
String vectorProperty,
49+
VectorValue queryVector,
50+
DistanceMeasure measure,
51+
int limit,
52+
@Nullable String distanceResultField,
53+
@Nullable Double distanceThreshold) {
5254
this.vectorProperty = vectorProperty;
5355
this.queryVector = queryVector;
5456
this.measure = measure;
@@ -57,21 +59,33 @@ public FindNearest(String vectorProperty, VectorValue queryVector, DistanceMeasu
5759
this.distanceThreshold = distanceThreshold;
5860
}
5961

60-
public FindNearest(String vectorProperty, VectorValue queryVector, DistanceMeasure measure, int limit) {
62+
public FindNearest(
63+
String vectorProperty, VectorValue queryVector, DistanceMeasure measure, int limit) {
6164
this(vectorProperty, queryVector, measure, limit, null, null);
6265
}
6366

64-
public FindNearest(String vectorProperty, VectorValue queryVector, DistanceMeasure measure, int limit, @Nullable String distanceResultField) {
67+
public FindNearest(
68+
String vectorProperty,
69+
VectorValue queryVector,
70+
DistanceMeasure measure,
71+
int limit,
72+
@Nullable String distanceResultField) {
6573
this(vectorProperty, queryVector, measure, limit, distanceResultField, null);
6674
}
6775

68-
public FindNearest(String vectorProperty, VectorValue queryVector, DistanceMeasure measure, int limit, @Nullable Double distanceThreshold) {
76+
public FindNearest(
77+
String vectorProperty,
78+
VectorValue queryVector,
79+
DistanceMeasure measure,
80+
int limit,
81+
@Nullable Double distanceThreshold) {
6982
this(vectorProperty, queryVector, measure, limit, null, distanceThreshold);
7083
}
7184

7285
@Override
7386
public int hashCode() {
74-
return Objects.hash(vectorProperty, queryVector, measure, limit, distanceResultField, distanceThreshold);
87+
return Objects.hash(
88+
vectorProperty, queryVector, measure, limit, distanceResultField, distanceThreshold);
7589
}
7690

7791
/**
@@ -90,11 +104,11 @@ public boolean equals(Object obj) {
90104
}
91105
FindNearest otherQuery = (FindNearest) obj;
92106
return Objects.equals(vectorProperty, otherQuery.vectorProperty)
93-
&& Objects.equals(queryVector, otherQuery.queryVector)
94-
&& Objects.equals(distanceResultField, otherQuery.distanceResultField)
95-
&& Objects.equals(distanceThreshold, otherQuery.distanceThreshold)
96-
&& limit == otherQuery.limit
97-
&& measure == otherQuery.measure;
107+
&& Objects.equals(queryVector, otherQuery.queryVector)
108+
&& Objects.equals(distanceResultField, otherQuery.distanceResultField)
109+
&& Objects.equals(distanceThreshold, otherQuery.distanceThreshold)
110+
&& limit == otherQuery.limit
111+
&& measure == otherQuery.measure;
98112
}
99113

100114
@Override
@@ -111,22 +125,38 @@ public String toString() {
111125

112126
static FindNearest fromPb(com.google.datastore.v1.FindNearest findNearestPb) {
113127
String vectorProperty = findNearestPb.getVectorProperty().getName();
114-
VectorValue queryVector = VectorValue.MARSHALLER.fromProto(findNearestPb.getQueryVector()).build();
115-
DistanceMeasure distanceMeasure = DistanceMeasure.valueOf(findNearestPb.getDistanceMeasure().toString());
128+
VectorValue queryVector =
129+
VectorValue.MARSHALLER.fromProto(findNearestPb.getQueryVector()).build();
130+
DistanceMeasure distanceMeasure =
131+
DistanceMeasure.valueOf(findNearestPb.getDistanceMeasure().toString());
116132
int limit = findNearestPb.getLimit().getValue();
117-
String distanceResultField = findNearestPb.getDistanceResultProperty() == null || findNearestPb.getDistanceResultProperty().isEmpty() ? null:findNearestPb.getDistanceResultProperty();
118-
Double distanceThreshold = findNearestPb.getDistanceThreshold() == null || findNearestPb.getDistanceThreshold() == DoubleValue.getDefaultInstance() ? null : findNearestPb.getDistanceThreshold().getValue();
119-
return new FindNearest(vectorProperty,queryVector, distanceMeasure, limit, distanceResultField, distanceThreshold);
133+
String distanceResultField =
134+
findNearestPb.getDistanceResultProperty() == null
135+
|| findNearestPb.getDistanceResultProperty().isEmpty()
136+
? null
137+
: findNearestPb.getDistanceResultProperty();
138+
Double distanceThreshold =
139+
findNearestPb.getDistanceThreshold() == null
140+
|| findNearestPb.getDistanceThreshold() == DoubleValue.getDefaultInstance()
141+
? null
142+
: findNearestPb.getDistanceThreshold().getValue();
143+
return new FindNearest(
144+
vectorProperty,
145+
queryVector,
146+
distanceMeasure,
147+
limit,
148+
distanceResultField,
149+
distanceThreshold);
120150
}
121151

122152
com.google.datastore.v1.FindNearest toPb() {
123-
com.google.datastore.v1.FindNearest.Builder findNearestPb = com.google.datastore.v1.FindNearest.newBuilder();
153+
com.google.datastore.v1.FindNearest.Builder findNearestPb =
154+
com.google.datastore.v1.FindNearest.newBuilder();
124155
findNearestPb.getVectorPropertyBuilder().setName(vectorProperty);
125156
findNearestPb.setQueryVector(queryVector.toPb());
126157
findNearestPb.setDistanceMeasure(toProto(measure));
127158
findNearestPb.setLimit(Int32Value.of(limit));
128-
if (distanceResultField != null)
129-
{
159+
if (distanceResultField != null) {
130160
findNearestPb.setDistanceResultProperty(distanceResultField);
131161
}
132162
if (distanceThreshold != null) {
@@ -136,7 +166,7 @@ com.google.datastore.v1.FindNearest toPb() {
136166
}
137167

138168
protected static com.google.datastore.v1.FindNearest.DistanceMeasure toProto(
139-
DistanceMeasure distanceMeasure) {
169+
DistanceMeasure distanceMeasure) {
140170
switch (distanceMeasure) {
141171
case COSINE:
142172
return com.google.datastore.v1.FindNearest.DistanceMeasure.COSINE;
@@ -152,7 +182,7 @@ protected static com.google.datastore.v1.FindNearest.DistanceMeasure toProto(
152182
/**
153183
* The distance measure to use when comparing vectors in a {@link FindNearest query}.
154184
*
155-
* @see com.google.cloud.firestore.Query#findNearest
185+
* @see com.google.cloud.datastore.Query#findNearest
156186
*/
157187
public enum DistanceMeasure {
158188
/**

google-cloud-datastore/src/main/java/com/google/cloud/datastore/Value.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,10 @@ com.google.datastore.v1.Value toPb() {
215215
public static Value<?> fromPb(com.google.datastore.v1.Value proto) {
216216
ValueTypeCase descriptorId = proto.getValueTypeCase();
217217
ValueType valueType = ValueType.getByDescriptorId(descriptorId.getNumber());
218-
if (valueType == null)
219-
return RawValue.MARSHALLER.fromProto(proto).build();
218+
if (valueType == null) return RawValue.MARSHALLER.fromProto(proto).build();
220219

221220
Value<?> returnValue = valueType.getMarshaller().fromProto(proto).build();
222-
if (valueType == ValueType.LIST && proto.getMeaning() == VECTOR_MEANING)
223-
{
221+
if (valueType == ValueType.LIST && proto.getMeaning() == VECTOR_MEANING) {
224222
for (com.google.datastore.v1.Value item : proto.getArrayValue().getValuesList()) {
225223
if (item.getValueTypeCase() != ValueTypeCase.DOUBLE_VALUE) {
226224
return returnValue;

0 commit comments

Comments
 (0)