diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoCollection.java b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoCollection.java
index c9f8709d..bee4890d 100755
--- a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoCollection.java
+++ b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoCollection.java
@@ -691,8 +691,7 @@ private void convertSelectorToDocument(Document selector, Document document) {
continue;
} else if (key.startsWith("$")) {
continue;
- } else if (value instanceof Document) {
- Document documentValue = (Document) value;
+ } else if (value instanceof Document documentValue) {
if (documentValue.keySet().equals(Set.of("$eq"))) {
changeSubdocumentValueOrThrow(document, key, documentValue.get("$eq"));
}
diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoDatabase.java b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoDatabase.java
index 3f492fe5..5d91a64d 100644
--- a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoDatabase.java
+++ b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoDatabase.java
@@ -865,8 +865,7 @@ private Document toWriteError(int index, MongoServerException e) {
Document error = new Document();
error.put("index", index);
error.put("errmsg", e.getMessageWithoutErrorCode());
- if (e instanceof MongoServerError) {
- MongoServerError err = (MongoServerError) e;
+ if (e instanceof MongoServerError err) {
error.put("code", Integer.valueOf(err.getCode()));
error.putIfNotNull("codeName", err.getCodeName());
}
@@ -876,8 +875,7 @@ private Document toWriteError(int index, MongoServerException e) {
private Document toError(Channel channel, MongoServerException ex) {
Document error = new Document();
error.put("err", ex.getMessageWithoutErrorCode());
- if (ex instanceof MongoServerError) {
- MongoServerError err = (MongoServerError) ex;
+ if (ex instanceof MongoServerError err) {
error.put("code", Integer.valueOf(err.getCode()));
error.putIfNotNull("codeName", err.getCodeName());
}
diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractUniqueIndex.java b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractUniqueIndex.java
index 909f326d..9050b0e2 100644
--- a/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractUniqueIndex.java
+++ b/core/src/main/java/de/bwaldvogel/mongo/backend/AbstractUniqueIndex.java
@@ -202,11 +202,10 @@ public synchronized Iterable
getPositions(Document query) {
}
}
return positions;
- } else if (queriedValue instanceof Document) {
+ } else if (queriedValue instanceof Document keyObj) {
if (isCompoundIndex()) {
throw new UnsupportedOperationException("Not yet implemented");
}
- Document keyObj = (Document) queriedValue;
if (Utils.containsQueryExpression(keyObj)) {
String expression = CollectionUtils.getSingleElement(keyObj.keySet(),
() -> new UnsupportedOperationException("illegal query key: " + queriedKeyValues));
@@ -215,8 +214,7 @@ public synchronized Iterable
getPositions(Document query) {
return getPositionsForExpression(keyObj, expression);
}
}
- } else if (queriedValue instanceof Collection) {
- Collection> values = (Collection>) queriedValue;
+ } else if (queriedValue instanceof Collection> values) {
return values.stream()
.map(KeyValue::new)
.map(this::getPosition)
diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/CollectionUtils.java b/core/src/main/java/de/bwaldvogel/mongo/backend/CollectionUtils.java
index 0fe25747..8925ba29 100644
--- a/core/src/main/java/de/bwaldvogel/mongo/backend/CollectionUtils.java
+++ b/core/src/main/java/de/bwaldvogel/mongo/backend/CollectionUtils.java
@@ -68,8 +68,7 @@ static List> multiplyWithOtherElements(Collection allValues, Coll
}
static T getElementAtPosition(Iterable iterable, int pos) {
- if (iterable instanceof List) {
- List list = (List) iterable;
+ if (iterable instanceof List list) {
return list.get(pos);
} else {
Iterator iterator = iterable.iterator();
diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcher.java b/core/src/main/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcher.java
index 510dc0b9..cdf1d413 100644
--- a/core/src/main/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcher.java
+++ b/core/src/main/java/de/bwaldvogel/mongo/backend/DefaultQueryMatcher.java
@@ -59,8 +59,7 @@ private void validateQueryValue(Object queryValue, String key) {
QueryOperator queryOperator = QueryOperator.fromValue(operator);
if (queryOperator == QueryOperator.TYPE) {
Object value = queryObject.get(operator);
- if (value instanceof Collection) {
- Collection> values = (Collection>) value;
+ if (value instanceof Collection> values) {
if (values.isEmpty()) {
throw new FailedToParseException(key + " must match at least one type");
}
@@ -134,8 +133,7 @@ private boolean checkMatch(Object queryValue, List keys, Object value) {
return checkMatchesValue(queryValue, value);
}
- if (queryValue instanceof Document) {
- Document query = (Document) queryValue;
+ if (queryValue instanceof Document query) {
if (query.containsKey(QueryOperator.ALL.getValue())) {
Object allQuery = query.get(QueryOperator.ALL.getValue());
return checkMatchesAllDocuments(allQuery, keys, value);
@@ -171,10 +169,8 @@ private boolean checkMatch(Object queryValue, List keys, Object value) {
return checkMatchesValue(queryValue, Missing.getInstance());
}
- if (documentValue instanceof Collection>) {
- Collection> documentValues = (Collection>) documentValue;
- if (queryValue instanceof Document) {
- Document queryDocument = (Document) queryValue;
+ if (documentValue instanceof Collection> documentValues) {
+ if (queryValue instanceof Document queryDocument) {
boolean matches = checkMatchesAnyValue(queryDocument, keys, document, documentValues);
if (matches) {
return true;
@@ -338,9 +334,7 @@ private boolean checkMatchesValue(Object queryValue, Object value, boolean requi
}
}
- if (queryValue instanceof Document) {
- Document queryObject = (Document) queryValue;
-
+ if (queryValue instanceof Document queryObject) {
if (queryObject.keySet().equals(Constants.REFERENCE_KEYS)) {
if (value instanceof Document) {
return matches((Document) value, queryObject);
@@ -412,8 +406,7 @@ private boolean checkMatchesElemValues(Object queryValue, Object values) {
}
private boolean checkMatchesAnyValue(Object queryValue, Collection> values) {
- if (queryValue instanceof Document) {
- Document queryDocument = (Document) queryValue;
+ if (queryValue instanceof Document queryDocument) {
if (queryDocument.keySet().equals(Set.of(QueryOperator.ELEM_MATCH.getValue()))) {
queryValue = queryDocument.get(QueryOperator.ELEM_MATCH.getValue());
}
@@ -445,13 +438,11 @@ private boolean checkExpressionMatch(Object value, Object expressionValue, Strin
case IN:
Collection> queriedObjects = (Collection>) expressionValue;
for (Object o : queriedObjects) {
- if (o instanceof BsonRegularExpression && value instanceof String) {
- BsonRegularExpression pattern = (BsonRegularExpression) o;
- if (pattern.matcher((String) value).find()) {
+ if (o instanceof BsonRegularExpression pattern && value instanceof String strValue) {
+ if (pattern.matcher(strValue).find()) {
return true;
}
- } else if (value instanceof Collection && !(o instanceof Collection)) {
- Collection> values = (Collection>) value;
+ } else if (value instanceof Collection> values && !(o instanceof Collection)) {
return values.stream().anyMatch(v -> Utils.nullAwareEquals(o, v));
} else if (Utils.nullAwareEquals(o, value)) {
return true;
@@ -533,8 +524,7 @@ static boolean matchTypes(Object value, Object expressionValue) {
return matchTypes(value, BsonType.forString((String) expressionValue));
} else if (expressionValue instanceof Number) {
return matchTypes(value, BsonType.forNumber((Number) expressionValue));
- } else if (expressionValue instanceof Collection) {
- Collection> values = (Collection>) expressionValue;
+ } else if (expressionValue instanceof Collection> values) {
for (Object type : values) {
if (matchTypes(value, type)) {
return true;
diff --git a/core/src/main/java/de/bwaldvogel/mongo/backend/FieldUpdates.java b/core/src/main/java/de/bwaldvogel/mongo/backend/FieldUpdates.java
index 0fcf83e7..bb0b4b3b 100644
--- a/core/src/main/java/de/bwaldvogel/mongo/backend/FieldUpdates.java
+++ b/core/src/main/java/de/bwaldvogel/mongo/backend/FieldUpdates.java
@@ -140,8 +140,7 @@ private void handlePush(String key, Object changeValue) {
Integer slice = null;
Comparator