Skip to content

Commit 2ecfa03

Browse files
authored
Remove FieldValue factory methods. (#5)
1 parent bba262d commit 2ecfa03

File tree

6 files changed

+106
-185
lines changed

6 files changed

+106
-185
lines changed

google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldValue.java

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -331,84 +331,6 @@ public static VectorValue vector(@Nonnull double[] values) {
331331
return new VectorValue(values);
332332
}
333333

334-
/**
335-
* Returns a {@link MinKey} value.
336-
*
337-
* @return A {@link MinKey} object which is the same as all MinKey objects.
338-
*/
339-
@Nonnull
340-
public static MinKey minKey() {
341-
return MinKey.instance();
342-
}
343-
344-
/**
345-
* Returns a {@link MaxKey} value.
346-
*
347-
* @return A {@link MaxKey} object which is the same as all MaxKey objects.
348-
*/
349-
@Nonnull
350-
public static MaxKey maxKey() {
351-
return MaxKey.instance();
352-
}
353-
354-
/**
355-
* Creates a new {@link RegexValue} constructed using the given pattern and options.
356-
*
357-
* @param pattern The pattern to use for the new regular expression.
358-
* @param options The options to use for the new regular expression.
359-
* @return A new {@link RegexValue} constructed using the given pattern and options.
360-
*/
361-
@Nonnull
362-
public static RegexValue regex(@Nonnull String pattern, @Nonnull String options) {
363-
return new RegexValue(pattern, options);
364-
}
365-
366-
/**
367-
* Creates a new {@link Int32Value} constructed using the given number.
368-
*
369-
* @param value The number to use for constructing the Int32Value object.
370-
* @return A new {@link Int32Value} constructed using the number.
371-
*/
372-
@Nonnull
373-
public static Int32Value int32(int value) {
374-
return new Int32Value(value);
375-
}
376-
377-
/**
378-
* Creates a new {@link BsonTimestamp} constructed using the given values.
379-
*
380-
* @param seconds The seconds value to use for the new BSON Timestamp.
381-
* @param increment The increment value to use for the new BSON Timestamp.
382-
* @return A new {@link BsonTimestamp} constructed using the given values.
383-
*/
384-
@Nonnull
385-
public static BsonTimestamp bsonTimestamp(long seconds, long increment) {
386-
return new BsonTimestamp(seconds, increment);
387-
}
388-
389-
/**
390-
* Creates a new {@link BsonObjectId} constructed using the given value.
391-
*
392-
* @param oid The 24-character hex string representation of the ObjectId.
393-
* @return A new {@link BsonObjectId} constructed using the given value.
394-
*/
395-
@Nonnull
396-
public static BsonObjectId bsonObjectId(@Nonnull String oid) {
397-
return new BsonObjectId(oid);
398-
}
399-
400-
/**
401-
* Creates a new {@link BsonBinaryData} constructed using the given values.
402-
*
403-
* @param data The data to use for the new instance as a binary array.
404-
* @param subtype The subtype to use for the new instance.
405-
* @return A new {@link BsonBinaryData} constructed using the given values.
406-
*/
407-
@Nonnull
408-
public static BsonBinaryData bsonBinaryData(int subtype, @Nonnull byte[] data) {
409-
return BsonBinaryData.fromBytes(subtype, data);
410-
}
411-
412334
/** Whether this FieldTransform should be included in the document mask. */
413335
abstract boolean includeInDocumentMask();
414336

google-cloud-firestore/src/test/java/com/google/cloud/firestore/ExtendedTypesTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@ void assertEncodesAndDecodesCorrectly(Value proto, Object object) {
5252

5353
@Test
5454
public void minKeyIsSingleton() {
55-
MinKey minKey1 = FieldValue.minKey();
55+
MinKey minKey1 = MinKey.instance();
5656
MinKey minKey2 = MinKey.instance();
5757
assertThat(minKey1).isEqualTo(minKey2);
58-
assertThat(minKey1).isNotEqualTo(FieldValue.maxKey());
58+
assertThat(minKey1).isNotEqualTo(MaxKey.instance());
5959
}
6060

6161
@Test
6262
public void maxKeyIsSingleton() {
63-
MaxKey maxKey1 = FieldValue.maxKey();
63+
MaxKey maxKey1 = MaxKey.instance();
6464
MaxKey maxKey2 = MaxKey.instance();
6565
assertThat(maxKey1).isEqualTo(maxKey2);
66-
assertThat(maxKey1).isNotEqualTo(FieldValue.minKey());
66+
assertThat(maxKey1).isNotEqualTo(MinKey.instance());
6767
}
6868

6969
@Test
7070
public void regexFieldsAndEquality() {
71-
RegexValue regex1 = FieldValue.regex("^foo", "i");
71+
RegexValue regex1 = new RegexValue("^foo", "i");
7272
RegexValue regex2 = new RegexValue("^foo", "i");
7373
RegexValue regex3 = new RegexValue("^foo", "x");
7474
RegexValue regex4 = new RegexValue("^bar", "i");
@@ -82,7 +82,7 @@ public void regexFieldsAndEquality() {
8282

8383
@Test
8484
public void Int32ValueAndEquality() {
85-
Int32Value i1 = FieldValue.int32(123);
85+
Int32Value i1 = new Int32Value(123);
8686
Int32Value i2 = new Int32Value(123);
8787
Int32Value i3 = new Int32Value(456);
8888

@@ -93,7 +93,7 @@ public void Int32ValueAndEquality() {
9393

9494
@Test
9595
public void BsonObjectIdValueAndEquality() {
96-
BsonObjectId oid1 = FieldValue.bsonObjectId("foo");
96+
BsonObjectId oid1 = new BsonObjectId("foo");
9797
BsonObjectId oid2 = new BsonObjectId("foo");
9898
BsonObjectId oid3 = new BsonObjectId("bar");
9999

@@ -104,7 +104,7 @@ public void BsonObjectIdValueAndEquality() {
104104

105105
@Test
106106
public void BsonTimestampValuesAndEquality() {
107-
BsonTimestamp t1 = FieldValue.bsonTimestamp(123, 456);
107+
BsonTimestamp t1 = new BsonTimestamp(123, 456);
108108
BsonTimestamp t2 = new BsonTimestamp(123, 456);
109109
BsonTimestamp t3 = new BsonTimestamp(124, 456);
110110
BsonTimestamp t4 = new BsonTimestamp(123, 457);
@@ -118,7 +118,7 @@ public void BsonTimestampValuesAndEquality() {
118118

119119
@Test
120120
public void BsonBinaryDataValuesAndEquality() {
121-
BsonBinaryData b1 = FieldValue.bsonBinaryData(127, new byte[] {1, 2, 3});
121+
BsonBinaryData b1 = BsonBinaryData.fromBytes(127, new byte[] {1, 2, 3});
122122
BsonBinaryData b2 = BsonBinaryData.fromBytes(127, new byte[] {1, 2, 3});
123123
BsonBinaryData b3 = BsonBinaryData.fromBytes(1, new byte[] {1, 2, 3});
124124
BsonBinaryData b4 = BsonBinaryData.fromBytes(127, new byte[] {1, 2, 4});
@@ -133,8 +133,8 @@ public void BsonBinaryDataValuesAndEquality() {
133133
@Test
134134
public void BsonBinaryDataConvertsByteToIntAndIntToByteCorrectly() {
135135
byte[] data = new byte[] {1, 2, 3};
136-
BsonBinaryData b1 = FieldValue.bsonBinaryData(127, data); // 0x7F - MSB:0
137-
BsonBinaryData b2 = FieldValue.bsonBinaryData(128, data); // 0x80 - MSB:1
136+
BsonBinaryData b1 = BsonBinaryData.fromBytes(127, data); // 0x7F - MSB:0
137+
BsonBinaryData b2 = BsonBinaryData.fromBytes(128, data); // 0x80 - MSB:1
138138
BsonBinaryData b3 = BsonBinaryData.fromBytes(255, data); // 0xFF - MSB:1
139139

140140
BsonBinaryData b4 = UserDataConverter.decodeBsonBinary(b1.toProto());
@@ -267,7 +267,7 @@ public void BsonTimestampValidation() {
267267
// Negative seconds
268268
IllegalArgumentException error1 = null;
269269
try {
270-
BsonTimestamp t1 = FieldValue.bsonTimestamp(-1, 1);
270+
BsonTimestamp t1 = new BsonTimestamp(-1, 1);
271271
} catch (IllegalArgumentException e) {
272272
error1 = e;
273273
}
@@ -278,7 +278,7 @@ public void BsonTimestampValidation() {
278278
// Larger than 2^32-1 seconds
279279
IllegalArgumentException error2 = null;
280280
try {
281-
BsonTimestamp t1 = FieldValue.bsonTimestamp(4294967296L, 1);
281+
BsonTimestamp t1 = new BsonTimestamp(4294967296L, 1);
282282
} catch (IllegalArgumentException e) {
283283
error2 = e;
284284
}
@@ -289,7 +289,7 @@ public void BsonTimestampValidation() {
289289
// Negative increment
290290
IllegalArgumentException error3 = null;
291291
try {
292-
BsonTimestamp t1 = FieldValue.bsonTimestamp(1234, -1);
292+
BsonTimestamp t1 = new BsonTimestamp(1234, -1);
293293
} catch (IllegalArgumentException e) {
294294
error3 = e;
295295
}
@@ -300,7 +300,7 @@ public void BsonTimestampValidation() {
300300
// Larger than 2^32-1 increment
301301
IllegalArgumentException error4 = null;
302302
try {
303-
BsonTimestamp t1 = FieldValue.bsonTimestamp(123, 4294967296L);
303+
BsonTimestamp t1 = new BsonTimestamp(123, 4294967296L);
304304
} catch (IllegalArgumentException e) {
305305
error4 = e;
306306
}
@@ -311,7 +311,7 @@ public void BsonTimestampValidation() {
311311

312312
@Test
313313
public void canEncodeAndDecodeMinKey() {
314-
MinKey minKey = FieldValue.minKey();
314+
MinKey minKey = MinKey.instance();
315315
Value proto =
316316
Value.newBuilder()
317317
.setMapValue(
@@ -325,7 +325,7 @@ public void canEncodeAndDecodeMinKey() {
325325

326326
@Test
327327
public void canEncodeAndDecodeMaxKey() {
328-
MaxKey maxKey = FieldValue.maxKey();
328+
MaxKey maxKey = MaxKey.instance();
329329
Value proto =
330330
Value.newBuilder()
331331
.setMapValue(
@@ -389,7 +389,7 @@ public void canEncodeAndDecodeBsonObjectId() {
389389

390390
@Test
391391
public void canEncodeAndDecodeBsonTimestamp() {
392-
BsonTimestamp bsonTimestamp = FieldValue.bsonTimestamp(12345, 67);
392+
BsonTimestamp bsonTimestamp = new BsonTimestamp(12345, 67);
393393
Value proto =
394394
Value.newBuilder()
395395
.setMapValue(
@@ -413,7 +413,7 @@ public void canEncodeAndDecodeBsonTimestamp() {
413413

414414
@Test
415415
public void canEncodeAndDecodeBsonBinaryData() {
416-
BsonBinaryData bsonBinaryData = FieldValue.bsonBinaryData(127, new byte[] {1, 2, 3});
416+
BsonBinaryData bsonBinaryData = BsonBinaryData.fromBytes(127, new byte[] {1, 2, 3});
417417
Value proto =
418418
Value.newBuilder()
419419
.setMapValue(

google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -980,13 +980,13 @@ public static class AllSupportedTypes {
980980
public GeoPoint geoPointValue = GEO_POINT;
981981
public Map<String, Object> model = ImmutableMap.of("foo", SINGLE_FIELD_OBJECT.foo);
982982
public VectorValue vectorValue = FieldValue.vector(new double[] {0.1, 0.2, 0.3});
983-
public MinKey minKey = FieldValue.minKey();
984-
public MaxKey maxKey = FieldValue.maxKey();
985-
public RegexValue regexValue = FieldValue.regex("^foo", "i");
986-
public Int32Value int32Value = FieldValue.int32(55);
987-
public BsonObjectId bsonObjectId = FieldValue.bsonObjectId("507f191e810c19729de860eb");
988-
public BsonTimestamp bsonTimestamp = FieldValue.bsonTimestamp(100, 10);
989-
public BsonBinaryData bsonBinaryData = FieldValue.bsonBinaryData(127, new byte[] {1, 2, 3});
983+
public MinKey minKey = MinKey.instance();
984+
public MaxKey maxKey = MaxKey.instance();
985+
public RegexValue regexValue = new RegexValue("^foo", "i");
986+
public Int32Value int32Value = new Int32Value(55);
987+
public BsonObjectId bsonObjectId = new BsonObjectId("507f191e810c19729de860eb");
988+
public BsonTimestamp bsonTimestamp = new BsonTimestamp(100, 10);
989+
public BsonBinaryData bsonBinaryData = BsonBinaryData.fromBytes(127, new byte[] {1, 2, 3});
990990

991991
@Override
992992
public boolean equals(Object o) {
@@ -1143,15 +1143,14 @@ public boolean equals(Object o) {
11431143
ALL_SUPPORTED_TYPES_MAP.put("geoPointValue", GEO_POINT);
11441144
ALL_SUPPORTED_TYPES_MAP.put("model", map("foo", SINGLE_FIELD_OBJECT.foo));
11451145
ALL_SUPPORTED_TYPES_MAP.put("vectorValue", FieldValue.vector(new double[] {0.1, 0.2, 0.3}));
1146-
ALL_SUPPORTED_TYPES_MAP.put("minKey", FieldValue.minKey());
1147-
ALL_SUPPORTED_TYPES_MAP.put("maxKey", FieldValue.maxKey());
1148-
ALL_SUPPORTED_TYPES_MAP.put("regexValue", FieldValue.regex("^foo", "i"));
1149-
ALL_SUPPORTED_TYPES_MAP.put("int32Value", FieldValue.int32(55));
1146+
ALL_SUPPORTED_TYPES_MAP.put("minKey", MinKey.instance());
1147+
ALL_SUPPORTED_TYPES_MAP.put("maxKey", MaxKey.instance());
1148+
ALL_SUPPORTED_TYPES_MAP.put("regexValue", new RegexValue("^foo", "i"));
1149+
ALL_SUPPORTED_TYPES_MAP.put("int32Value", new Int32Value(55));
1150+
ALL_SUPPORTED_TYPES_MAP.put("bsonObjectId", new BsonObjectId("507f191e810c19729de860eb"));
1151+
ALL_SUPPORTED_TYPES_MAP.put("bsonTimestamp", new BsonTimestamp(100, 10));
11501152
ALL_SUPPORTED_TYPES_MAP.put(
1151-
"bsonObjectId", FieldValue.bsonObjectId("507f191e810c19729de860eb"));
1152-
ALL_SUPPORTED_TYPES_MAP.put("bsonTimestamp", FieldValue.bsonTimestamp(100, 10));
1153-
ALL_SUPPORTED_TYPES_MAP.put(
1154-
"bsonBinaryData", FieldValue.bsonBinaryData(127, new byte[] {1, 2, 3}));
1153+
"bsonBinaryData", BsonBinaryData.fromBytes(127, new byte[] {1, 2, 3}));
11551154
ALL_SUPPORTED_TYPES_PROTO =
11561155
ImmutableMap.<String, Value>builder()
11571156
.put("foo", Value.newBuilder().setStringValue("bar").build())

google-cloud-firestore/src/test/java/com/google/cloud/firestore/OrderTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,24 @@ private Value maxKeyValue() {
213213
}
214214

215215
private Value regexValue(String pattern, String options) {
216-
return Value.newBuilder().setMapValue(FieldValue.regex(pattern, options).toProto()).build();
216+
return Value.newBuilder().setMapValue(new RegexValue(pattern, options).toProto()).build();
217217
}
218218

219219
private Value int32Value(int value) {
220-
return Value.newBuilder().setMapValue(FieldValue.int32(value).toProto()).build();
220+
return Value.newBuilder().setMapValue(new Int32Value(value).toProto()).build();
221221
}
222222

223223
private Value bsonObjectIdValue(String oid) {
224-
return Value.newBuilder().setMapValue(FieldValue.bsonObjectId(oid).toProto()).build();
224+
return Value.newBuilder().setMapValue(new BsonObjectId(oid).toProto()).build();
225225
}
226226

227227
private Value bsonTimestampValue(long seconds, long increment) {
228-
return Value.newBuilder()
229-
.setMapValue(FieldValue.bsonTimestamp(seconds, increment).toProto())
230-
.build();
228+
return Value.newBuilder().setMapValue(new BsonTimestamp(seconds, increment).toProto()).build();
231229
}
232230

233231
private Value bsonBinaryData(int subtype, byte[] data) {
234232
return Value.newBuilder()
235-
.setMapValue(FieldValue.bsonBinaryData(subtype, data).toProto())
233+
.setMapValue(BsonBinaryData.fromBytes(subtype, data).toProto())
236234
.build();
237235
}
238236

0 commit comments

Comments
 (0)