Skip to content

Commit 1738ec1

Browse files
committed
Refactor to instanceof pattern variable
1 parent 3e295a9 commit 1738ec1

24 files changed

+93
-96
lines changed

src/main/java/org/springframework/data/couchbase/core/AbstractTemplateSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ public Long getCas(final Object entity) {
180180
long cas = 0;
181181
if (versionProperty != null) {
182182
Object casObject = accessor.getProperty(versionProperty);
183-
if (casObject instanceof Number) {
184-
cas = ((Number) casObject).longValue();
183+
if (casObject instanceof Number number) {
184+
cas = number.longValue();
185185
}
186186
}
187187
return cas;

src/main/java/org/springframework/data/couchbase/core/CouchbaseExceptionTranslator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ public final DataAccessException translateExceptionIfPossible(final RuntimeExcep
126126
return new DataRetrievalFailureException(ex.getMessage(), ex);
127127
}
128128

129-
if (ex instanceof TransactionOperationFailedException) {
129+
if (ex instanceof TransactionOperationFailedException transactionOperationFailedException) {
130130
// Replace the TransactionOperationFailedException, since we want the Spring operation to fail with a
131131
// Spring error. Internal state has already been set in the AttemptContext so the retry, rollback etc.
132132
// will get respected regardless of what gets propagated (or not) from the lambda.
133-
return new UncategorizedTransactionDataAccessException((TransactionOperationFailedException) ex);
133+
return new UncategorizedTransactionDataAccessException(transactionOperationFailedException);
134134
}
135135

136136
// Unable to translate exception, therefore just throw the original!

src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ public CouchbaseTemplate(final CouchbaseClientFactory clientFactory, final Couch
7676
this.scanConsistency = scanConsistency;
7777

7878
this.mappingContext = this.converter.getMappingContext();
79-
if (mappingContext instanceof CouchbaseMappingContext) {
80-
CouchbaseMappingContext cmc = (CouchbaseMappingContext) mappingContext;
81-
if (cmc.isAutoIndexCreation()) {
79+
if (mappingContext instanceof CouchbaseMappingContext cmc) {
80+
if (cmc.isAutoIndexCreation()) {
8281
indexCreator = new CouchbasePersistentEntityIndexCreator(cmc, this);
8382
}
8483
}
@@ -264,11 +263,10 @@ private void prepareIndexCreator(final ApplicationContext context) {
264263
}
265264
}
266265

267-
if (context instanceof ConfigurableApplicationContext && indexCreator != null) {
268-
((ConfigurableApplicationContext) context).addApplicationListener(indexCreator);
269-
if (mappingContext instanceof CouchbaseMappingContext) {
270-
CouchbaseMappingContext cmc = (CouchbaseMappingContext) mappingContext;
271-
cmc.setIndexCreator(indexCreator);
266+
if (context instanceof ConfigurableApplicationContext configurableApplicationContext && indexCreator != null) {
267+
configurableApplicationContext.addApplicationListener(indexCreator);
268+
if (mappingContext instanceof CouchbaseMappingContext cmc) {
269+
cmc.setIndexCreator(indexCreator);
272270
}
273271
}
274272
}

src/main/java/org/springframework/data/couchbase/core/ReactiveExistsByIdOperationSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public Mono<Boolean> one(final String id) {
8686
.getCollection(pArgs.getCollection()).reactive().exists(id, buildOptions(pArgs.getOptions()))
8787
.map(ExistsResult::exists))
8888
.onErrorMap(throwable -> {
89-
if (throwable instanceof RuntimeException) {
90-
return template.potentiallyConvertRuntimeException((RuntimeException) throwable);
89+
if (throwable instanceof RuntimeException e) {
90+
return template.potentiallyConvertRuntimeException(e);
9191
} else {
9292
return throwable;
9393
}

src/main/java/org/springframework/data/couchbase/core/ReactiveFindByAnalyticsOperationSupport.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public Flux<T> all() {
119119
}
120120
return TransactionalSupport.verifyNotInTransaction("findByAnalytics").then(template.getCouchbaseClientFactory()
121121
.getCluster().reactive().analyticsQuery(statement, buildAnalyticsOptions())).onErrorMap(throwable -> {
122-
if (throwable instanceof RuntimeException) {
123-
return template.potentiallyConvertRuntimeException((RuntimeException) throwable);
122+
if (throwable instanceof RuntimeException e) {
123+
return template.potentiallyConvertRuntimeException(e);
124124
} else {
125125
return throwable;
126126
}
@@ -153,8 +153,8 @@ public Mono<Long> count() {
153153
}
154154
return TransactionalSupport.verifyNotInTransaction("findByAnalytics").then(template.getCouchbaseClientFactory()
155155
.getCluster().reactive().analyticsQuery(statement, buildAnalyticsOptions())).onErrorMap(throwable -> {
156-
if (throwable instanceof RuntimeException) {
157-
return template.potentiallyConvertRuntimeException((RuntimeException) throwable);
156+
if (throwable instanceof RuntimeException e) {
157+
return template.potentiallyConvertRuntimeException(e);
158158
} else {
159159
return throwable;
160160
}

src/main/java/org/springframework/data/couchbase/core/ReactiveFindByIdOperationSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ public Mono<T> one(final Object id) {
132132
}
133133
return Mono.error(throwable);
134134
}).onErrorMap(throwable -> {
135-
if (throwable instanceof RuntimeException) {
136-
return template.potentiallyConvertRuntimeException((RuntimeException) throwable);
135+
if (throwable instanceof RuntimeException e) {
136+
return template.potentiallyConvertRuntimeException(e);
137137
} else {
138138
return throwable;
139139
}

src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ public Flux<T> all() {
205205
});
206206

207207
return allResult.onErrorMap(throwable -> {
208-
if (throwable instanceof RuntimeException) {
209-
return template.potentiallyConvertRuntimeException((RuntimeException) throwable);
208+
if (throwable instanceof RuntimeException e) {
209+
return template.potentiallyConvertRuntimeException(e);
210210
} else {
211211
return throwable;
212212
}
213-
}).flatMapMany(o -> o instanceof ReactiveQueryResult ? ((ReactiveQueryResult) o).rowsAsObject()
213+
}).flatMapMany(o -> o instanceof ReactiveQueryResult reactiveQueryResult ? reactiveQueryResult.rowsAsObject()
214214
: Flux.fromIterable(((TransactionQueryResult) o).rowsAsObject())).flatMap(row -> {
215215
String id = "";
216216
Long cas = Long.valueOf(0);
@@ -273,12 +273,12 @@ public Mono<Long> count() {
273273
});
274274

275275
return allResult.onErrorMap(throwable -> {
276-
if (throwable instanceof RuntimeException) {
277-
return template.potentiallyConvertRuntimeException((RuntimeException) throwable);
276+
if (throwable instanceof RuntimeException e) {
277+
return template.potentiallyConvertRuntimeException(e);
278278
} else {
279279
return throwable;
280280
}
281-
}).flatMapMany(o -> o instanceof ReactiveQueryResult ? ((ReactiveQueryResult) o).rowsAsObject()
281+
}).flatMapMany(o -> o instanceof ReactiveQueryResult reactiveQueryResult ? reactiveQueryResult.rowsAsObject()
282282
: Flux.fromIterable(((TransactionQueryResult) o).rowsAsObject()))
283283
.map(row -> row.getLong(row.getNames().iterator().next())).next();
284284
}

src/main/java/org/springframework/data/couchbase/core/ReactiveFindFromReplicasByIdOperationSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public Mono<T> any(final String id) {
8989
.flatMap(result -> support.decodeEntity(id, result.contentAs(String.class), result.cas(), returnType,
9090
pArgs.getScope(), pArgs.getCollection(), null, null))
9191
.onErrorMap(throwable -> {
92-
if (throwable instanceof RuntimeException) {
93-
return template.potentiallyConvertRuntimeException((RuntimeException) throwable);
92+
if (throwable instanceof RuntimeException e) {
93+
return template.potentiallyConvertRuntimeException(e);
9494
} else {
9595
return throwable;
9696
}

src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ public Mono<T> one(T object) {
124124
null, null));
125125
}
126126
})).onErrorMap(throwable -> {
127-
if (throwable instanceof RuntimeException) {
128-
return template.potentiallyConvertRuntimeException((RuntimeException) throwable);
127+
if (throwable instanceof RuntimeException e) {
128+
return template.potentiallyConvertRuntimeException(e);
129129
} else {
130130
return throwable;
131131
}

src/main/java/org/springframework/data/couchbase/core/ReactiveMutateInByIdOperationSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public Mono<T> one(T object) {
116116
});
117117

118118
return reactiveEntity.onErrorMap(throwable -> {
119-
if (throwable instanceof RuntimeException) {
120-
return template.potentiallyConvertRuntimeException((RuntimeException) throwable);
119+
if (throwable instanceof RuntimeException e) {
120+
return template.potentiallyConvertRuntimeException(e);
121121
} else {
122122
return throwable;
123123
}

0 commit comments

Comments
 (0)