From 7a3b297a8766bf6c43c024e410f50a84301e3532 Mon Sep 17 00:00:00 2001
From: "release-please[bot]"
<55107282+release-please[bot]@users.noreply.github.com>
Date: Wed, 11 Aug 2021 23:00:41 +0000
Subject: [PATCH 01/11] chore: release 3.0.2-SNAPSHOT (#730)
:robot: I have created a release \*beep\* \*boop\*
---
### Updating meta-information for bleeding-edge SNAPSHOT release.
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
---
google-cloud-firestore-admin/pom.xml | 4 ++--
google-cloud-firestore-bom/pom.xml | 16 ++++++++--------
google-cloud-firestore/pom.xml | 4 ++--
grpc-google-cloud-firestore-admin-v1/pom.xml | 4 ++--
grpc-google-cloud-firestore-v1/pom.xml | 4 ++--
pom.xml | 12 ++++++------
proto-google-cloud-firestore-admin-v1/pom.xml | 4 ++--
proto-google-cloud-firestore-bundle-v1/pom.xml | 4 ++--
proto-google-cloud-firestore-v1/pom.xml | 4 ++--
versions.txt | 16 ++++++++--------
10 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/google-cloud-firestore-admin/pom.xml b/google-cloud-firestore-admin/pom.xml
index 2da47fcc5f..feee2470b1 100644
--- a/google-cloud-firestore-admin/pom.xml
+++ b/google-cloud-firestore-admin/pom.xml
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
google-cloud-firestore-admin
- 3.0.1
+ 3.0.2-SNAPSHOT
jar
Google Cloud Firestore Admin Client
https://github.com/googleapis/java-firestore
@@ -14,7 +14,7 @@
com.google.cloud
google-cloud-firestore-parent
- 3.0.1
+ 3.0.2-SNAPSHOT
diff --git a/google-cloud-firestore-bom/pom.xml b/google-cloud-firestore-bom/pom.xml
index 937ca8a9ee..77bf11b4d1 100644
--- a/google-cloud-firestore-bom/pom.xml
+++ b/google-cloud-firestore-bom/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.google.cloud
google-cloud-firestore-bom
- 3.0.1
+ 3.0.2-SNAPSHOT
pom
com.google.cloud
@@ -52,37 +52,37 @@
com.google.cloud
google-cloud-firestore
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.api.grpc
proto-google-cloud-firestore-admin-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.cloud
proto-google-cloud-firestore-bundle-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.api.grpc
proto-google-cloud-firestore-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.api.grpc
grpc-google-cloud-firestore-admin-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.api.grpc
grpc-google-cloud-firestore-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.cloud
google-cloud-firestore-admin
- 3.0.1
+ 3.0.2-SNAPSHOT
diff --git a/google-cloud-firestore/pom.xml b/google-cloud-firestore/pom.xml
index e277f136bf..4e33dc4657 100644
--- a/google-cloud-firestore/pom.xml
+++ b/google-cloud-firestore/pom.xml
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
google-cloud-firestore
- 3.0.1
+ 3.0.2-SNAPSHOT
jar
Google Cloud Firestore
https://github.com/googleapis/java-firestore
@@ -14,7 +14,7 @@
com.google.cloud
google-cloud-firestore-parent
- 3.0.1
+ 3.0.2-SNAPSHOT
google-cloud-firestore
diff --git a/grpc-google-cloud-firestore-admin-v1/pom.xml b/grpc-google-cloud-firestore-admin-v1/pom.xml
index c78169fb01..272953a86b 100644
--- a/grpc-google-cloud-firestore-admin-v1/pom.xml
+++ b/grpc-google-cloud-firestore-admin-v1/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-firestore-admin-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
grpc-google-cloud-firestore-admin-v1
GRPC library for grpc-google-cloud-firestore-admin-v1
com.google.cloud
google-cloud-firestore-parent
- 3.0.1
+ 3.0.2-SNAPSHOT
diff --git a/grpc-google-cloud-firestore-v1/pom.xml b/grpc-google-cloud-firestore-v1/pom.xml
index 2d57f03b3a..c2913a49d0 100644
--- a/grpc-google-cloud-firestore-v1/pom.xml
+++ b/grpc-google-cloud-firestore-v1/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-firestore-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
grpc-google-cloud-firestore-v1
GRPC library for grpc-google-cloud-firestore-v1
com.google.cloud
google-cloud-firestore-parent
- 3.0.1
+ 3.0.2-SNAPSHOT
diff --git a/pom.xml b/pom.xml
index f7c930a613..01d9cb7446 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.google.cloud
google-cloud-firestore-parent
pom
- 3.0.1
+ 3.0.2-SNAPSHOT
Google Cloud Firestore Parent
https://github.com/googleapis/java-firestore
@@ -150,27 +150,27 @@
com.google.api.grpc
proto-google-cloud-firestore-admin-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.cloud
proto-google-cloud-firestore-bundle-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.api.grpc
proto-google-cloud-firestore-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.api.grpc
grpc-google-cloud-firestore-admin-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
com.google.api.grpc
grpc-google-cloud-firestore-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
diff --git a/proto-google-cloud-firestore-admin-v1/pom.xml b/proto-google-cloud-firestore-admin-v1/pom.xml
index e58ad1871f..875536481e 100644
--- a/proto-google-cloud-firestore-admin-v1/pom.xml
+++ b/proto-google-cloud-firestore-admin-v1/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
proto-google-cloud-firestore-admin-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
proto-google-cloud-firestore-admin-v1
PROTO library for proto-google-cloud-firestore-admin-v1
com.google.cloud
google-cloud-firestore-parent
- 3.0.1
+ 3.0.2-SNAPSHOT
diff --git a/proto-google-cloud-firestore-bundle-v1/pom.xml b/proto-google-cloud-firestore-bundle-v1/pom.xml
index 6a9b484694..f5814e66b3 100644
--- a/proto-google-cloud-firestore-bundle-v1/pom.xml
+++ b/proto-google-cloud-firestore-bundle-v1/pom.xml
@@ -5,14 +5,14 @@
4.0.0
proto-google-cloud-firestore-bundle-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
proto-google-cloud-firestore-bundle-v1
PROTO library for proto-google-cloud-firestore-bundle-v1
com.google.cloud
google-cloud-firestore-parent
- 3.0.1
+ 3.0.2-SNAPSHOT
diff --git a/proto-google-cloud-firestore-v1/pom.xml b/proto-google-cloud-firestore-v1/pom.xml
index 917cb2b995..82b61e5eca 100644
--- a/proto-google-cloud-firestore-v1/pom.xml
+++ b/proto-google-cloud-firestore-v1/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
proto-google-cloud-firestore-v1
- 3.0.1
+ 3.0.2-SNAPSHOT
proto-google-cloud-firestore-v1
PROTO library for proto-google-cloud-firestore-v1
com.google.cloud
google-cloud-firestore-parent
- 3.0.1
+ 3.0.2-SNAPSHOT
diff --git a/versions.txt b/versions.txt
index 224d4d62b7..4a5c481479 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,11 +1,11 @@
# Format:
# module:released-version:current-version
-google-cloud-firestore:3.0.1:3.0.1
-google-cloud-firestore-admin:3.0.1:3.0.1
-google-cloud-firestore-bom:3.0.1:3.0.1
-google-cloud-firestore-parent:3.0.1:3.0.1
-grpc-google-cloud-firestore-admin-v1:3.0.1:3.0.1
-grpc-google-cloud-firestore-v1:3.0.1:3.0.1
-proto-google-cloud-firestore-admin-v1:3.0.1:3.0.1
-proto-google-cloud-firestore-v1:3.0.1:3.0.1
+google-cloud-firestore:3.0.1:3.0.2-SNAPSHOT
+google-cloud-firestore-admin:3.0.1:3.0.2-SNAPSHOT
+google-cloud-firestore-bom:3.0.1:3.0.2-SNAPSHOT
+google-cloud-firestore-parent:3.0.1:3.0.2-SNAPSHOT
+grpc-google-cloud-firestore-admin-v1:3.0.1:3.0.2-SNAPSHOT
+grpc-google-cloud-firestore-v1:3.0.1:3.0.2-SNAPSHOT
+proto-google-cloud-firestore-admin-v1:3.0.1:3.0.2-SNAPSHOT
+proto-google-cloud-firestore-v1:3.0.1:3.0.2-SNAPSHOT
From 00a2f28e04a399c12e8009349cad8c5f3a421a50 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Thu, 12 Aug 2021 17:44:27 +0200
Subject: [PATCH 02/11] chore(deps): update dependency
com.google.cloud:google-cloud-firestore to v3.0.1 (#731)
---
samples/install-without-bom/pom.xml | 2 +-
samples/snapshot/pom.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index e425c334d0..2906ab398e 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud
google-cloud-firestore
- 3.0.0
+ 3.0.1
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index fdd9a9cff2..63e0e47482 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -28,7 +28,7 @@
com.google.cloud
google-cloud-firestore
- 3.0.0
+ 3.0.1
From a2369912ab0997e3eea08f11de56976091726e42 Mon Sep 17 00:00:00 2001
From: Yoshi Automation Bot
Date: Thu, 12 Aug 2021 08:54:44 -0700
Subject: [PATCH 03/11] chore: regenerate README (#732)
This PR was generated using Autosynth. :rainbow:
Log from Synthtool
```
2021-08-12 15:46:33,377 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-firestore/.github/readme/synth.py.
On branch autosynth-readme
nothing to commit, working tree clean
2021-08-12 15:46:34,747 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata.
```
Full log will be available here:
https://source.cloud.google.com/results/invocations/e364f6d2-b21a-49fe-b200-e7b8cf337536/targets
- [ ] To automatically regenerate this PR, check this box. (May take up to 24 hours.)
---
.github/readme/synth.metadata/synth.metadata | 4 ++--
README.md | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/.github/readme/synth.metadata/synth.metadata b/.github/readme/synth.metadata/synth.metadata
index 5aa7ba2734..092311ecc0 100644
--- a/.github/readme/synth.metadata/synth.metadata
+++ b/.github/readme/synth.metadata/synth.metadata
@@ -4,14 +4,14 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/java-firestore.git",
- "sha": "2c7f0d845d0f44dbaf81b44d2cae1a87a2e55ccf"
+ "sha": "00a2f28e04a399c12e8009349cad8c5f3a421a50"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
- "sha": "6252f2cd074c38f37b44abe5e96d128733eb1b61"
+ "sha": "7e1f6da50524b5d98eb67adbf6dd0805df54233d"
}
}
]
diff --git a/README.md b/README.md
index 23491489f3..ffcec69ae1 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ If you are using Maven without BOM, add this to your dependencies:
com.google.cloud
google-cloud-firestore
- 3.0.0
+ 3.0.1
```
@@ -56,13 +56,13 @@ compile 'com.google.cloud:google-cloud-firestore'
If you are using Gradle without BOM, add this to your dependencies
```Groovy
-compile 'com.google.cloud:google-cloud-firestore:3.0.0'
+compile 'com.google.cloud:google-cloud-firestore:3.0.1'
```
If you are using SBT, add this to your dependencies
```Scala
-libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.0.0"
+libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.0.1"
```
## Authentication
From e48f2f9d2404a054c6c9b6a946108999cea65dca Mon Sep 17 00:00:00 2001
From: Sebastian Schmidt
Date: Thu, 12 Aug 2021 12:54:42 -0600
Subject: [PATCH 04/11] chore: hello Java8 (#726)
---
.../cloud/firestore/BulkCommitBatch.java | 71 ++-
.../google/cloud/firestore/BulkWriter.java | 253 +++--------
.../cloud/firestore/CollectionGroup.java | 50 +--
.../cloud/firestore/CollectionReference.java | 10 +-
.../cloud/firestore/CustomClassMapper.java | 4 +-
.../cloud/firestore/DocumentReference.java | 38 +-
.../google/cloud/firestore/DocumentSet.java | 3 +-
.../com/google/cloud/firestore/FieldMask.java | 2 +-
.../com/google/cloud/firestore/FieldPath.java | 2 +-
.../cloud/firestore/FirestoreBundle.java | 14 +-
.../cloud/firestore/FirestoreOptions.java | 13 +-
.../com/google/cloud/firestore/Internal.java | 2 +-
.../com/google/cloud/firestore/Query.java | 83 ++--
.../cloud/firestore/RecursiveDelete.java | 75 ++--
.../google/cloud/firestore/ResourcePath.java | 9 +-
.../google/cloud/firestore/Transaction.java | 26 +-
.../cloud/firestore/TransactionRunner.java | 60 +--
.../google/cloud/firestore/UpdateBuilder.java | 20 +-
.../com/google/cloud/firestore/Watch.java | 128 +++---
.../firestore/collection/ArraySortedMap.java | 18 +-
.../collection/ImmutableSortedMap.java | 12 +-
.../ImmutableSortedMapIterator.java | 4 +-
.../collection/ImmutableSortedSet.java | 16 +-
.../collection/LLRBBlackValueNode.java | 2 +-
.../firestore/collection/LLRBEmptyNode.java | 2 +-
.../cloud/firestore/collection/LLRBNode.java | 4 +-
.../collection/LLRBRedValueNode.java | 4 +-
.../firestore/collection/LLRBValueNode.java | 8 +-
.../firestore/collection/RBTreeSortedMap.java | 39 +-
.../collection/StandardComparator.java | 2 +-
.../firestore/spi/v1/GrpcFirestoreRpc.java | 12 +-
.../cloud/firestore/BulkWriterTest.java | 167 ++-----
.../firestore/CollectionReferenceTest.java | 2 +-
.../firestore/ConformanceConversions.java | 4 +-
.../cloud/firestore/ConformanceTest.java | 97 ++--
.../firestore/DocumentReferenceTest.java | 30 +-
.../cloud/firestore/FirestoreBundleTest.java | 14 +-
.../google/cloud/firestore/FirestoreTest.java | 7 +-
.../cloud/firestore/ITBulkWriterTest.java | 38 +-
.../cloud/firestore/LocalFirestoreHelper.java | 58 +--
.../google/cloud/firestore/MapperTest.java | 422 +++---------------
.../com/google/cloud/firestore/QueryTest.java | 65 ++-
.../cloud/firestore/RecursiveDeleteTest.java | 132 +++---
.../cloud/firestore/TransactionTest.java | 327 ++++----------
.../com/google/cloud/firestore/WatchTest.java | 60 +--
.../cloud/firestore/it/ITQueryWatchTest.java | 63 +--
.../cloud/firestore/it/ITShutdownTest.java | 28 +-
.../cloud/firestore/it/ITSystemTest.java | 212 ++++-----
48 files changed, 883 insertions(+), 1829 deletions(-)
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkCommitBatch.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkCommitBatch.java
index 7d6dd81c67..5ad7868672 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkCommitBatch.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkCommitBatch.java
@@ -16,8 +16,6 @@
package com.google.cloud.firestore;
-import com.google.api.core.ApiAsyncFunction;
-import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.gax.rpc.ApiException;
@@ -92,32 +90,29 @@ ApiFuture bulkCommit() {
return ApiFutures.transformAsync(
response,
- new ApiAsyncFunction() {
- @Override
- public ApiFuture apply(BatchWriteResponse batchWriteResponse) {
- List> pendingUserCallbacks = new ArrayList<>();
-
- List writeResults =
- batchWriteResponse.getWriteResultsList();
- List statuses = batchWriteResponse.getStatusList();
-
- for (int i = 0; i < writeResults.size(); ++i) {
- com.google.firestore.v1.WriteResult writeResult = writeResults.get(i);
- com.google.rpc.Status status = statuses.get(i);
- BulkWriterOperation operation = pendingOperations.get(i);
- Status code = Status.fromCodeValue(status.getCode());
- if (code == Status.OK) {
- pendingUserCallbacks.add(
- operation.onSuccess(
- new WriteResult(Timestamp.fromProto(writeResult.getUpdateTime()))));
- } else {
- pendingUserCallbacks.add(
- operation.onException(
- FirestoreException.forServerRejection(code, status.getMessage())));
- }
+ batchWriteResponse -> {
+ List> pendingUserCallbacks = new ArrayList<>();
+
+ List writeResults =
+ batchWriteResponse.getWriteResultsList();
+ List statuses = batchWriteResponse.getStatusList();
+
+ for (int i = 0; i < writeResults.size(); ++i) {
+ com.google.firestore.v1.WriteResult writeResult = writeResults.get(i);
+ com.google.rpc.Status status = statuses.get(i);
+ BulkWriterOperation operation = pendingOperations.get(i);
+ Status code = Status.fromCodeValue(status.getCode());
+ if (code == Status.OK) {
+ pendingUserCallbacks.add(
+ operation.onSuccess(
+ new WriteResult(Timestamp.fromProto(writeResult.getUpdateTime()))));
+ } else {
+ pendingUserCallbacks.add(
+ operation.onException(
+ FirestoreException.forServerRejection(code, status.getMessage())));
}
- return BulkWriter.silenceFuture(ApiFutures.allAsList(pendingUserCallbacks));
}
+ return BulkWriter.silenceFuture(ApiFutures.allAsList(pendingUserCallbacks));
},
executor);
}
@@ -127,20 +122,18 @@ private ApiFuture processExceptions(ApiFuture() {
- @Override
- public BatchWriteResponse apply(ApiException exception) {
- com.google.rpc.Status.Builder status =
- com.google.rpc.Status.newBuilder()
- .setCode(exception.getStatusCode().getCode().ordinal())
- .setMessage(exception.getMessage());
- BatchWriteResponse.Builder response = BatchWriteResponse.newBuilder();
- for (int i = 0; i < pendingOperations.size(); ++i) {
- response.addWriteResults(com.google.firestore.v1.WriteResult.getDefaultInstance());
- response.addStatus(status);
- }
- return response.build();
+ exception -> {
+ com.google.rpc.Status.Builder status =
+ com.google.rpc.Status.newBuilder()
+ .setCode(exception.getStatusCode().getCode().ordinal())
+ .setMessage(exception.getMessage());
+ BatchWriteResponse.Builder responseBuilder = BatchWriteResponse.newBuilder();
+ for (int i = 0; i < pendingOperations.size(); ++i) {
+ responseBuilder.addWriteResults(
+ com.google.firestore.v1.WriteResult.getDefaultInstance());
+ responseBuilder.addStatus(status);
}
+ return responseBuilder.build();
},
MoreExecutors.directExecutor());
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java
index 365fa6c3ec..d0c134736c 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java
@@ -18,7 +18,6 @@
import static com.google.cloud.firestore.BulkWriterOperation.DEFAULT_BACKOFF_MAX_DELAY_MS;
-import com.google.api.core.ApiAsyncFunction;
import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutureCallback;
@@ -59,7 +58,7 @@ public interface WriteResultCallback {
* @param result The result of the operation.
*/
void onResult(DocumentReference documentReference, WriteResult result);
- };
+ }
/**
* A callback set by `addWriteErrorListener()` to be run every time an operation fails and
@@ -132,24 +131,20 @@ enum OperationType {
static final double DEFAULT_JITTER_FACTOR = 0.3;
private static final WriteResultCallback DEFAULT_SUCCESS_LISTENER =
- new WriteResultCallback() {
- public void onResult(DocumentReference documentReference, WriteResult result) {}
- };
+ (documentReference, result) -> {};
private static final WriteErrorCallback DEFAULT_ERROR_LISTENER =
- new WriteErrorCallback() {
- public boolean onError(BulkWriterException error) {
- if (error.getFailedAttempts() > MAX_RETRY_ATTEMPTS) {
- return false;
- }
- Set codes = FirestoreSettings.newBuilder().batchWriteSettings().getRetryableCodes();
- for (Code code : codes) {
- if (code.equals(Code.valueOf(error.getStatus().getCode().name()))) {
- return true;
- }
- }
+ error -> {
+ if (error.getFailedAttempts() > MAX_RETRY_ATTEMPTS) {
return false;
}
+ Set codes = FirestoreSettings.newBuilder().batchWriteSettings().getRetryableCodes();
+ for (Code code : codes) {
+ if (code.equals(Code.valueOf(error.getStatus().getCode().name()))) {
+ return true;
+ }
+ }
+ return false;
};
private static final Logger logger = Logger.getLogger(BulkWriter.class.getName());
@@ -295,13 +290,7 @@ public ApiFuture create(
@Nonnull final DocumentReference documentReference,
@Nonnull final Map fields) {
return executeWrite(
- documentReference,
- OperationType.CREATE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.create(documentReference, fields);
- }
- });
+ documentReference, OperationType.CREATE, batch -> batch.create(documentReference, fields));
}
/**
@@ -317,13 +306,7 @@ public ApiFuture apply(BulkCommitBatch batch) {
public ApiFuture create(
@Nonnull final DocumentReference documentReference, @Nonnull final Object pojo) {
return executeWrite(
- documentReference,
- OperationType.CREATE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.create(documentReference, pojo);
- }
- });
+ documentReference, OperationType.CREATE, batch -> batch.create(documentReference, pojo));
}
/**
@@ -336,13 +319,7 @@ public ApiFuture apply(BulkCommitBatch batch) {
@Nonnull
public ApiFuture delete(@Nonnull final DocumentReference documentReference) {
return executeWrite(
- documentReference,
- OperationType.DELETE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.delete(documentReference);
- }
- });
+ documentReference, OperationType.DELETE, batch -> batch.delete(documentReference));
}
/**
@@ -360,11 +337,7 @@ public ApiFuture delete(
return executeWrite(
documentReference,
OperationType.DELETE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.delete(documentReference, precondition);
- }
- });
+ batch -> batch.delete(documentReference, precondition));
}
/**
@@ -381,13 +354,7 @@ public ApiFuture set(
@Nonnull final DocumentReference documentReference,
@Nonnull final Map fields) {
return executeWrite(
- documentReference,
- OperationType.SET,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.set(documentReference, fields);
- }
- });
+ documentReference, OperationType.SET, batch -> batch.set(documentReference, fields));
}
/**
@@ -409,11 +376,7 @@ public ApiFuture set(
return executeWrite(
documentReference,
OperationType.SET,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.set(documentReference, fields, options);
- }
- });
+ batch -> batch.set(documentReference, fields, options));
}
/**
@@ -433,13 +396,7 @@ public ApiFuture set(
@Nonnull final Object pojo,
@Nonnull final SetOptions options) {
return executeWrite(
- documentReference,
- OperationType.SET,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.set(documentReference, pojo, options);
- }
- });
+ documentReference, OperationType.SET, batch -> batch.set(documentReference, pojo, options));
}
/**
@@ -455,13 +412,7 @@ public ApiFuture apply(BulkCommitBatch batch) {
public ApiFuture set(
@Nonnull final DocumentReference documentReference, @Nonnull final Object pojo) {
return executeWrite(
- documentReference,
- OperationType.SET,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.set(documentReference, pojo);
- }
- });
+ documentReference, OperationType.SET, batch -> batch.set(documentReference, pojo));
}
/**
@@ -483,13 +434,7 @@ public ApiFuture update(
@Nonnull final DocumentReference documentReference,
@Nonnull final Map fields) {
return executeWrite(
- documentReference,
- OperationType.UPDATE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.update(documentReference, fields);
- }
- });
+ documentReference, OperationType.UPDATE, batch -> batch.update(documentReference, fields));
}
/**
@@ -515,11 +460,7 @@ public ApiFuture update(
return executeWrite(
documentReference,
OperationType.UPDATE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.update(documentReference, fields, precondition);
- }
- });
+ batch -> batch.update(documentReference, fields, precondition));
}
/**
@@ -547,11 +488,7 @@ public ApiFuture update(
return executeWrite(
documentReference,
OperationType.UPDATE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.update(documentReference, field, value, moreFieldsAndValues);
- }
- });
+ batch -> batch.update(documentReference, field, value, moreFieldsAndValues));
}
/**
@@ -579,11 +516,7 @@ public ApiFuture update(
return executeWrite(
documentReference,
OperationType.UPDATE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.update(documentReference, fieldPath, value, moreFieldsAndValues);
- }
- });
+ batch -> batch.update(documentReference, fieldPath, value, moreFieldsAndValues));
}
/**
@@ -612,11 +545,7 @@ public ApiFuture update(
return executeWrite(
documentReference,
OperationType.UPDATE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.update(documentReference, precondition, field, value, moreFieldsAndValues);
- }
- });
+ batch -> batch.update(documentReference, precondition, field, value, moreFieldsAndValues));
}
/**
@@ -646,12 +575,8 @@ public ApiFuture update(
return executeWrite(
documentReference,
OperationType.UPDATE,
- new ApiFunction>() {
- public ApiFuture apply(BulkCommitBatch batch) {
- return batch.update(
- documentReference, precondition, fieldPath, value, moreFieldsAndValues);
- }
- });
+ batch ->
+ batch.update(documentReference, precondition, fieldPath, value, moreFieldsAndValues));
}
/**
@@ -666,29 +591,20 @@ private ApiFuture executeWrite(
new BulkWriterOperation(
documentReference,
operationType,
- new ApiFunction() {
- @Override
- public Void apply(BulkWriterOperation operation) {
- synchronized (lock) {
- sendOperationLocked(enqueueOperationOnBatchCallback, operation);
- }
- return null;
+ op -> {
+ synchronized (lock) {
+ sendOperationLocked(enqueueOperationOnBatchCallback, op);
}
+ return null;
},
- new ApiFunction>() {
- @Override
- public ApiFuture apply(WriteResult writeResult) {
- synchronized (lock) {
- return invokeUserSuccessCallbackLocked(documentReference, writeResult);
- }
+ writeResult -> {
+ synchronized (lock) {
+ return invokeUserSuccessCallbackLocked(documentReference, writeResult);
}
},
- new ApiFunction>() {
- @Override
- public ApiFuture apply(BulkWriterException e) {
- synchronized (lock) {
- return invokeUserErrorCallbackLocked(e);
- }
+ e -> {
+ synchronized (lock) {
+ return invokeUserErrorCallbackLocked(e);
}
});
@@ -701,12 +617,7 @@ public ApiFuture apply(BulkWriterException e) {
lastOperation =
ApiFutures.transformAsync(
lastOperation,
- new ApiAsyncFunction() {
- @Override
- public ApiFuture apply(Void aVoid) {
- return silenceFuture(operation.getFuture());
- }
- },
+ aVoid -> silenceFuture(operation.getFuture()),
MoreExecutors.directExecutor());
// Schedule the operation if the BulkWriter has fewer than the maximum number of allowed
@@ -716,13 +627,10 @@ public ApiFuture apply(Void aVoid) {
sendOperationLocked(enqueueOperationOnBatchCallback, operation);
} else {
bufferedOperations.add(
- new Runnable() {
- @Override
- public void run() {
- synchronized (lock) {
- pendingOpsCount++;
- sendOperationLocked(enqueueOperationOnBatchCallback, operation);
- }
+ () -> {
+ synchronized (lock) {
+ pendingOpsCount++;
+ sendOperationLocked(enqueueOperationOnBatchCallback, operation);
}
});
}
@@ -731,24 +639,20 @@ public void run() {
ApiFuture processedOperationFuture =
ApiFutures.transformAsync(
operation.getFuture(),
- new ApiAsyncFunction() {
- public ApiFuture apply(WriteResult result) throws Exception {
- pendingOpsCount--;
- processBufferedOperations();
- return ApiFutures.immediateFuture(result);
- }
+ result -> {
+ pendingOpsCount--;
+ processBufferedOperations();
+ return ApiFutures.immediateFuture(result);
},
MoreExecutors.directExecutor());
return ApiFutures.catchingAsync(
processedOperationFuture,
ApiException.class,
- new ApiAsyncFunction() {
- public ApiFuture apply(ApiException e) throws Exception {
- pendingOpsCount--;
- processBufferedOperations();
- throw e;
- }
+ e -> {
+ pendingOpsCount--;
+ processBufferedOperations();
+ throw e;
},
MoreExecutors.directExecutor());
}
@@ -978,12 +882,9 @@ private void scheduleCurrentBatchLocked(final boolean flush) {
final int backoffMsWithJitter = applyJitter(highestBackoffDuration);
bulkWriterExecutor.schedule(
- new Runnable() {
- @Override
- public void run() {
- synchronized (lock) {
- sendBatchLocked(pendingBatch, flush);
- }
+ () -> {
+ synchronized (lock) {
+ sendBatchLocked(pendingBatch, flush);
}
},
backoffMsWithJitter,
@@ -999,13 +900,10 @@ private void sendBatchLocked(final BulkCommitBatch batch, final boolean flush) {
batch
.bulkCommit()
.addListener(
- new Runnable() {
- @Override
- public void run() {
- if (flush) {
- synchronized (lock) {
- scheduleCurrentBatchLocked(/* flush= */ true);
- }
+ () -> {
+ if (flush) {
+ synchronized (lock) {
+ scheduleCurrentBatchLocked(/* flush= */ true);
}
}
},
@@ -1014,12 +912,9 @@ public void run() {
long delayMs = rateLimiter.getNextRequestDelayMs(batch.getMutationsSize());
logger.log(Level.FINE, String.format("Backing off for %d seconds", delayMs / 1000));
bulkWriterExecutor.schedule(
- new Runnable() {
- @Override
- public void run() {
- synchronized (lock) {
- sendBatchLocked(batch, flush);
- }
+ () -> {
+ synchronized (lock) {
+ sendBatchLocked(batch, flush);
}
},
delayMs,
@@ -1090,15 +985,12 @@ private SettableApiFuture invokeUserErrorCallbackLocked(
final SettableApiFuture callbackResult = SettableApiFuture.create();
final WriteErrorCallback listener = errorListener;
errorExecutor.execute(
- new Runnable() {
- @Override
- public void run() {
- try {
- boolean shouldRetry = listener.onError(error);
- callbackResult.set(shouldRetry);
- } catch (Exception e) {
- callbackResult.setException(e);
- }
+ () -> {
+ try {
+ boolean shouldRetry = listener.onError(error);
+ callbackResult.set(shouldRetry);
+ } catch (Exception e) {
+ callbackResult.setException(e);
}
});
return callbackResult;
@@ -1110,15 +1002,12 @@ private ApiFuture invokeUserSuccessCallbackLocked(
final SettableApiFuture callbackResult = SettableApiFuture.create();
final WriteResultCallback listener = successListener;
successExecutor.execute(
- new Runnable() {
- @Override
- public void run() {
- try {
- listener.onResult(documentReference, result);
- callbackResult.set(null);
- } catch (Exception e) {
- callbackResult.setException(e);
- }
+ () -> {
+ try {
+ listener.onResult(documentReference, result);
+ callbackResult.set(null);
+ } catch (Exception e) {
+ callbackResult.setException(e);
}
});
return callbackResult;
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionGroup.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionGroup.java
index 0a4c35e73b..8ecce62cb1 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionGroup.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionGroup.java
@@ -16,15 +16,12 @@
package com.google.cloud.firestore;
-import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.ApiExceptions;
import com.google.api.gax.rpc.ApiStreamObserver;
-import com.google.cloud.firestore.v1.FirestoreClient;
import com.google.cloud.firestore.v1.FirestoreClient.PartitionQueryPagedResponse;
-import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.MoreExecutors;
@@ -35,8 +32,8 @@
import io.opencensus.trace.Status;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
+import java.util.function.Function;
import javax.annotation.Nullable;
/**
@@ -79,7 +76,7 @@ public void getPartitions(
} else {
PartitionQueryRequest request = buildRequest(desiredPartitionCount);
- final FirestoreClient.PartitionQueryPagedResponse response;
+ final PartitionQueryPagedResponse response;
final TraceUtil traceUtil = TraceUtil.getInstance();
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_PARTITIONQUERY);
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
@@ -90,12 +87,9 @@ public void getPartitions(
consumePartitions(
response,
- new Function() {
- @Override
- public Void apply(QueryPartition queryPartition) {
- observer.onNext(queryPartition);
- return null;
- }
+ queryPartition -> {
+ observer.onNext(queryPartition);
+ return null;
});
observer.onCompleted();
@@ -121,21 +115,15 @@ public ApiFuture> getPartitions(long desiredPartitionCount)
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
return ApiFutures.transform(
rpcContext.sendRequest(request, rpcContext.getClient().partitionQueryPagedCallable()),
- new ApiFunction>() {
- @Override
- public List apply(PartitionQueryPagedResponse response) {
- final ImmutableList.Builder partitions = ImmutableList.builder();
- consumePartitions(
- response,
- new Function() {
- @Override
- public Void apply(QueryPartition queryPartition) {
- partitions.add(queryPartition);
- return null;
- }
- });
- return partitions.build();
- }
+ response -> {
+ final ImmutableList.Builder partitions = ImmutableList.builder();
+ consumePartitions(
+ response,
+ queryPartition -> {
+ partitions.add(queryPartition);
+ return null;
+ });
+ return partitions.build();
},
MoreExecutors.directExecutor());
} catch (ApiException exception) {
@@ -169,14 +157,8 @@ private void consumePartitions(
}
// Sort the partitions as they may not be ordered if responses are paged.
- Collections.sort(
- cursors,
- new Comparator() {
- @Override
- public int compare(Cursor left, Cursor right) {
- return Order.INSTANCE.compareArrays(left.getValuesList(), right.getValuesList());
- }
- });
+ cursors.sort(
+ (left, right) -> Order.INSTANCE.compareArrays(left.getValuesList(), right.getValuesList()));
@Nullable Object[] lastCursor = null;
for (Cursor cursor : cursors) {
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionReference.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionReference.java
index 54d2d69bca..3b771fdb86 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionReference.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionReference.java
@@ -16,7 +16,6 @@
package com.google.cloud.firestore;
-import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.core.InternalExtensionOnly;
@@ -195,14 +194,7 @@ public ApiFuture add(@Nonnull final Map field
ApiFuture createFuture = documentReference.create(fields);
return ApiFutures.transform(
- createFuture,
- new ApiFunction() {
- @Override
- public DocumentReference apply(WriteResult writeResult) {
- return documentReference;
- }
- },
- MoreExecutors.directExecutor());
+ createFuture, writeResult -> documentReference, MoreExecutors.directExecutor());
}
/**
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java
index 96689ff6f2..a17c3a08e2 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java
@@ -305,7 +305,7 @@ private static T deserializeToParameterizedType(
try {
result =
(rawType == Map.class)
- ? new HashMap()
+ ? new HashMap<>()
: (HashMap) rawType.getDeclaredConstructor().newInstance();
} catch (InstantiationException
| IllegalAccessException
@@ -789,7 +789,7 @@ private void addProperty(String property) {
}
T deserialize(Map values, DeserializeContext context) {
- return deserialize(values, Collections.>, Type>emptyMap(), context);
+ return deserialize(values, Collections.emptyMap(), context);
}
T deserialize(
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java
index ebf892ba7a..5841bdcf7d 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java
@@ -16,7 +16,6 @@
package com.google.cloud.firestore;
-import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.core.InternalExtensionOnly;
@@ -131,12 +130,7 @@ public CollectionReference collection(@Nonnull String collectionPath) {
private ApiFuture extractFirst(ApiFuture> results) {
return ApiFutures.transform(
results,
- new ApiFunction, T>() {
- @Override
- public T apply(List results) {
- return results.isEmpty() ? null : results.get(0);
- }
- },
+ results1 -> results1.isEmpty() ? null : results1.get(0),
MoreExecutors.directExecutor());
}
@@ -436,26 +430,22 @@ public ListenerRegistration addSnapshotListener(
return Watch.forDocument(this)
.runWatch(
executor,
- new EventListener() {
- @Override
- public void onEvent(
- @Nullable QuerySnapshot value, @Nullable FirestoreException error) {
- if (value == null) {
- listener.onEvent(null, error);
- return;
- }
+ (value, error) -> {
+ if (value == null) {
+ listener.onEvent(null, error);
+ return;
+ }
- for (DocumentSnapshot doc : value) {
- if (doc.getReference().equals(DocumentReference.this)) {
- listener.onEvent(value.getDocuments().get(0), null);
- return;
- }
+ for (DocumentSnapshot doc : value) {
+ if (doc.getReference().equals(DocumentReference.this)) {
+ listener.onEvent(value.getDocuments().get(0), null);
+ return;
}
- listener.onEvent(
- DocumentSnapshot.fromMissing(
- rpcContext, DocumentReference.this, value.getReadTime()),
- null);
}
+ listener.onEvent(
+ DocumentSnapshot.fromMissing(
+ rpcContext, DocumentReference.this, value.getReadTime()),
+ null);
});
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSet.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSet.java
index d453092694..4230709030 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSet.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSet.java
@@ -36,8 +36,7 @@ class DocumentSet implements Iterable {
/** Returns an empty DocumentSet sorted by the given comparator, then by keys. */
static DocumentSet emptySet(final Comparator comparator) {
return new DocumentSet(
- EMPTY_DOCUMENT_MAP,
- new ImmutableSortedSet<>(Collections.emptyList(), comparator));
+ EMPTY_DOCUMENT_MAP, new ImmutableSortedSet<>(Collections.emptyList(), comparator));
}
/**
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldMask.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldMask.java
index 2bcfa252bd..0277029da1 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldMask.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldMask.java
@@ -27,7 +27,7 @@
/** A FieldMask can be used to limit the number of fields returned by a `getAll()` call. */
public final class FieldMask {
- static final FieldMask EMPTY_MASK = new FieldMask(new TreeSet());
+ static final FieldMask EMPTY_MASK = new FieldMask(new TreeSet<>());
private final SortedSet fieldPaths; // Sorted for testing.
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldPath.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldPath.java
index b850f2522f..752b7ea09e 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldPath.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FieldPath.java
@@ -87,7 +87,7 @@ static FieldPath fromDotSeparatedString(String field) {
static FieldPath empty() {
// NOTE: This is not static since it would create a circular class dependency during
// initialization.
- return new AutoValue_FieldPath(ImmutableList.of());
+ return new AutoValue_FieldPath(ImmutableList.of());
}
private String encodedPath;
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreBundle.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreBundle.java
index f28c1aab95..2b4977aebc 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreBundle.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreBundle.java
@@ -17,7 +17,6 @@
package com.google.cloud.firestore;
import com.google.cloud.Timestamp;
-import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.firestore.bundle.BundleElement;
import com.google.firestore.bundle.BundleMetadata;
@@ -33,6 +32,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
/** Represents a Firestore data bundle with results from the given document and query snapshots. */
public final class FirestoreBundle {
@@ -43,16 +43,16 @@ public final class FirestoreBundle {
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
// Raw byte array to hold the content of the bundle.
- private byte[] bundleData;
+ private final byte[] bundleData;
/** Builds a Firestore data bundle with results from the given document and query snapshots. */
public static final class Builder {
// Id of the bundle.
- private String id;
+ private final String id;
// Resulting documents for the bundle, keyed by full document path.
- private Map documents = new HashMap<>();
+ private final Map documents = new HashMap<>();
// Named queries saved in the bundle, keyed by query name.
- private Map namedQueries = new HashMap<>();
+ private final Map namedQueries = new HashMap<>();
// The latest read time among all bundled documents and queries.
private Timestamp latestReadTime = Timestamp.MIN_VALUE;
@@ -73,7 +73,7 @@ public String getId() {
* @returns This instance.
*/
public Builder add(DocumentSnapshot documentSnapshot) {
- return add(documentSnapshot, Optional.absent());
+ return add(documentSnapshot, Optional.empty());
}
private Builder add(DocumentSnapshot documentSnapshot, Optional queryName) {
@@ -81,7 +81,7 @@ private Builder add(DocumentSnapshot documentSnapshot, Optional queryNam
BundledDocument originalDocument = documents.get(documentSnapshot.getReference().getName());
List queries =
originalDocument == null
- ? Lists.newArrayList()
+ ? Lists.newArrayList()
: Lists.newArrayList(originalDocument.getMetadata().getQueriesList());
// Update with document built from `documentSnapshot` because it is newer.
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreOptions.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreOptions.java
index 392bf78416..47de09d39a 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreOptions.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreOptions.java
@@ -16,7 +16,6 @@
package com.google.cloud.firestore;
-import com.google.api.core.ApiFunction;
import com.google.api.core.InternalApi;
import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.FixedCredentialsProvider;
@@ -36,7 +35,7 @@
import io.grpc.ManagedChannelBuilder;
import java.io.IOException;
import java.net.URI;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -236,13 +235,7 @@ public FirestoreOptions build() {
this.setChannelProvider(
InstantiatingGrpcChannelProvider.newBuilder()
.setEndpoint(emulatorHost)
- .setChannelConfigurator(
- new ApiFunction() {
- @Override
- public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
- return input.usePlaintext();
- }
- })
+ .setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
.build());
// Use a `CredentialProvider` to match the Firebase Admin SDK, which prevents the Admin SDK
// from overwriting the Emulator credentials.
@@ -255,7 +248,7 @@ public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
public static class EmulatorCredentials extends Credentials {
private final Map> HEADERS =
- ImmutableMap.of("Authorization", Arrays.asList("Bearer owner"));
+ ImmutableMap.of("Authorization", Collections.singletonList("Bearer owner"));
@Override
public String getAuthenticationType() {
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Internal.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Internal.java
index 3d1bbc4f4f..46f16f5f38 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Internal.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Internal.java
@@ -28,7 +28,7 @@
@InternalApi
public class Internal {
- private FirestoreImpl firestore;
+ private final FirestoreImpl firestore;
@InternalApi
public Internal(FirestoreImpl firestore) {
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java
index b1f5fa0bf1..3cf86a81ed 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java
@@ -268,9 +268,9 @@ static Builder builder() {
return new AutoValue_Query_QueryOptions.Builder()
.setAllDescendants(false)
.setLimitType(LimitType.First)
- .setFieldOrders(ImmutableList.of())
- .setFieldFilters(ImmutableList.of())
- .setFieldProjections(ImmutableList.of())
+ .setFieldOrders(ImmutableList.of())
+ .setFieldFilters(ImmutableList.of())
+ .setFieldProjections(ImmutableList.of())
.setKindless(false)
.setRequireConsistency(true);
}
@@ -1617,7 +1617,7 @@ ApiFuture get(@Nullable ByteString transactionId) {
internalStream(
new QuerySnapshotObserver() {
- List documentSnapshots = new ArrayList<>();
+ final List documentSnapshots = new ArrayList<>();
@Override
public void onNext(QueryDocumentSnapshot documentSnapshot) {
@@ -1649,48 +1649,45 @@ public void onCompleted() {
}
Comparator comparator() {
- return new Comparator() {
- @Override
- public int compare(QueryDocumentSnapshot doc1, QueryDocumentSnapshot doc2) {
- // Add implicit sorting by name, using the last specified direction.
- ImmutableList fieldOrders = options.getFieldOrders();
- Direction lastDirection =
- fieldOrders.isEmpty()
- ? Direction.ASCENDING
- : fieldOrders.get(fieldOrders.size() - 1).direction;
-
- List orderBys = new ArrayList<>(fieldOrders);
- orderBys.add(new FieldOrder(FieldPath.DOCUMENT_ID.toProto(), lastDirection));
-
- for (FieldOrder orderBy : orderBys) {
- int comp;
-
- String path = orderBy.fieldReference.getFieldPath();
- if (FieldPath.isDocumentId(path)) {
- comp =
- doc1.getReference()
- .getResourcePath()
- .compareTo(doc2.getReference().getResourcePath());
- } else {
- FieldPath fieldPath = FieldPath.fromDotSeparatedString(path);
- Preconditions.checkState(
- doc1.contains(fieldPath) && doc2.contains(fieldPath),
- "Can only compare fields that exist in the DocumentSnapshot."
- + " Please include the fields you are ordering on in your select() call.");
- Value v1 = doc1.extractField(fieldPath);
- Value v2 = doc2.extractField(fieldPath);
-
- comp = com.google.cloud.firestore.Order.INSTANCE.compare(v1, v2);
- }
-
- if (comp != 0) {
- int direction = orderBy.direction.equals(Direction.ASCENDING) ? 1 : -1;
- return direction * comp;
- }
+ return (doc1, doc2) -> {
+ // Add implicit sorting by name, using the last specified direction.
+ ImmutableList fieldOrders = options.getFieldOrders();
+ Direction lastDirection =
+ fieldOrders.isEmpty()
+ ? Direction.ASCENDING
+ : fieldOrders.get(fieldOrders.size() - 1).direction;
+
+ List orderBys = new ArrayList<>(fieldOrders);
+ orderBys.add(new FieldOrder(FieldPath.DOCUMENT_ID.toProto(), lastDirection));
+
+ for (FieldOrder orderBy : orderBys) {
+ int comp;
+
+ String path = orderBy.fieldReference.getFieldPath();
+ if (FieldPath.isDocumentId(path)) {
+ comp =
+ doc1.getReference()
+ .getResourcePath()
+ .compareTo(doc2.getReference().getResourcePath());
+ } else {
+ FieldPath fieldPath = FieldPath.fromDotSeparatedString(path);
+ Preconditions.checkState(
+ doc1.contains(fieldPath) && doc2.contains(fieldPath),
+ "Can only compare fields that exist in the DocumentSnapshot."
+ + " Please include the fields you are ordering on in your select() call.");
+ Value v1 = doc1.extractField(fieldPath);
+ Value v2 = doc2.extractField(fieldPath);
+
+ comp = com.google.cloud.firestore.Order.INSTANCE.compare(v1, v2);
}
- return 0;
+ if (comp != 0) {
+ int direction = orderBy.direction.equals(Direction.ASCENDING) ? 1 : -1;
+ return direction * comp;
+ }
}
+
+ return 0;
};
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecursiveDelete.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecursiveDelete.java
index b14eb19834..eba64e7690 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecursiveDelete.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecursiveDelete.java
@@ -262,29 +262,29 @@ private void onQueryEnd() {
// Completes the future returned by run() and sets the exception if an error occurred.
ApiFutures.transformAsync(
ApiFutures.allAsList(pendingFutures),
- new ApiAsyncFunction, Void>() {
- public ApiFuture apply(List unused) {
- synchronized (lock) {
- if (lastError == null) {
- completionFuture.set(null);
- } else {
- String message =
- errorCount
- + (errorCount != 1 ? " deletes" : " delete")
- + " failed. "
- + lastError.getMessage();
- if (lastError instanceof FirestoreException) {
- lastError =
- new FirestoreException(message, ((FirestoreException) lastError).getStatus());
+ (ApiAsyncFunction, Void>)
+ unused -> {
+ synchronized (lock) {
+ if (lastError == null) {
+ completionFuture.set(null);
} else {
- lastError = new Throwable(message, lastError);
+ String message =
+ errorCount
+ + (errorCount != 1 ? " deletes" : " delete")
+ + " failed. "
+ + lastError.getMessage();
+ if (lastError instanceof FirestoreException) {
+ lastError =
+ new FirestoreException(
+ message, ((FirestoreException) lastError).getStatus());
+ } else {
+ lastError = new Throwable(message, lastError);
+ }
+ completionFuture.setException(lastError);
}
- completionFuture.setException(lastError);
+ return ApiFutures.immediateFuture(null);
}
- return ApiFutures.immediateFuture(null);
- }
- }
- },
+ },
MoreExecutors.directExecutor());
}
@@ -298,33 +298,28 @@ private ApiFuture deleteReference(final DocumentReference reference) {
ApiFutures.catchingAsync(
writer.delete(reference),
Throwable.class,
- new ApiAsyncFunction() {
- public ApiFuture apply(Throwable e) {
- synchronized (lock) {
- errorCount++;
- lastError = e;
- return ApiFutures.immediateFuture(null);
- }
+ e -> {
+ synchronized (lock) {
+ errorCount++;
+ lastError = e;
+ return ApiFutures.immediateFuture(null);
}
},
MoreExecutors.directExecutor());
return ApiFutures.transformAsync(
catchingDeleteFuture,
- new ApiAsyncFunction() {
-
- public ApiFuture apply(WriteResult result) {
- synchronized (lock) {
- pendingOperationsCount--;
- // We wait until the previous stream has ended in order to ensure the
- // startAfter document is correct. Starting the next stream while
- // there are pending operations allows Firestore to maximize
- // BulkWriter throughput.
- if (documentsPending && !streamInProgress && pendingOperationsCount < minPendingOps) {
- streamDescendants();
- }
- return ApiFutures.immediateFuture(null);
+ result -> {
+ synchronized (lock) {
+ pendingOperationsCount--;
+ // We wait until the previous stream has ended in order to ensure the
+ // startAfter document is correct. Starting the next stream while
+ // there are pending operations allows Firestore to maximize
+ // BulkWriter throughput.
+ if (documentsPending && !streamInProgress && pendingOperationsCount < minPendingOps) {
+ streamDescendants();
}
+ return ApiFutures.immediateFuture(null);
}
},
MoreExecutors.directExecutor());
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java
index ee44cf4f38..6a289b9172 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java
@@ -44,7 +44,7 @@ static ResourcePath create(DatabaseRootName databaseName, ImmutableList
* @param databaseName The Firestore database name.
*/
static ResourcePath create(DatabaseRootName databaseName) {
- return new AutoValue_ResourcePath(ImmutableList.of(), databaseName);
+ return new AutoValue_ResourcePath(ImmutableList.of(), databaseName);
}
/**
@@ -185,11 +185,6 @@ ResourcePath createPathWithSegments(ImmutableList segments) {
}
public static Comparator comparator() {
- return new Comparator() {
- @Override
- public int compare(ResourcePath left, ResourcePath right) {
- return left.compareTo(right);
- }
- };
+ return Comparator.naturalOrder();
}
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Transaction.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Transaction.java
index d8e9ca31ce..5d3693fdd6 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Transaction.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Transaction.java
@@ -16,7 +16,6 @@
package com.google.cloud.firestore;
-import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.cloud.firestore.TransactionOptions.TransactionOptionsType;
@@ -107,12 +106,9 @@ ApiFuture begin() {
return ApiFutures.transform(
transactionBeginFuture,
- new ApiFunction() {
- @Override
- public Void apply(BeginTransactionResponse beginTransactionResponse) {
- transactionId = beginTransactionResponse.getTransaction();
- return null;
- }
+ beginTransactionResponse -> {
+ transactionId = beginTransactionResponse.getTransaction();
+ return null;
},
MoreExecutors.directExecutor());
}
@@ -133,14 +129,7 @@ ApiFuture rollback() {
firestore.sendRequest(reqBuilder.build(), firestore.getClient().rollbackCallable());
return ApiFutures.transform(
- rollbackFuture,
- new ApiFunction() {
- @Override
- public Void apply(Empty beginTransactionResponse) {
- return null;
- }
- },
- MoreExecutors.directExecutor());
+ rollbackFuture, beginTransactionResponse -> null, MoreExecutors.directExecutor());
}
/**
@@ -155,12 +144,7 @@ public ApiFuture get(@Nonnull DocumentReference documentRef) {
Tracing.getTracer().getCurrentSpan().addAnnotation(TraceUtil.SPAN_NAME_GETDOCUMENT);
return ApiFutures.transform(
firestore.getAll(new DocumentReference[] {documentRef}, /*fieldMask=*/ null, transactionId),
- new ApiFunction, DocumentSnapshot>() {
- @Override
- public DocumentSnapshot apply(List snapshots) {
- return snapshots.isEmpty() ? null : snapshots.get(0);
- }
- },
+ snapshots -> snapshots.isEmpty() ? null : snapshots.get(0),
MoreExecutors.directExecutor());
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/TransactionRunner.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/TransactionRunner.java
index 3c479f0fc9..420f41e08e 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/TransactionRunner.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/TransactionRunner.java
@@ -116,7 +116,7 @@ ApiFuture run() {
private ApiFuture maybeRollback() {
return transaction.hasTransactionId()
? transaction.rollback()
- : ApiFutures.immediateFuture(null);
+ : ApiFutures.immediateFuture(null);
}
/** A callback that invokes the BeginTransaction callback. */
@@ -126,11 +126,8 @@ public ApiFuture apply(Void input) {
final SettableApiFuture backoff = SettableApiFuture.create();
// Add a backoff delay. At first, this is 0.
firestoreExecutor.schedule(
- new Runnable() {
- @Override
- public void run() {
- backoff.set(null);
- }
+ () -> {
+ backoff.set(null);
},
nextBackoffAttempt.getRandomizedRetryDelay().toMillis(),
TimeUnit.MILLISECONDS);
@@ -148,30 +145,27 @@ private SettableApiFuture invokeUserCallback() {
final SettableApiFuture returnedResult = SettableApiFuture.create();
userCallbackExecutor.execute(
- new Runnable() {
- @Override
- public void run() {
- ApiFuture userCallbackResult;
- try {
- userCallbackResult = userCallback.updateCallback(transaction);
- } catch (Exception e) {
- userCallbackResult = ApiFutures.immediateFailedFuture(e);
- }
- ApiFutures.addCallback(
- userCallbackResult,
- new ApiFutureCallback() {
- @Override
- public void onFailure(Throwable t) {
- returnedResult.setException(t);
- }
-
- @Override
- public void onSuccess(T result) {
- returnedResult.set(result);
- }
- },
- firestoreExecutor);
+ () -> {
+ ApiFuture userCallbackResult;
+ try {
+ userCallbackResult = userCallback.updateCallback(transaction);
+ } catch (Exception e) {
+ userCallbackResult = ApiFutures.immediateFailedFuture(e);
}
+ ApiFutures.addCallback(
+ userCallbackResult,
+ new ApiFutureCallback() {
+ @Override
+ public void onFailure(Throwable t) {
+ returnedResult.setException(t);
+ }
+
+ @Override
+ public void onSuccess(T result) {
+ returnedResult.set(result);
+ }
+ },
+ firestoreExecutor);
});
return returnedResult;
}
@@ -289,13 +283,7 @@ private ApiFuture rollbackAndReject(final Throwable throwable) {
transaction
.rollback()
.addListener(
- new Runnable() {
- @Override
- public void run() {
- failedTransaction.setException(throwable);
- }
- },
- MoreExecutors.directExecutor());
+ () -> failedTransaction.setException(throwable), MoreExecutors.directExecutor());
} else {
failedTransaction.setException(throwable);
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java
index 18fee618a0..ee21f0e06e 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java
@@ -16,7 +16,6 @@
package com.google.cloud.firestore;
-import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.core.InternalExtensionOnly;
@@ -619,20 +618,17 @@ ApiFuture> commit(@Nullable ByteString transactionId) {
return ApiFutures.transform(
response,
- new ApiFunction>() {
- @Override
- public List apply(CommitResponse commitResponse) {
- List writeResults =
- commitResponse.getWriteResultsList();
+ commitResponse -> {
+ List writeResults =
+ commitResponse.getWriteResultsList();
- List result = new ArrayList<>();
+ List result = new ArrayList<>();
- for (com.google.firestore.v1.WriteResult writeResult : writeResults) {
- result.add(WriteResult.fromProto(writeResult, commitResponse.getCommitTime()));
- }
-
- return result;
+ for (com.google.firestore.v1.WriteResult writeResult : writeResults) {
+ result.add(WriteResult.fromProto(writeResult, commitResponse.getCommitTime()));
}
+
+ return result;
},
MoreExecutors.directExecutor());
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java
index 7eda432cbe..f655b58c40 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java
@@ -38,7 +38,6 @@
import io.grpc.StatusRuntimeException;
import io.opencensus.trace.Tracing;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -105,7 +104,7 @@ class Watch implements ApiStreamObserver {
* Indicates whether we are interested in data from the stream. Set to false in the
* 'unsubscribe()' callback.
*/
- private AtomicBoolean isActive;
+ private final AtomicBoolean isActive;
/** The list of document changes in a snapshot separated by change type. */
static class ChangeSet {
@@ -281,25 +280,19 @@ ListenerRegistration runWatch(
initStream();
- return new ListenerRegistration() {
- @Override
- public void remove() {
- isActive.set(false);
-
- firestore
- .getClient()
- .getExecutor()
- .execute(
- new Runnable() {
- @Override
- public void run() {
- synchronized (Watch.this) {
- stream.onCompleted();
- stream = null;
- }
- }
- });
- }
+ return () -> {
+ isActive.set(false);
+
+ firestore
+ .getClient()
+ .getExecutor()
+ .execute(
+ () -> {
+ synchronized (Watch.this) {
+ stream.onCompleted();
+ stream = null;
+ }
+ });
};
}
@@ -334,21 +327,18 @@ private void closeStream(final Throwable throwable) {
if (isActive.getAndSet(false)) {
userCallbackExecutor.execute(
- new Runnable() {
- @Override
- public void run() {
- if (throwable instanceof FirestoreException) {
- listener.onEvent(null, (FirestoreException) throwable);
- } else {
- Status status = getStatus(throwable);
- FirestoreException firestoreException =
- FirestoreException.forApiException(
- new ApiException(
- throwable,
- GrpcStatusCode.of(status != null ? status.getCode() : Code.UNKNOWN),
- false));
- listener.onEvent(null, firestoreException);
- }
+ () -> {
+ if (throwable instanceof FirestoreException) {
+ listener.onEvent(null, (FirestoreException) throwable);
+ } else {
+ Status status = getStatus(throwable);
+ FirestoreException firestoreException =
+ FirestoreException.forApiException(
+ new ApiException(
+ throwable,
+ GrpcStatusCode.of(status != null ? status.getCode() : Code.UNKNOWN),
+ false));
+ listener.onEvent(null, firestoreException);
}
});
}
@@ -383,40 +373,36 @@ private void resetStream() {
/** Initializes a new stream to the backend with backoff. */
private void initStream() {
firestoreExecutor.schedule(
- new Runnable() {
- @Override
- public void run() {
- try {
+ () -> {
+ try {
+ if (!isActive.get()) {
+ return;
+ }
+
+ synchronized (Watch.this) {
if (!isActive.get()) {
return;
}
- synchronized (Watch.this) {
- if (!isActive.get()) {
- return;
- }
-
- Preconditions.checkState(stream == null);
-
- current = false;
- nextAttempt = backoff.createNextAttempt(nextAttempt);
+ Preconditions.checkState(stream == null);
- Tracing.getTracer().getCurrentSpan().addAnnotation(TraceUtil.SPAN_NAME_LISTEN);
- stream =
- firestore.streamRequest(Watch.this, firestore.getClient().listenCallable());
+ current = false;
+ nextAttempt = backoff.createNextAttempt(nextAttempt);
- ListenRequest.Builder request = ListenRequest.newBuilder();
- request.setDatabase(firestore.getDatabaseName());
- request.setAddTarget(target);
- if (resumeToken != null) {
- request.getAddTargetBuilder().setResumeToken(resumeToken);
- }
+ Tracing.getTracer().getCurrentSpan().addAnnotation(TraceUtil.SPAN_NAME_LISTEN);
+ stream = firestore.streamRequest(Watch.this, firestore.getClient().listenCallable());
- stream.onNext(request.build());
+ ListenRequest.Builder request = ListenRequest.newBuilder();
+ request.setDatabase(firestore.getDatabaseName());
+ request.setAddTarget(target);
+ if (resumeToken != null) {
+ request.getAddTargetBuilder().setResumeToken(resumeToken);
}
- } catch (Throwable throwable) {
- onError(throwable);
+
+ stream.onNext(request.build());
}
+ } catch (Throwable throwable) {
+ onError(throwable);
}
},
nextAttempt.getRandomizedRetryDelay().toMillis(),
@@ -465,13 +451,7 @@ private void pushSnapshot(final Timestamp readTime, ByteString nextResumeToken)
if (!hasPushed || !changes.isEmpty()) {
final QuerySnapshot querySnapshot =
QuerySnapshot.withChanges(query, readTime, documentSet, changes);
- userCallbackExecutor.execute(
- new Runnable() {
- @Override
- public void run() {
- listener.onEvent(querySnapshot, null);
- }
- });
+ userCallbackExecutor.execute(() -> listener.onEvent(querySnapshot, null));
hasPushed = true;
}
@@ -497,7 +477,7 @@ private DocumentChange addDoc(QueryDocumentSnapshot newDocument) {
documentSet = documentSet.add(newDocument);
int newIndex = documentSet.indexOf(resourcePath);
return new DocumentChange(newDocument, Type.ADDED, -1, newIndex);
- };
+ }
/**
* Applies a document modification to the document tree. Returns the DocumentChange event for
@@ -516,7 +496,7 @@ private DocumentChange modifyDoc(QueryDocumentSnapshot newDocument) {
return new DocumentChange(newDocument, Type.MODIFIED, oldIndex, newIndex);
}
return null;
- };
+ }
/**
* Applies the mutations in changeMap to the document tree. Modified 'documentSet' in-place and
@@ -532,17 +512,17 @@ private List computeSnapshot(Timestamp readTime) {
// Process the sorted changes in the order that is expected by our clients (removals, additions,
// and then modifications). We also need to sort the individual changes to assure that
// oldIndex/newIndex keep incrementing.
- Collections.sort(changeSet.deletes, comparator);
+ changeSet.deletes.sort(comparator);
for (QueryDocumentSnapshot delete : changeSet.deletes) {
appliedChanges.add(deleteDoc(delete));
}
- Collections.sort(changeSet.adds, comparator);
+ changeSet.adds.sort(comparator);
for (QueryDocumentSnapshot add : changeSet.adds) {
appliedChanges.add(addDoc(add));
}
- Collections.sort(changeSet.updates, comparator);
+ changeSet.updates.sort(comparator);
for (QueryDocumentSnapshot update : changeSet.updates) {
DocumentChange change = modifyDoc(update);
if (change != null) {
@@ -590,5 +570,5 @@ private static Status getStatus(Throwable throwable) {
private static boolean isResourceExhaustedError(Throwable throwable) {
Status status = getStatus(throwable);
return status != null && status.getCode().equals(Code.RESOURCE_EXHAUSTED);
- };
+ }
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ArraySortedMap.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ArraySortedMap.java
index dd23461964..a27d7effa0 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ArraySortedMap.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ArraySortedMap.java
@@ -19,7 +19,6 @@
import com.google.api.core.InternalApi;
import java.util.AbstractMap;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
@@ -44,7 +43,7 @@ public static ArraySortedMap buildFrom(
Map values,
Builder.KeyTranslator translator,
Comparator comparator) {
- Collections.sort(keys, comparator);
+ keys.sort(comparator);
int size = keys.size();
A[] keyArray = (A[]) new Object[size];
C[] valueArray = (C[]) new Object[size];
@@ -55,12 +54,11 @@ public static ArraySortedMap buildFrom(
valueArray[pos] = value;
pos++;
}
- return new ArraySortedMap(comparator, keyArray, valueArray);
+ return new ArraySortedMap<>(comparator, keyArray, valueArray);
}
public static ArraySortedMap fromMap(Map map, Comparator comparator) {
- return buildFrom(
- new ArrayList(map.keySet()), map, Builder.identityTranslator(), comparator);
+ return buildFrom(new ArrayList<>(map.keySet()), map, Builder.identityTranslator(), comparator);
}
private final K[] keys;
@@ -100,7 +98,7 @@ public ImmutableSortedMap remove(K key) {
} else {
K[] keys = removeFromArray(this.keys, pos);
V[] values = removeFromArray(this.values, pos);
- return new ArraySortedMap(this.comparator, keys, values);
+ return new ArraySortedMap<>(this.comparator, keys, values);
}
}
@@ -114,12 +112,12 @@ public ImmutableSortedMap insert(K key, V value) {
// The key and/or value might have changed, even though the comparison might still yield 0
K[] newKeys = replaceInArray(this.keys, pos, key);
V[] newValues = replaceInArray(this.values, pos, value);
- return new ArraySortedMap(this.comparator, newKeys, newValues);
+ return new ArraySortedMap<>(this.comparator, newKeys, newValues);
}
} else {
if (this.keys.length > Builder.ARRAY_TO_RB_TREE_SIZE_THRESHOLD) {
@SuppressWarnings("unchecked")
- Map map = new HashMap(this.keys.length + 1);
+ Map map = new HashMap<>(this.keys.length + 1);
for (int i = 0; i < this.keys.length; i++) {
map.put(this.keys[i], this.values[i]);
}
@@ -129,7 +127,7 @@ public ImmutableSortedMap insert(K key, V value) {
int newPos = findKeyOrInsertPosition(key);
K[] keys = addToArray(this.keys, newPos, key);
V[] values = addToArray(this.values, newPos, value);
- return new ArraySortedMap(this.comparator, keys, values);
+ return new ArraySortedMap<>(this.comparator, keys, values);
}
}
}
@@ -175,7 +173,7 @@ public Map.Entry next() {
final K key = keys[currentPos];
final V value = values[currentPos];
currentPos = reverse ? currentPos - 1 : currentPos + 1;
- return new AbstractMap.SimpleImmutableEntry(key, value);
+ return new AbstractMap.SimpleImmutableEntry<>(key, value);
}
@Override
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedMap.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedMap.java
index 7191b38ada..006dbd0ef2 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedMap.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedMap.java
@@ -120,20 +120,14 @@ public static class Builder {
static final int ARRAY_TO_RB_TREE_SIZE_THRESHOLD = 25;
public static ImmutableSortedMap emptyMap(Comparator comparator) {
- return new ArraySortedMap(comparator);
+ return new ArraySortedMap<>(comparator);
}
public interface KeyTranslator {
- public D translate(C key);
+ D translate(C key);
}
- private static final KeyTranslator IDENTITY_TRANSLATOR =
- new KeyTranslator() {
- @Override
- public Object translate(Object key) {
- return key;
- }
- };
+ private static final KeyTranslator IDENTITY_TRANSLATOR = key -> key;
@SuppressWarnings("unchecked")
public static KeyTranslator identityTranslator() {
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedMapIterator.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedMapIterator.java
index 9c0c1c01ab..58444ae37a 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedMapIterator.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedMapIterator.java
@@ -36,7 +36,7 @@ public class ImmutableSortedMapIterator implements Iterator root, K startKey, Comparator comparator, boolean isReverse) {
- this.nodeStack = new Stack>();
+ this.nodeStack = new Stack<>();
this.isReverse = isReverse;
LLRBNode node = root;
@@ -81,7 +81,7 @@ public boolean hasNext() {
public Map.Entry next() {
try {
final LLRBValueNode node = nodeStack.pop();
- Map.Entry entry = new AbstractMap.SimpleEntry(node.getKey(), node.getValue());
+ Map.Entry entry = new AbstractMap.SimpleEntry<>(node.getKey(), node.getValue());
if (this.isReverse) {
LLRBNode next = node.getLeft();
while (!next.isEmpty()) {
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedSet.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedSet.java
index 6c41979037..13b74472f0 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedSet.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/ImmutableSortedSet.java
@@ -57,8 +57,8 @@ public ImmutableSortedSet(List elems, Comparator comparator) {
this.map =
ImmutableSortedMap.Builder.buildFrom(
elems,
- Collections.emptyMap(),
- ImmutableSortedMap.Builder.identityTranslator(),
+ Collections.emptyMap(),
+ ImmutableSortedMap.Builder.identityTranslator(),
comparator);
}
@@ -89,11 +89,11 @@ public boolean contains(T entry) {
public ImmutableSortedSet remove(T entry) {
ImmutableSortedMap newMap = this.map.remove(entry);
- return (newMap == this.map) ? this : new ImmutableSortedSet(newMap);
+ return (newMap == this.map) ? this : new ImmutableSortedSet<>(newMap);
}
public ImmutableSortedSet insert(T entry) {
- return new ImmutableSortedSet(map.insert(entry, null));
+ return new ImmutableSortedSet<>(map.insert(entry, null));
}
public T getMinEntry() {
@@ -113,19 +113,19 @@ public boolean isEmpty() {
}
public Iterator iterator() {
- return new WrappedEntryIterator(this.map.iterator());
+ return new WrappedEntryIterator<>(this.map.iterator());
}
public Iterator iteratorFrom(T entry) {
- return new WrappedEntryIterator(this.map.iteratorFrom(entry));
+ return new WrappedEntryIterator<>(this.map.iteratorFrom(entry));
}
public Iterator reverseIteratorFrom(T entry) {
- return new WrappedEntryIterator(this.map.reverseIteratorFrom(entry));
+ return new WrappedEntryIterator<>(this.map.reverseIteratorFrom(entry));
}
public Iterator reverseIterator() {
- return new WrappedEntryIterator(this.map.reverseIterator());
+ return new WrappedEntryIterator<>(this.map.reverseIterator());
}
public T getPredecessorEntry(T entry) {
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBBlackValueNode.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBBlackValueNode.java
index d78043ae26..05d5a6296c 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBBlackValueNode.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBBlackValueNode.java
@@ -71,6 +71,6 @@ protected LLRBValueNode copy(K key, V value, LLRBNode left, LLRBNode
V newValue = value == null ? this.getValue() : value;
LLRBNode newLeft = left == null ? this.getLeft() : left;
LLRBNode newRight = right == null ? this.getRight() : right;
- return new LLRBBlackValueNode(newKey, newValue, newLeft, newRight);
+ return new LLRBBlackValueNode<>(newKey, newValue, newLeft, newRight);
}
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBEmptyNode.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBEmptyNode.java
index bf37c84223..8658432614 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBEmptyNode.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBEmptyNode.java
@@ -41,7 +41,7 @@ public LLRBNode copy(
@Override
public LLRBNode insert(K key, V value, Comparator comparator) {
- return new LLRBRedValueNode(key, value);
+ return new LLRBRedValueNode<>(key, value);
}
@Override
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBNode.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBNode.java
index 8dec8bb744..b71a09267a 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBNode.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/collection/LLRBNode.java
@@ -24,11 +24,11 @@
@InternalApi
public interface LLRBNode