committed by
Christoph Strobl
parent
7f74794a11
commit
561c3d4f39
@@ -96,15 +96,14 @@ class MongoResultsWriter implements ResultsWriter {
|
||||
for (Object key : doc.keySet()) {
|
||||
|
||||
Object value = doc.get(key);
|
||||
if (value instanceof Document) {
|
||||
value = fixDocumentKeys((Document) value);
|
||||
} else if (value instanceof BasicDBObject) {
|
||||
value = fixDocumentKeys(new Document((BasicDBObject) value));
|
||||
if (value instanceof Document document) {
|
||||
value = fixDocumentKeys(document);
|
||||
} else if (value instanceof BasicDBObject basicDBObject) {
|
||||
value = fixDocumentKeys(new Document(basicDBObject));
|
||||
}
|
||||
|
||||
if (key instanceof String) {
|
||||
if (key instanceof String newKey) {
|
||||
|
||||
String newKey = (String) key;
|
||||
if (newKey.contains(".")) {
|
||||
newKey = newKey.replace('.', ',');
|
||||
}
|
||||
|
||||
@@ -150,12 +150,12 @@ public class ChangeStreamOptions {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
if (timestamp instanceof Instant) {
|
||||
return new BsonTimestamp((int) ((Instant) timestamp).getEpochSecond(), 0);
|
||||
if (timestamp instanceof Instant instant) {
|
||||
return new BsonTimestamp((int) instant.getEpochSecond(), 0);
|
||||
}
|
||||
|
||||
if (timestamp instanceof BsonTimestamp) {
|
||||
return Instant.ofEpochSecond(((BsonTimestamp) timestamp).getTime());
|
||||
if (timestamp instanceof BsonTimestamp bsonTimestamp) {
|
||||
return Instant.ofEpochSecond(bsonTimestamp.getTime());
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
|
||||
@@ -64,18 +64,15 @@ class CountQuery {
|
||||
|
||||
for (Map.Entry<String, Object> entry : source.entrySet()) {
|
||||
|
||||
if (entry.getValue() instanceof Document && requiresRewrite(entry.getValue())) {
|
||||
if (entry.getValue() instanceof Document document && requiresRewrite(entry.getValue())) {
|
||||
|
||||
Document theValue = (Document) entry.getValue();
|
||||
target.putAll(createGeoWithin(entry.getKey(), theValue, source.get("$and")));
|
||||
target.putAll(createGeoWithin(entry.getKey(), document, source.get("$and")));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry.getValue() instanceof Collection && requiresRewrite(entry.getValue())) {
|
||||
if (entry.getValue() instanceof Collection<?> collection && requiresRewrite(entry.getValue())) {
|
||||
|
||||
Collection<?> source = (Collection<?>) entry.getValue();
|
||||
|
||||
target.put(entry.getKey(), rewriteCollection(source));
|
||||
target.put(entry.getKey(), rewriteCollection(collection));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -96,12 +93,12 @@ class CountQuery {
|
||||
*/
|
||||
private boolean requiresRewrite(Object valueToInspect) {
|
||||
|
||||
if (valueToInspect instanceof Document) {
|
||||
return requiresRewrite((Document) valueToInspect);
|
||||
if (valueToInspect instanceof Document document) {
|
||||
return requiresRewrite(document);
|
||||
}
|
||||
|
||||
if (valueToInspect instanceof Collection) {
|
||||
return requiresRewrite((Collection<?>) valueToInspect);
|
||||
if (valueToInspect instanceof Collection<?> collection) {
|
||||
return requiresRewrite(collection);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -110,7 +107,7 @@ class CountQuery {
|
||||
private boolean requiresRewrite(Collection<?> collection) {
|
||||
|
||||
for (Object o : collection) {
|
||||
if (o instanceof Document && requiresRewrite((Document) o)) {
|
||||
if (o instanceof Document document && requiresRewrite(document)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -139,8 +136,8 @@ class CountQuery {
|
||||
Collection<Object> rewrittenCollection = new ArrayList<>(source.size());
|
||||
|
||||
for (Object item : source) {
|
||||
if (item instanceof Document && requiresRewrite(item)) {
|
||||
rewrittenCollection.add(CountQuery.of((Document) item).toQueryDocument());
|
||||
if (item instanceof Document document && requiresRewrite(item)) {
|
||||
rewrittenCollection.add(CountQuery.of(document).toQueryDocument());
|
||||
} else {
|
||||
rewrittenCollection.add(item);
|
||||
}
|
||||
@@ -242,8 +239,8 @@ class CountQuery {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value instanceof Point) {
|
||||
return Arrays.asList(((Point) value).getX(), ((Point) value).getY());
|
||||
if (value instanceof Point point) {
|
||||
return Arrays.asList(point.getX(), point.getY());
|
||||
}
|
||||
|
||||
if (value instanceof Document document) {
|
||||
|
||||
@@ -288,13 +288,13 @@ class DefaultBulkOperations extends BulkOperationsSupport implements BulkOperati
|
||||
|
||||
maybeEmitBeforeSaveEvent(it);
|
||||
|
||||
if (it.model() instanceof InsertOneModel) {
|
||||
if (it.model() instanceof InsertOneModel<Document> model) {
|
||||
|
||||
Document target = ((InsertOneModel<Document>) it.model()).getDocument();
|
||||
Document target = model.getDocument();
|
||||
maybeInvokeBeforeSaveCallback(it.source(), target);
|
||||
} else if (it.model() instanceof ReplaceOneModel) {
|
||||
} else if (it.model() instanceof ReplaceOneModel<Document> model) {
|
||||
|
||||
Document target = ((ReplaceOneModel<Document>) it.model()).getReplacement();
|
||||
Document target = model.getReplacement();
|
||||
maybeInvokeBeforeSaveCallback(it.source(), target);
|
||||
}
|
||||
|
||||
@@ -348,8 +348,8 @@ class DefaultBulkOperations extends BulkOperationsSupport implements BulkOperati
|
||||
|
||||
private Document getMappedObject(Object source) {
|
||||
|
||||
if (source instanceof Document) {
|
||||
return (Document) source;
|
||||
if (source instanceof Document document) {
|
||||
return document;
|
||||
}
|
||||
|
||||
Document sink = new Document();
|
||||
@@ -364,13 +364,13 @@ class DefaultBulkOperations extends BulkOperationsSupport implements BulkOperati
|
||||
|
||||
private void maybeInvokeAfterSaveCallback(SourceAwareWriteModelHolder holder) {
|
||||
|
||||
if (holder.model() instanceof InsertOneModel) {
|
||||
if (holder.model() instanceof InsertOneModel<Document> model) {
|
||||
|
||||
Document target = ((InsertOneModel<Document>) holder.model()).getDocument();
|
||||
Document target = model.getDocument();
|
||||
maybeInvokeAfterSaveCallback(holder.source(), target);
|
||||
} else if (holder.model() instanceof ReplaceOneModel) {
|
||||
} else if (holder.model() instanceof ReplaceOneModel<Document> model) {
|
||||
|
||||
Document target = ((ReplaceOneModel<Document>) holder.model()).getReplacement();
|
||||
Document target = model.getReplacement();
|
||||
maybeInvokeAfterSaveCallback(holder.source(), target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ class DefaultScriptOperations implements ScriptOperations {
|
||||
return args;
|
||||
}
|
||||
|
||||
List<Object> convertedValues = new ArrayList<Object>(args.length);
|
||||
List<Object> convertedValues = new ArrayList<>(args.length);
|
||||
|
||||
for (Object arg : args) {
|
||||
convertedValues.add(arg instanceof String && quote ? String.format("'%s'", arg)
|
||||
|
||||
@@ -575,8 +575,8 @@ class EntityOperations {
|
||||
|
||||
@Override
|
||||
public MappedDocument toMappedDocument(MongoWriter<? super T> writer) {
|
||||
return MappedDocument.of(map instanceof Document //
|
||||
? (Document) map //
|
||||
return MappedDocument.of(map instanceof Document document //
|
||||
? document //
|
||||
: new Document(map));
|
||||
}
|
||||
|
||||
@@ -656,8 +656,8 @@ class EntityOperations {
|
||||
public MappedDocument toMappedDocument(MongoWriter<? super T> writer) {
|
||||
|
||||
T bean = getBean();
|
||||
bean = (T) (bean instanceof Document //
|
||||
? (Document) bean //
|
||||
bean = (T) (bean instanceof Document document//
|
||||
? document //
|
||||
: new Document(bean));
|
||||
Document document = new Document();
|
||||
writer.write(bean, document);
|
||||
|
||||
@@ -98,9 +98,7 @@ class ExecutableAggregationOperationSupport implements ExecutableAggregationOper
|
||||
return collection;
|
||||
}
|
||||
|
||||
if (aggregation instanceof TypedAggregation) {
|
||||
|
||||
TypedAggregation<?> typedAggregation = (TypedAggregation<?>) aggregation;
|
||||
if (aggregation instanceof TypedAggregation typedAggregation) {
|
||||
|
||||
if (typedAggregation.getInputType() != null) {
|
||||
return template.getCollectionName(typedAggregation.getInputType());
|
||||
|
||||
@@ -322,7 +322,7 @@ class MappingMongoJsonSchemaCreator implements MongoJsonSchemaCreator {
|
||||
|
||||
private TypedJsonSchemaObject createSchemaObject(Object type, Collection<?> possibleValues) {
|
||||
|
||||
TypedJsonSchemaObject schemaObject = type instanceof Type ? JsonSchemaObject.of(Type.class.cast(type))
|
||||
TypedJsonSchemaObject schemaObject = type instanceof Type typeObject ? JsonSchemaObject.of(typeObject)
|
||||
: JsonSchemaObject.of(Class.class.cast(type));
|
||||
|
||||
if (!CollectionUtils.isEmpty(possibleValues)) {
|
||||
@@ -331,23 +331,22 @@ class MappingMongoJsonSchemaCreator implements MongoJsonSchemaCreator {
|
||||
return schemaObject;
|
||||
}
|
||||
|
||||
private String computePropertyFieldName(PersistentProperty property) {
|
||||
private String computePropertyFieldName(PersistentProperty<?> property) {
|
||||
|
||||
return property instanceof MongoPersistentProperty ? ((MongoPersistentProperty) property).getFieldName()
|
||||
: property.getName();
|
||||
return property instanceof MongoPersistentProperty mongoPersistentProperty ?
|
||||
mongoPersistentProperty.getFieldName() : property.getName();
|
||||
}
|
||||
|
||||
private boolean isRequiredProperty(PersistentProperty property) {
|
||||
private boolean isRequiredProperty(PersistentProperty<?> property) {
|
||||
return property.getType().isPrimitive();
|
||||
}
|
||||
|
||||
private Class<?> computeTargetType(PersistentProperty<?> property) {
|
||||
|
||||
if (!(property instanceof MongoPersistentProperty)) {
|
||||
if (!(property instanceof MongoPersistentProperty mongoProperty)) {
|
||||
return property.getType();
|
||||
}
|
||||
|
||||
MongoPersistentProperty mongoProperty = (MongoPersistentProperty) property;
|
||||
if (!mongoProperty.isIdProperty()) {
|
||||
return mongoProperty.getFieldType();
|
||||
}
|
||||
|
||||
@@ -99,12 +99,12 @@ public class MongoExceptionTranslator implements PersistenceExceptionTranslator
|
||||
|
||||
if (DATA_INTEGRITY_EXCEPTIONS.contains(exception)) {
|
||||
|
||||
if (ex instanceof MongoServerException) {
|
||||
if (((MongoServerException) ex).getCode() == 11000) {
|
||||
if (ex instanceof MongoServerException mse) {
|
||||
if (mse.getCode() == 11000) {
|
||||
return new DuplicateKeyException(ex.getMessage(), ex);
|
||||
}
|
||||
if (ex instanceof MongoBulkWriteException) {
|
||||
for (BulkWriteError x : ((MongoBulkWriteException) ex).getWriteErrors()) {
|
||||
if (ex instanceof MongoBulkWriteException bulkException) {
|
||||
for (BulkWriteError x : bulkException.getWriteErrors()) {
|
||||
if (x.getCode() == 11000) {
|
||||
return new DuplicateKeyException(ex.getMessage(), ex);
|
||||
}
|
||||
@@ -116,9 +116,9 @@ public class MongoExceptionTranslator implements PersistenceExceptionTranslator
|
||||
}
|
||||
|
||||
// All other MongoExceptions
|
||||
if (ex instanceof MongoException) {
|
||||
if (ex instanceof MongoException mongoException) {
|
||||
|
||||
int code = ((MongoException) ex).getCode();
|
||||
int code = mongoException.getCode();
|
||||
|
||||
if (MongoDbErrorCodes.isDuplicateKeyCode(code)) {
|
||||
return new DuplicateKeyException(ex.getMessage(), ex);
|
||||
|
||||
@@ -255,9 +255,7 @@ public class MongoTemplate
|
||||
// We always have a mapping context in the converter, whether it's a simple one or not
|
||||
mappingContext = this.mongoConverter.getMappingContext();
|
||||
// We create indexes based on mapping events
|
||||
if (mappingContext instanceof MongoMappingContext) {
|
||||
|
||||
MongoMappingContext mappingContext = (MongoMappingContext) this.mappingContext;
|
||||
if (mappingContext instanceof MongoMappingContext mappingContext) {
|
||||
|
||||
if (mappingContext.isAutoIndexCreation()) {
|
||||
|
||||
@@ -276,8 +274,8 @@ public class MongoTemplate
|
||||
|
||||
// we need to (re)create the MappingMongoConverter as we need to have it use a DbRefResolver that operates within
|
||||
// the sames session. Otherwise loading referenced objects would happen outside of it.
|
||||
if (that.mongoConverter instanceof MappingMongoConverter) {
|
||||
this.mongoConverter = ((MappingMongoConverter) that.mongoConverter).with(dbFactory);
|
||||
if (that.mongoConverter instanceof MappingMongoConverter mappingMongoConverter) {
|
||||
this.mongoConverter = mappingMongoConverter.with(dbFactory);
|
||||
} else {
|
||||
this.mongoConverter = that.mongoConverter;
|
||||
}
|
||||
@@ -366,8 +364,8 @@ public class MongoTemplate
|
||||
setEntityCallbacks(EntityCallbacks.create(applicationContext));
|
||||
}
|
||||
|
||||
if (mappingContext instanceof ApplicationEventPublisherAware) {
|
||||
((ApplicationEventPublisherAware) mappingContext).setApplicationEventPublisher(eventPublisher);
|
||||
if (mappingContext instanceof ApplicationEventPublisherAware applicationEventPublisherAware) {
|
||||
applicationEventPublisherAware.setApplicationEventPublisher(eventPublisher);
|
||||
}
|
||||
|
||||
resourceLoader = applicationContext;
|
||||
@@ -449,8 +447,8 @@ public class MongoTemplate
|
||||
}
|
||||
}
|
||||
|
||||
if (context instanceof ConfigurableApplicationContext && indexCreator != null) {
|
||||
((ConfigurableApplicationContext) context).addApplicationListener(indexCreator);
|
||||
if (context instanceof ConfigurableApplicationContext configurableApplicationContext && indexCreator != null) {
|
||||
configurableApplicationContext.addApplicationListener(indexCreator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1312,7 +1310,7 @@ public class MongoTemplate
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(WriteResultChecking.EXCEPTION, writeResultChecking)) {
|
||||
if (wc == null || wc.getWObject() == null
|
||||
|| (wc.getWObject() instanceof Number && ((Number) wc.getWObject()).intValue() < 1)) {
|
||||
|| (wc.getWObject() instanceof Number concern && concern.intValue() < 1)) {
|
||||
return WriteConcern.ACKNOWLEDGED;
|
||||
}
|
||||
}
|
||||
@@ -2230,7 +2228,7 @@ public class MongoTemplate
|
||||
cursor = hintFunction.apply(mongoDbFactory, cursor::hintString, cursor::hint);
|
||||
}
|
||||
|
||||
Class<?> domainType = aggregation instanceof TypedAggregation ? ((TypedAggregation) aggregation).getInputType()
|
||||
Class<?> domainType = aggregation instanceof TypedAggregation typedAggregation ? typedAggregation.getInputType()
|
||||
: null;
|
||||
|
||||
Optionals.firstNonEmpty(options::getCollation, //
|
||||
@@ -3120,8 +3118,8 @@ public class MongoTemplate
|
||||
opts.arrayFilters(arrayFilters);
|
||||
}
|
||||
|
||||
if (update instanceof Document) {
|
||||
return collectionPreparer.prepare(collection).findOneAndUpdate(query, (Document) update, opts);
|
||||
if (update instanceof Document document) {
|
||||
return collectionPreparer.prepare(collection).findOneAndUpdate(query, document, opts);
|
||||
} else if (update instanceof List) {
|
||||
return collectionPreparer.prepare(collection).findOneAndUpdate(query, (List<Document>) update, opts);
|
||||
}
|
||||
|
||||
@@ -388,12 +388,12 @@ class QueryOperations {
|
||||
|
||||
for (Entry<String, Object> entry : fields.entrySet()) {
|
||||
|
||||
if (entry.getValue() instanceof MongoExpression) {
|
||||
if (entry.getValue() instanceof MongoExpression mongoExpression) {
|
||||
|
||||
AggregationOperationContext ctx = entity == null ? Aggregation.DEFAULT_CONTEXT
|
||||
: new RelaxedTypeBasedAggregationOperationContext(entity.getType(), mappingContext, queryMapper);
|
||||
|
||||
evaluated.put(entry.getKey(), AggregationExpression.from((MongoExpression) entry.getValue()).toDocument(ctx));
|
||||
evaluated.put(entry.getKey(), AggregationExpression.from(mongoExpression).toDocument(ctx));
|
||||
} else {
|
||||
evaluated.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
@@ -456,7 +456,7 @@ class QueryOperations {
|
||||
*/
|
||||
private DistinctQueryContext(@Nullable Object query, String fieldName) {
|
||||
|
||||
super(query instanceof Document ? new BasicQuery((Document) query) : (Query) query);
|
||||
super(query instanceof Document document ? new BasicQuery(document) : (Query) query);
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
@@ -907,10 +907,10 @@ class QueryOperations {
|
||||
|
||||
this.aggregation = aggregation;
|
||||
|
||||
if (aggregation instanceof TypedAggregation) {
|
||||
this.inputType = ((TypedAggregation<?>) aggregation).getInputType();
|
||||
} else if (aggregationOperationContext instanceof TypeBasedAggregationOperationContext) {
|
||||
this.inputType = ((TypeBasedAggregationOperationContext) aggregationOperationContext).getType();
|
||||
if (aggregation instanceof TypedAggregation typedAggregation) {
|
||||
this.inputType = typedAggregation.getInputType();
|
||||
} else if (aggregationOperationContext instanceof TypeBasedAggregationOperationContext typeBasedAggregationOperationContext) {
|
||||
this.inputType = typeBasedAggregationOperationContext.getType();
|
||||
} else {
|
||||
this.inputType = null;
|
||||
}
|
||||
@@ -935,8 +935,8 @@ class QueryOperations {
|
||||
|
||||
this.aggregation = aggregation;
|
||||
|
||||
if (aggregation instanceof TypedAggregation) {
|
||||
this.inputType = ((TypedAggregation<?>) aggregation).getInputType();
|
||||
if (aggregation instanceof TypedAggregation typedAggregation) {
|
||||
this.inputType = typedAggregation.getInputType();
|
||||
} else {
|
||||
this.inputType = inputType;
|
||||
}
|
||||
|
||||
@@ -98,9 +98,7 @@ class ReactiveAggregationOperationSupport implements ReactiveAggregationOperatio
|
||||
return collection;
|
||||
}
|
||||
|
||||
if (aggregation instanceof TypedAggregation) {
|
||||
|
||||
TypedAggregation<?> typedAggregation = (TypedAggregation<?>) aggregation;
|
||||
if (aggregation instanceof TypedAggregation typedAggregation) {
|
||||
|
||||
if (typedAggregation.getInputType() != null) {
|
||||
return template.getCollectionName(typedAggregation.getInputType());
|
||||
|
||||
@@ -93,10 +93,10 @@ class ReactiveChangeStreamOperationSupport implements ReactiveChangeStreamOperat
|
||||
|
||||
return withOptions(builder -> {
|
||||
|
||||
if (token instanceof Instant) {
|
||||
builder.resumeAt((Instant) token);
|
||||
} else if (token instanceof BsonTimestamp) {
|
||||
builder.resumeAt((BsonTimestamp) token);
|
||||
if (token instanceof Instant instant) {
|
||||
builder.resumeAt(instant);
|
||||
} else if (token instanceof BsonTimestamp bsonTimestamp) {
|
||||
builder.resumeAt(bsonTimestamp);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -161,8 +161,8 @@ class ReactiveChangeStreamOperationSupport implements ReactiveChangeStreamOperat
|
||||
}
|
||||
|
||||
options.getFilter().ifPresent(it -> {
|
||||
if (it instanceof Aggregation) {
|
||||
builder.filter((Aggregation) it);
|
||||
if (it instanceof Aggregation aggregation) {
|
||||
builder.filter(aggregation);
|
||||
} else {
|
||||
builder.filter(((List<Document>) it).toArray(new Document[0]));
|
||||
}
|
||||
|
||||
@@ -265,9 +265,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
this.eventDelegate = new EntityLifecycleEventDelegate();
|
||||
|
||||
// We create indexes based on mapping events
|
||||
if (this.mappingContext instanceof MongoMappingContext) {
|
||||
|
||||
MongoMappingContext mongoMappingContext = (MongoMappingContext) this.mappingContext;
|
||||
if (this.mappingContext instanceof MongoMappingContext mongoMappingContext) {
|
||||
|
||||
if (mongoMappingContext.isAutoIndexCreation()) {
|
||||
this.indexCreator = new ReactiveMongoPersistentEntityIndexCreator(mongoMappingContext, this::indexOps);
|
||||
@@ -371,8 +369,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
setEntityCallbacks(ReactiveEntityCallbacks.create(applicationContext));
|
||||
}
|
||||
|
||||
if (mappingContext instanceof ApplicationEventPublisherAware) {
|
||||
((ApplicationEventPublisherAware) mappingContext).setApplicationEventPublisher(eventPublisher);
|
||||
if (mappingContext instanceof ApplicationEventPublisherAware applicationEventPublisherAware) {
|
||||
applicationEventPublisherAware.setApplicationEventPublisher(eventPublisher);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,8 +454,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
}
|
||||
|
||||
if (context instanceof ConfigurableApplicationContext) {
|
||||
((ConfigurableApplicationContext) context).addApplicationListener(indexCreatorListener);
|
||||
if (context instanceof ConfigurableApplicationContext configurableApplicationContext) {
|
||||
configurableApplicationContext.addApplicationListener(indexCreatorListener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2024,10 +2022,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
Object filter = options.getFilter().orElse(Collections.emptyList());
|
||||
|
||||
if (filter instanceof Aggregation) {
|
||||
Aggregation agg = (Aggregation) filter;
|
||||
AggregationOperationContext context = agg instanceof TypedAggregation
|
||||
? new TypeBasedAggregationOperationContext(((TypedAggregation<?>) agg).getInputType(),
|
||||
if (filter instanceof Aggregation agg) {
|
||||
AggregationOperationContext context = agg instanceof TypedAggregation typedAggregation
|
||||
? new TypeBasedAggregationOperationContext(typedAggregation.getInputType(),
|
||||
getConverter().getMappingContext(), queryMapper)
|
||||
: new RelaxedTypeBasedAggregationOperationContext(Object.class, mappingContext, queryMapper);
|
||||
|
||||
@@ -2620,7 +2617,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(WriteResultChecking.EXCEPTION, writeResultChecking)) {
|
||||
if (wc == null || wc.getWObject() == null
|
||||
|| (wc.getWObject() instanceof Number && ((Number) wc.getWObject()).intValue() < 1)) {
|
||||
|| (wc.getWObject() instanceof Number concern && concern.intValue() < 1)) {
|
||||
return WriteConcern.ACKNOWLEDGED;
|
||||
}
|
||||
}
|
||||
@@ -2683,8 +2680,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
return throwable -> {
|
||||
|
||||
if (throwable instanceof RuntimeException) {
|
||||
return potentiallyConvertRuntimeException((RuntimeException) throwable, exceptionTranslator);
|
||||
if (throwable instanceof RuntimeException runtimeException) {
|
||||
return potentiallyConvertRuntimeException(runtimeException, exceptionTranslator);
|
||||
}
|
||||
|
||||
return throwable;
|
||||
@@ -2903,8 +2900,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
FindOneAndUpdateOptions findOneAndUpdateOptions = convertToFindOneAndUpdateOptions(options, fields, sort,
|
||||
arrayFilters);
|
||||
if (update instanceof Document) {
|
||||
return collectionToUse.findOneAndUpdate(query, (Document) update, findOneAndUpdateOptions);
|
||||
if (update instanceof Document document) {
|
||||
return collection.findOneAndUpdate(query, document, findOneAndUpdateOptions);
|
||||
} else if (update instanceof List) {
|
||||
return collectionToUse.findOneAndUpdate(query, (List<Document>) update, findOneAndUpdateOptions);
|
||||
}
|
||||
@@ -3331,9 +3328,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
PersistentEntity<?, ?> entity = event.getPersistentEntity();
|
||||
|
||||
// Double check type as Spring infrastructure does not consider nested generics
|
||||
if (entity instanceof MongoPersistentEntity) {
|
||||
if (entity instanceof MongoPersistentEntity<?> mongoPersistentProperties) {
|
||||
|
||||
onCheckForIndexes((MongoPersistentEntity<?>) entity, subscriptionExceptionHandler);
|
||||
onCheckForIndexes(mongoPersistentProperties, subscriptionExceptionHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ abstract class AbstractAggregationExpression implements AggregationExpression {
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object unpack(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
if (value instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
}
|
||||
|
||||
if (value instanceof Field field) {
|
||||
@@ -136,8 +136,8 @@ abstract class AbstractAggregationExpression implements AggregationExpression {
|
||||
|
||||
List<Object> clone = new ArrayList<>((List<Object>) this.value);
|
||||
|
||||
if (value instanceof Collection && Expand.EXPAND_VALUES.equals(expandList)) {
|
||||
clone.addAll((Collection<?>) value);
|
||||
if (value instanceof Collection<?> collection && Expand.EXPAND_VALUES.equals(expandList)) {
|
||||
clone.addAll(collection);
|
||||
} else {
|
||||
clone.add(value);
|
||||
}
|
||||
|
||||
@@ -360,10 +360,8 @@ public class AccumulatorOperators {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Document toDocument(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof List) {
|
||||
if (((List) value).size() == 1) {
|
||||
return super.toDocument(((List<Object>) value).iterator().next(), context);
|
||||
}
|
||||
if (value instanceof List<?> list && list.size() == 1) {
|
||||
return super.toDocument(list.iterator().next(), context);
|
||||
}
|
||||
|
||||
return super.toDocument(value, context);
|
||||
@@ -440,10 +438,8 @@ public class AccumulatorOperators {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Document toDocument(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof List) {
|
||||
if (((List) value).size() == 1) {
|
||||
return super.toDocument(((List<Object>) value).iterator().next(), context);
|
||||
}
|
||||
if (value instanceof List<?> list && list.size() == 1) {
|
||||
return super.toDocument(list.iterator().next(), context);
|
||||
}
|
||||
|
||||
return super.toDocument(value, context);
|
||||
@@ -539,10 +535,8 @@ public class AccumulatorOperators {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Document toDocument(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof List) {
|
||||
if (((List) value).size() == 1) {
|
||||
return super.toDocument(((List<Object>) value).iterator().next(), context);
|
||||
}
|
||||
if (value instanceof List<?> list && list.size() == 1) {
|
||||
return super.toDocument(list.iterator().next(), context);
|
||||
}
|
||||
|
||||
return super.toDocument(value, context);
|
||||
@@ -639,10 +633,8 @@ public class AccumulatorOperators {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Document toDocument(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof List) {
|
||||
if (((List) value).size() == 1) {
|
||||
return super.toDocument(((List<Object>) value).iterator().next(), context);
|
||||
}
|
||||
if (value instanceof List<?> list && list.size() == 1) {
|
||||
return super.toDocument(list.iterator().next(), context);
|
||||
}
|
||||
|
||||
return super.toDocument(value, context);
|
||||
@@ -719,10 +711,8 @@ public class AccumulatorOperators {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Document toDocument(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof List) {
|
||||
if (((List) value).size() == 1) {
|
||||
return super.toDocument(((List<Object>) value).iterator().next(), context);
|
||||
}
|
||||
if (value instanceof List<?> list && list.size() == 1) {
|
||||
return super.toDocument(list.iterator().next(), context);
|
||||
}
|
||||
|
||||
return super.toDocument(value, context);
|
||||
@@ -799,10 +789,8 @@ public class AccumulatorOperators {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Document toDocument(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof List) {
|
||||
if (((List) value).size() == 1) {
|
||||
return super.toDocument(((List<Object>) value).iterator().next(), context);
|
||||
}
|
||||
if (value instanceof List<?> list && list.size() == 1) {
|
||||
return super.toDocument(list.iterator().next(), context);
|
||||
}
|
||||
|
||||
return super.toDocument(value, context);
|
||||
|
||||
@@ -148,7 +148,7 @@ public class AddFieldsOperation extends DocumentEnhancingOperation {
|
||||
@Override
|
||||
public AddFieldsOperationBuilder withValueOf(Object value) {
|
||||
|
||||
valueMap.put(field, value instanceof String ? Fields.fields((String) value) : value);
|
||||
valueMap.put(field, value instanceof String stringValue ? Fields.fields(stringValue) : value);
|
||||
return AddFieldsOperationBuilder.this;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,11 +43,11 @@ public interface AggregationExpression extends MongoExpression {
|
||||
*/
|
||||
static AggregationExpression from(MongoExpression expression) {
|
||||
|
||||
if (expression instanceof AggregationExpression) {
|
||||
return AggregationExpression.class.cast(expression);
|
||||
if (expression instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression;
|
||||
}
|
||||
|
||||
return (context) -> context.getMappedObject(expression.toDocument());
|
||||
return context -> context.getMappedObject(expression.toDocument());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,9 +55,8 @@ class AggregationOperationRenderer {
|
||||
|
||||
operationDocuments.addAll(operation.toPipelineStages(contextToUse));
|
||||
|
||||
if (operation instanceof FieldsExposingAggregationOperation) {
|
||||
if (operation instanceof FieldsExposingAggregationOperation exposedFieldsOperation) {
|
||||
|
||||
FieldsExposingAggregationOperation exposedFieldsOperation = (FieldsExposingAggregationOperation) operation;
|
||||
ExposedFields fields = exposedFieldsOperation.getFields();
|
||||
|
||||
if (operation instanceof InheritsFieldsAggregationOperation || exposedFieldsOperation.inheritsFields()) {
|
||||
|
||||
@@ -105,6 +105,6 @@ public class AggregationResults<T> implements Iterable<T> {
|
||||
private String parseServerUsed() {
|
||||
|
||||
Object object = rawResults.get("serverUsed");
|
||||
return object instanceof String ? (String) object : null;
|
||||
return object instanceof String stringValue ? stringValue : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,10 +97,8 @@ public class AggregationUpdate extends Aggregation implements UpdateDefinition {
|
||||
super(pipeline);
|
||||
|
||||
for (AggregationOperation operation : pipeline) {
|
||||
if (operation instanceof FieldsExposingAggregationOperation) {
|
||||
((FieldsExposingAggregationOperation) operation).getFields().forEach(it -> {
|
||||
keysTouched.add(it.getName());
|
||||
});
|
||||
if (operation instanceof FieldsExposingAggregationOperation exposingAggregationOperation) {
|
||||
exposingAggregationOperation.getFields().forEach(it -> keysTouched.add(it.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,18 +681,18 @@ public class ArrayOperators {
|
||||
}
|
||||
|
||||
private Object getMappedInput(AggregationOperationContext context) {
|
||||
return input instanceof Field ? context.getReference((Field) input).toString() : input;
|
||||
return input instanceof Field field ? context.getReference(field).toString() : input;
|
||||
}
|
||||
|
||||
private Object getMappedCondition(AggregationOperationContext context) {
|
||||
|
||||
if (!(condition instanceof AggregationExpression)) {
|
||||
if (!(condition instanceof AggregationExpression aggregationExpression)) {
|
||||
return condition;
|
||||
}
|
||||
|
||||
NestedDelegatingExpressionAggregationOperationContext nea = new NestedDelegatingExpressionAggregationOperationContext(
|
||||
context, Collections.singleton(as));
|
||||
return ((AggregationExpression) condition).toDocument(nea);
|
||||
return aggregationExpression.toDocument(nea);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -785,7 +785,7 @@ public class ArrayOperators {
|
||||
public AsBuilder filter(List<?> array) {
|
||||
|
||||
Assert.notNull(array, "Array must not be null");
|
||||
filter.input = new ArrayList<Object>(array);
|
||||
filter.input = new ArrayList<>(array);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1292,10 +1292,10 @@ public class ArrayOperators {
|
||||
if (value instanceof Document) {
|
||||
return value;
|
||||
}
|
||||
if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
} else if (value instanceof Field) {
|
||||
return context.getReference(((Field) value)).toString();
|
||||
if (value instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
} else if (value instanceof Field field) {
|
||||
return context.getReference(field).toString();
|
||||
} else {
|
||||
return context.getMappedObject(new Document("###val###", value)).get("###val###");
|
||||
}
|
||||
@@ -1655,7 +1655,7 @@ public class ArrayOperators {
|
||||
|
||||
private ZipBuilder(Object sourceArray) {
|
||||
|
||||
this.sourceArrays = new ArrayList<Object>();
|
||||
this.sourceArrays = new ArrayList<>();
|
||||
this.sourceArrays.add(sourceArray);
|
||||
}
|
||||
|
||||
@@ -1672,14 +1672,14 @@ public class ArrayOperators {
|
||||
Assert.notNull(arrays, "Arrays must not be null");
|
||||
for (Object value : arrays) {
|
||||
|
||||
if (value instanceof String) {
|
||||
sourceArrays.add(Fields.field((String) value));
|
||||
if (value instanceof String stringValue) {
|
||||
sourceArrays.add(Fields.field(stringValue));
|
||||
} else {
|
||||
sourceArrays.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
return new Zip(Collections.<String, Object>singletonMap("inputs", sourceArrays));
|
||||
return new Zip(Collections.singletonMap("inputs", sourceArrays));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class BucketOperation extends BucketOperationSupport<BucketOperation, Buc
|
||||
|
||||
super(bucketOperation);
|
||||
|
||||
this.boundaries = new ArrayList<Object>(boundaries);
|
||||
this.boundaries = new ArrayList<>(boundaries);
|
||||
this.defaultBucket = defaultBucket;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class BucketOperation extends BucketOperationSupport<BucketOperation, Buc
|
||||
Assert.notNull(boundaries, "Boundaries must not be null");
|
||||
Assert.noNullElements(boundaries, "Boundaries must not contain null values");
|
||||
|
||||
List<Object> newBoundaries = new ArrayList<Object>(this.boundaries.size() + boundaries.length);
|
||||
List<Object> newBoundaries = new ArrayList<>(this.boundaries.size() + boundaries.length);
|
||||
newBoundaries.addAll(this.boundaries);
|
||||
newBoundaries.addAll(Arrays.asList(boundaries));
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
Assert.hasText(operation, "Operation must not be empty or null");
|
||||
Assert.notNull(value, "Values must not be null");
|
||||
|
||||
List<Object> objects = new ArrayList<Object>(values.length + 1);
|
||||
List<Object> objects = new ArrayList<>(values.length + 1);
|
||||
objects.add(value);
|
||||
objects.addAll(Arrays.asList(values));
|
||||
return apply(new OperationOutput(operation, objects));
|
||||
@@ -350,8 +350,8 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
*/
|
||||
public T as(String alias) {
|
||||
|
||||
if (value instanceof OperationOutput) {
|
||||
return this.operation.andOutput(((OperationOutput) this.value).withAlias(alias));
|
||||
if (value instanceof OperationOutput operationOutput) {
|
||||
return this.operation.andOutput(operationOutput.withAlias(alias));
|
||||
}
|
||||
|
||||
if (value instanceof Field) {
|
||||
@@ -520,7 +520,7 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
Assert.notNull(values, "Values must not be null");
|
||||
|
||||
this.operation = operation;
|
||||
this.values = new ArrayList<Object>(values);
|
||||
this.values = new ArrayList<>(values);
|
||||
}
|
||||
|
||||
private OperationOutput(Field field, OperationOutput operationOutput) {
|
||||
@@ -540,18 +540,18 @@ public abstract class BucketOperationSupport<T extends BucketOperationSupport<T,
|
||||
|
||||
protected List<Object> getOperationArguments(AggregationOperationContext context) {
|
||||
|
||||
List<Object> result = new ArrayList<Object>(values != null ? values.size() : 1);
|
||||
List<Object> result = new ArrayList<>(values != null ? values.size() : 1);
|
||||
|
||||
for (Object element : values) {
|
||||
|
||||
if (element instanceof Field) {
|
||||
result.add(context.getReference((Field) element).toString());
|
||||
} else if (element instanceof Fields) {
|
||||
for (Field field : (Fields) element) {
|
||||
if (element instanceof Field field) {
|
||||
result.add(context.getReference(field).toString());
|
||||
} else if (element instanceof Fields fields) {
|
||||
for (Field field : fields) {
|
||||
result.add(context.getReference(field).toString());
|
||||
}
|
||||
} else if (element instanceof AggregationExpression) {
|
||||
result.add(((AggregationExpression) element).toDocument(context));
|
||||
} else if (element instanceof AggregationExpression aggregationExpression) {
|
||||
result.add(aggregationExpression.toDocument(context));
|
||||
} else {
|
||||
result.add(element);
|
||||
}
|
||||
|
||||
@@ -278,10 +278,10 @@ public class ConditionalOperators {
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
List<Object> list = new ArrayList<>();
|
||||
|
||||
if (condition instanceof Collection) {
|
||||
for (Object val : ((Collection) this.condition)) {
|
||||
if (condition instanceof Collection<?> collection) {
|
||||
for (Object val : collection) {
|
||||
list.add(mapCondition(val, context));
|
||||
}
|
||||
} else {
|
||||
@@ -294,10 +294,10 @@ public class ConditionalOperators {
|
||||
|
||||
private Object mapCondition(Object condition, AggregationOperationContext context) {
|
||||
|
||||
if (condition instanceof Field) {
|
||||
return context.getReference((Field) condition).toString();
|
||||
} else if (condition instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) condition).toDocument(context);
|
||||
if (condition instanceof Field field) {
|
||||
return context.getReference(field).toString();
|
||||
} else if (condition instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
} else {
|
||||
return condition;
|
||||
}
|
||||
@@ -305,10 +305,10 @@ public class ConditionalOperators {
|
||||
|
||||
private Object resolve(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof Field) {
|
||||
return context.getReference((Field) value).toString();
|
||||
} else if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
if (value instanceof Field field) {
|
||||
return context.getReference(field).toString();
|
||||
} else if (value instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
} else if (value instanceof Document) {
|
||||
return value;
|
||||
}
|
||||
@@ -482,7 +482,7 @@ public class ConditionalOperators {
|
||||
public static Switch switchCases(List<CaseOperator> conditions) {
|
||||
|
||||
Assert.notNull(conditions, "Conditions must not be null");
|
||||
return new Switch(Collections.<String, Object> singletonMap("branches", new ArrayList<CaseOperator>(conditions)));
|
||||
return new Switch(Collections.singletonMap("branches", new ArrayList<>(conditions)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -529,10 +529,10 @@ public class ConditionalOperators {
|
||||
|
||||
Document dbo = new Document("case", when.toDocument(context));
|
||||
|
||||
if (then instanceof AggregationExpression) {
|
||||
dbo.put("then", ((AggregationExpression) then).toDocument(context));
|
||||
} else if (then instanceof Field) {
|
||||
dbo.put("then", context.getReference((Field) then).toString());
|
||||
if (then instanceof AggregationExpression aggregationExpression) {
|
||||
dbo.put("then", aggregationExpression.toDocument(context));
|
||||
} else if (then instanceof Field field) {
|
||||
dbo.put("then", context.getReference(field).toString());
|
||||
} else {
|
||||
dbo.put("then", then);
|
||||
}
|
||||
@@ -629,8 +629,8 @@ public class ConditionalOperators {
|
||||
return resolve(context, value);
|
||||
}
|
||||
|
||||
if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
if (value instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
}
|
||||
|
||||
return context.getMappedObject(new Document("$set", value)).get("$set");
|
||||
@@ -642,13 +642,13 @@ public class ConditionalOperators {
|
||||
return resolve(context, value);
|
||||
}
|
||||
|
||||
if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
if (value instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
}
|
||||
|
||||
if (value instanceof CriteriaDefinition) {
|
||||
if (value instanceof CriteriaDefinition criteriaDefinition) {
|
||||
|
||||
Document mappedObject = context.getMappedObject(((CriteriaDefinition) value).getCriteriaObject());
|
||||
Document mappedObject = context.getMappedObject(criteriaDefinition.getCriteriaObject());
|
||||
List<Object> clauses = getClauses(context, mappedObject);
|
||||
return clauses.size() == 1 ? clauses.get(0) : clauses;
|
||||
}
|
||||
@@ -659,7 +659,7 @@ public class ConditionalOperators {
|
||||
|
||||
private List<Object> getClauses(AggregationOperationContext context, Document mappedObject) {
|
||||
|
||||
List<Object> clauses = new ArrayList<Object>();
|
||||
List<Object> clauses = new ArrayList<>();
|
||||
|
||||
for (String key : mappedObject.keySet()) {
|
||||
|
||||
@@ -672,23 +672,20 @@ public class ConditionalOperators {
|
||||
|
||||
private List<Object> getClauses(AggregationOperationContext context, String key, Object predicate) {
|
||||
|
||||
List<Object> clauses = new ArrayList<Object>();
|
||||
List<Object> clauses = new ArrayList<>();
|
||||
|
||||
if (predicate instanceof List) {
|
||||
if (predicate instanceof List<?> predicates) {
|
||||
|
||||
List<?> predicates = (List<?>) predicate;
|
||||
List<Object> args = new ArrayList<Object>(predicates.size());
|
||||
List<Object> args = new ArrayList<>(predicates.size());
|
||||
|
||||
for (Object clause : (List<?>) predicate) {
|
||||
if (clause instanceof Document) {
|
||||
args.addAll(getClauses(context, (Document) clause));
|
||||
for (Object clause : predicates) {
|
||||
if (clause instanceof Document document) {
|
||||
args.addAll(getClauses(context, document));
|
||||
}
|
||||
}
|
||||
|
||||
clauses.add(new Document(key, args));
|
||||
} else if (predicate instanceof Document) {
|
||||
|
||||
Document nested = (Document) predicate;
|
||||
} else if (predicate instanceof Document nested) {
|
||||
|
||||
for (String s : nested.keySet()) {
|
||||
|
||||
@@ -696,14 +693,14 @@ public class ConditionalOperators {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<Object> args = new ArrayList<Object>(2);
|
||||
List<Object> args = new ArrayList<>(2);
|
||||
args.add("$" + key);
|
||||
args.add(nested.get(s));
|
||||
clauses.add(new Document(s, args));
|
||||
}
|
||||
} else if (!isKeyword(key)) {
|
||||
|
||||
List<Object> args = new ArrayList<Object>(2);
|
||||
List<Object> args = new ArrayList<>(2);
|
||||
args.add("$" + key);
|
||||
args.add(predicate);
|
||||
clauses.add(new Document("$eq", args));
|
||||
@@ -724,8 +721,8 @@ public class ConditionalOperators {
|
||||
|
||||
private Object resolve(AggregationOperationContext context, Object value) {
|
||||
|
||||
if (value instanceof Document) {
|
||||
return context.getMappedObject((Document) value);
|
||||
if (value instanceof Document document) {
|
||||
return context.getMappedObject(document);
|
||||
}
|
||||
|
||||
return context.getReference((Field) value).toString();
|
||||
|
||||
@@ -985,8 +985,8 @@ public class DateOperators {
|
||||
|
||||
java.util.Map<String, Object> args;
|
||||
|
||||
if (source instanceof Map) {
|
||||
args = new LinkedHashMap<>((Map) source);
|
||||
if (source instanceof Map map) {
|
||||
args = new LinkedHashMap<>(map);
|
||||
} else {
|
||||
args = new LinkedHashMap<>(2);
|
||||
args.put("date", source);
|
||||
@@ -1877,12 +1877,12 @@ public class DateOperators {
|
||||
|
||||
java.util.Map<String, Object> clone = new LinkedHashMap<>(argumentMap());
|
||||
|
||||
if (value instanceof Timezone) {
|
||||
if (value instanceof Timezone timezone) {
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(value, Timezone.none())) {
|
||||
clone.remove("timezone");
|
||||
} else {
|
||||
clone.put("timezone", ((Timezone) value).value);
|
||||
clone.put("timezone", timezone.value);
|
||||
}
|
||||
} else {
|
||||
clone.put(key, value);
|
||||
|
||||
@@ -84,21 +84,21 @@ abstract class DocumentEnhancingOperation implements InheritsFieldsAggregationOp
|
||||
return exposedFields;
|
||||
}
|
||||
|
||||
private ExposedFields add(Object field) {
|
||||
private ExposedFields add(Object fieldValue) {
|
||||
|
||||
if (field instanceof Field) {
|
||||
return exposedFields.and(new ExposedField((Field) field, true));
|
||||
if (fieldValue instanceof Field field) {
|
||||
return exposedFields.and(new ExposedField(field, true));
|
||||
}
|
||||
if (field instanceof String) {
|
||||
return exposedFields.and(new ExposedField(Fields.field((String) field), true));
|
||||
if (fieldValue instanceof String fieldName) {
|
||||
return exposedFields.and(new ExposedField(Fields.field(fieldName), true));
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format("Expected %s to be a field/property", field));
|
||||
throw new IllegalArgumentException(String.format("Expected %s to be a field/property", fieldValue));
|
||||
}
|
||||
|
||||
private static Document toSetEntry(Entry<Object, Object> entry, AggregationOperationContext context) {
|
||||
|
||||
String field = entry.getKey() instanceof String ? context.getReference((String) entry.getKey()).getRaw()
|
||||
String field = entry.getKey() instanceof String key ? context.getReference(key).getRaw()
|
||||
: context.getReference((Field) entry.getKey()).getRaw();
|
||||
|
||||
Object value = computeValue(entry.getValue(), context);
|
||||
@@ -108,20 +108,20 @@ abstract class DocumentEnhancingOperation implements InheritsFieldsAggregationOp
|
||||
|
||||
private static Object computeValue(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof Field) {
|
||||
return context.getReference((Field) value).toString();
|
||||
if (value instanceof Field field) {
|
||||
return context.getReference(field).toString();
|
||||
}
|
||||
|
||||
if (value instanceof ExpressionProjection) {
|
||||
return ((ExpressionProjection) value).toExpression(context);
|
||||
if (value instanceof ExpressionProjection expressionProjection) {
|
||||
return expressionProjection.toExpression(context);
|
||||
}
|
||||
|
||||
if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
if (value instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
}
|
||||
|
||||
if (value instanceof Collection) {
|
||||
return ((Collection<?>) value).stream().map(it -> computeValue(it, context)).collect(Collectors.toList());
|
||||
if (value instanceof Collection<?> collection) {
|
||||
return collection.stream().map(it -> computeValue(it, context)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -393,13 +393,11 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof DirectFieldReference)) {
|
||||
if (!(obj instanceof DirectFieldReference fieldReference)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DirectFieldReference that = (DirectFieldReference) obj;
|
||||
|
||||
return this.field.equals(that.field);
|
||||
return this.field.equals(fieldReference.field);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -460,12 +458,11 @@ public final class ExposedFields implements Iterable<ExposedField> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof ExpressionFieldReference)) {
|
||||
if (!(obj instanceof ExpressionFieldReference fieldReference)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ExpressionFieldReference that = (ExpressionFieldReference) obj;
|
||||
return ObjectUtils.nullSafeEquals(this.delegate, that.delegate);
|
||||
return ObjectUtils.nullSafeEquals(this.delegate, fieldReference.delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -308,13 +308,11 @@ public final class Fields implements Iterable<Field> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof AggregationField)) {
|
||||
if (!(obj instanceof AggregationField field)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AggregationField that = (AggregationField) obj;
|
||||
|
||||
return this.name.equals(that.name) && ObjectUtils.nullSafeEquals(this.target, that.target);
|
||||
return this.name.equals(field.name) && ObjectUtils.nullSafeEquals(this.target, field.target);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -84,14 +84,14 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
|
||||
graphLookup.put("from", from);
|
||||
|
||||
List<Object> mappedStartWith = new ArrayList<Object>(startWith.size());
|
||||
List<Object> mappedStartWith = new ArrayList<>(startWith.size());
|
||||
|
||||
for (Object startWithElement : startWith) {
|
||||
|
||||
if (startWithElement instanceof AggregationExpression) {
|
||||
mappedStartWith.add(((AggregationExpression) startWithElement).toDocument(context));
|
||||
} else if (startWithElement instanceof Field) {
|
||||
mappedStartWith.add(context.getReference((Field) startWithElement).toString());
|
||||
if (startWithElement instanceof AggregationExpression aggregationExpression) {
|
||||
mappedStartWith.add(aggregationExpression.toDocument(context));
|
||||
} else if (startWithElement instanceof Field field) {
|
||||
mappedStartWith.add(context.getReference(field).toString());
|
||||
} else {
|
||||
mappedStartWith.add(startWithElement);
|
||||
}
|
||||
@@ -237,7 +237,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
Assert.notNull(fieldReferences, "FieldReferences must not be null");
|
||||
Assert.noNullElements(fieldReferences, "FieldReferences must not contain null elements");
|
||||
|
||||
List<Object> fields = new ArrayList<Object>(fieldReferences.length);
|
||||
List<Object> fields = new ArrayList<>(fieldReferences.length);
|
||||
|
||||
for (String fieldReference : fieldReferences) {
|
||||
fields.add(Fields.field(fieldReference));
|
||||
@@ -269,14 +269,14 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
|
||||
private List<Object> verifyAndPotentiallyTransformStartsWithTypes(Object... expressions) {
|
||||
|
||||
List<Object> expressionsToUse = new ArrayList<Object>(expressions.length);
|
||||
List<Object> expressionsToUse = new ArrayList<>(expressions.length);
|
||||
|
||||
for (Object expression : expressions) {
|
||||
|
||||
assertStartWithType(expression);
|
||||
|
||||
if (expression instanceof String) {
|
||||
expressionsToUse.add(Fields.field((String) expression));
|
||||
if (expression instanceof String stringValue) {
|
||||
expressionsToUse.add(Fields.field(stringValue));
|
||||
} else {
|
||||
expressionsToUse.add(expression);
|
||||
}
|
||||
@@ -333,7 +333,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
String connectTo) {
|
||||
|
||||
this.from = from;
|
||||
this.startWith = new ArrayList<Object>(startWith);
|
||||
this.startWith = new ArrayList<>(startWith);
|
||||
this.connectFrom = Fields.field(connectFrom);
|
||||
this.connectTo = Fields.field(connectTo);
|
||||
}
|
||||
|
||||
@@ -514,8 +514,8 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
|
||||
|
||||
if (reference == null) {
|
||||
|
||||
if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
if (value instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -339,8 +339,8 @@ public class MergeOperation implements FieldsExposingAggregationOperation, Inher
|
||||
|
||||
Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof Aggregation) {
|
||||
return new Document("whenMatched", ((Aggregation) value).toPipeline(context));
|
||||
if (value instanceof Aggregation aggregation) {
|
||||
return new Document("whenMatched", aggregation.toPipeline(context));
|
||||
}
|
||||
|
||||
return new Document("whenMatched", value);
|
||||
|
||||
@@ -245,12 +245,8 @@ public class ObjectOperators {
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object potentiallyExtractSingleValue(Object value) {
|
||||
|
||||
if (value instanceof Collection) {
|
||||
|
||||
Collection<Object> collection = ((Collection<Object>) value);
|
||||
if (collection.size() == 1) {
|
||||
return collection.iterator().next();
|
||||
}
|
||||
if (value instanceof Collection<?> collection && collection.size() == 1) {
|
||||
return collection.iterator().next();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ public class PrefixingDelegatingAggregationOperationContext implements Aggregati
|
||||
List<Object> prefixed = new ArrayList<>(sourceCollection.size());
|
||||
|
||||
for (Object o : sourceCollection) {
|
||||
if (o instanceof Document) {
|
||||
prefixed.add(doPrefix((Document) o));
|
||||
if (o instanceof Document document) {
|
||||
prefixed.add(doPrefix(document));
|
||||
} else {
|
||||
prefixed.add(o);
|
||||
}
|
||||
|
||||
@@ -207,10 +207,10 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
|
||||
for (Object value : values) {
|
||||
|
||||
if (value instanceof Field) {
|
||||
builder.and((Field) value);
|
||||
} else if (value instanceof AggregationExpression) {
|
||||
builder.and((AggregationExpression) value);
|
||||
if (value instanceof Field field) {
|
||||
builder.and(field);
|
||||
} else if (value instanceof AggregationExpression aggregationExpression) {
|
||||
builder.and(aggregationExpression);
|
||||
} else {
|
||||
builder.and(value);
|
||||
}
|
||||
@@ -330,7 +330,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @param operation must not be {@literal null}.
|
||||
* @param parameters
|
||||
* @param parameters parameters must not be {@literal null}.
|
||||
*/
|
||||
public ExpressionProjectionOperationBuilder(String expression, ProjectionOperation operation, Object[] parameters) {
|
||||
|
||||
@@ -347,7 +347,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
@Override
|
||||
protected List<Object> getOperationArguments(AggregationOperationContext context) {
|
||||
|
||||
List<Object> result = new ArrayList<Object>(values.length + 1);
|
||||
List<Object> result = new ArrayList<>(values.length + 1);
|
||||
result.add(ExpressionProjection.toMongoExpression(context,
|
||||
ExpressionProjectionOperationBuilder.this.expression, ExpressionProjectionOperationBuilder.this.params));
|
||||
result.addAll(Arrays.asList(values));
|
||||
@@ -1455,19 +1455,19 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
|
||||
protected List<Object> getOperationArguments(AggregationOperationContext context) {
|
||||
|
||||
List<Object> result = new ArrayList<Object>(values.size());
|
||||
List<Object> result = new ArrayList<>(values.size());
|
||||
result.add(context.getReference(getField()).toString());
|
||||
|
||||
for (Object element : values) {
|
||||
|
||||
if (element instanceof Field) {
|
||||
result.add(context.getReference((Field) element).toString());
|
||||
} else if (element instanceof Fields) {
|
||||
for (Field field : (Fields) element) {
|
||||
if (element instanceof Field field) {
|
||||
result.add(context.getReference(field).toString());
|
||||
} else if (element instanceof Fields fields) {
|
||||
for (Field field : fields) {
|
||||
result.add(context.getReference(field).toString());
|
||||
}
|
||||
} else if (element instanceof AggregationExpression) {
|
||||
result.add(((AggregationExpression) element).toDocument(context));
|
||||
} else if (element instanceof AggregationExpression aggregationExpression) {
|
||||
result.add(aggregationExpression.toDocument(context));
|
||||
} else {
|
||||
result.add(element);
|
||||
}
|
||||
@@ -1734,6 +1734,29 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link Projection} including all top level fields of the given target type mapped to include potentially
|
||||
* deviating field names.
|
||||
*
|
||||
* @since 2.2
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
static class FilterProjection extends Projection {
|
||||
|
||||
public static String FILTER_ELEMENT = "filterElement";
|
||||
private final Object value;
|
||||
|
||||
FilterProjection(String fieldReference, Object value) {
|
||||
super(Fields.field(FILTER_ELEMENT + "." + fieldReference));
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document(getExposedField().getName(), value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for {@code array} projections.
|
||||
*
|
||||
@@ -1829,20 +1852,16 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
|
||||
private Object toArrayEntry(Object projection, AggregationOperationContext ctx) {
|
||||
|
||||
if (projection instanceof Field) {
|
||||
return ctx.getReference((Field) projection).toString();
|
||||
if (projection instanceof Field field) {
|
||||
return ctx.getReference(field).toString();
|
||||
}
|
||||
|
||||
if (projection instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) projection).toDocument(ctx);
|
||||
if (projection instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(ctx);
|
||||
}
|
||||
|
||||
if (projection instanceof FieldProjection) {
|
||||
return ctx.getReference(((FieldProjection) projection).getExposedField().getTarget()).toString();
|
||||
}
|
||||
|
||||
if (projection instanceof Projection) {
|
||||
((Projection) projection).toDocument(ctx);
|
||||
if (projection instanceof FieldProjection fieldProjection) {
|
||||
return ctx.getReference(fieldProjection.getExposedField().getTarget()).toString();
|
||||
}
|
||||
|
||||
return projection;
|
||||
|
||||
@@ -226,14 +226,14 @@ public class RedactOperation implements AggregationOperation {
|
||||
|
||||
private ThenBuilder when() {
|
||||
|
||||
if (when instanceof CriteriaDefinition) {
|
||||
return ConditionalOperators.Cond.when((CriteriaDefinition) when);
|
||||
if (when instanceof CriteriaDefinition criteriaDefinition) {
|
||||
return ConditionalOperators.Cond.when(criteriaDefinition);
|
||||
}
|
||||
if (when instanceof AggregationExpression) {
|
||||
return ConditionalOperators.Cond.when((AggregationExpression) when);
|
||||
if (when instanceof AggregationExpression aggregationExpression) {
|
||||
return ConditionalOperators.Cond.when(aggregationExpression);
|
||||
}
|
||||
if (when instanceof Document) {
|
||||
return ConditionalOperators.Cond.when((Document) when);
|
||||
if (when instanceof Document document) {
|
||||
return ConditionalOperators.Cond.when(document);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format(
|
||||
|
||||
@@ -249,9 +249,9 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
||||
|
||||
public ReplaceRootDocumentOperation as(String fieldName) {
|
||||
|
||||
if (value instanceof AggregationExpression) {
|
||||
if (value instanceof AggregationExpression aggregationExpression) {
|
||||
return new ReplaceRootDocumentOperation(currentOperation,
|
||||
ReplacementDocument.forExpression(fieldName, (AggregationExpression) value));
|
||||
ReplacementDocument.forExpression(fieldName, aggregationExpression));
|
||||
}
|
||||
|
||||
return new ReplaceRootDocumentOperation(currentOperation, ReplacementDocument.forSingleValue(fieldName, value));
|
||||
|
||||
@@ -62,23 +62,23 @@ public class ReplaceWithOperation extends ReplaceRootOperation {
|
||||
public static ReplaceWithOperation replaceWithValueOf(Object value) {
|
||||
|
||||
Assert.notNull(value, "Value must not be null");
|
||||
return new ReplaceWithOperation((ctx) -> {
|
||||
return new ReplaceWithOperation(ctx -> {
|
||||
|
||||
Object target = value instanceof String ? Fields.field((String) value) : value;
|
||||
Object target = value instanceof String stringValue ? Fields.field(stringValue) : value;
|
||||
return computeValue(target, ctx);
|
||||
});
|
||||
}
|
||||
|
||||
private static Object computeValue(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof Field) {
|
||||
return context.getReference((Field) value).toString();
|
||||
if (value instanceof Field field) {
|
||||
return context.getReference(field).toString();
|
||||
}
|
||||
if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
if (value instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
}
|
||||
if (value instanceof Collection) {
|
||||
return ((Collection) value).stream().map(it -> computeValue(it, context)).collect(Collectors.toList());
|
||||
if (value instanceof Collection<?> collection) {
|
||||
return collection.stream().map(it -> computeValue(it, context)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class SetOperation extends DocumentEnhancingOperation {
|
||||
@Override
|
||||
public SetOperation toValueOf(Object value) {
|
||||
|
||||
valueMap.put(field, value instanceof String ? Fields.fields((String) value) : value);
|
||||
valueMap.put(field, value instanceof String stringValue ? Fields.fields(stringValue) : value);
|
||||
return FieldAppender.this.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -78,10 +78,10 @@ public class SetWindowFieldsOperation
|
||||
|
||||
Document $setWindowFields = new Document();
|
||||
if (partitionBy != null) {
|
||||
if (partitionBy instanceof AggregationExpression) {
|
||||
$setWindowFields.append("partitionBy", ((AggregationExpression) partitionBy).toDocument(context));
|
||||
} else if (partitionBy instanceof Field) {
|
||||
$setWindowFields.append("partitionBy", context.getReference((Field) partitionBy).toString());
|
||||
if (partitionBy instanceof AggregationExpression aggregationExpression) {
|
||||
$setWindowFields.append("partitionBy", aggregationExpression.toDocument(context));
|
||||
} else if (partitionBy instanceof Field field) {
|
||||
$setWindowFields.append("partitionBy", context.getReference(field).toString());
|
||||
} else {
|
||||
$setWindowFields.append("partitionBy", partitionBy);
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ class SpelExpressionTransformer implements AggregationExpressionTransformer {
|
||||
private Document createOperationObjectAndAddToPreviousArgumentsIfNecessary(
|
||||
AggregationExpressionTransformationContext<OperatorNode> context, OperatorNode currentNode) {
|
||||
|
||||
Document nextDocument = new Document(currentNode.getMongoOperator(), new ArrayList<Object>());
|
||||
Document nextDocument = new Document(currentNode.getMongoOperator(), new ArrayList<>());
|
||||
|
||||
if (!context.hasPreviousOperation()) {
|
||||
return nextDocument;
|
||||
@@ -282,7 +282,7 @@ class SpelExpressionTransformer implements AggregationExpressionTransformer {
|
||||
@Nullable Object leftResult) {
|
||||
|
||||
Object result = leftResult instanceof Number ? leftResult
|
||||
: new Document("$multiply", Arrays.<Object> asList(Integer.valueOf(-1), leftResult));
|
||||
: new Document("$multiply", Arrays.asList(Integer.valueOf(-1), leftResult));
|
||||
|
||||
if (leftResult != null && context.hasPreviousOperation()) {
|
||||
context.addToPreviousOperation(result);
|
||||
@@ -453,7 +453,7 @@ class SpelExpressionTransformer implements AggregationExpressionTransformer {
|
||||
}
|
||||
else {
|
||||
|
||||
List<Object> argList = new ArrayList<Object>();
|
||||
List<Object> argList = new ArrayList<>();
|
||||
|
||||
for (ExpressionNode childNode : node) {
|
||||
argList.add(transform(childNode, context));
|
||||
@@ -516,7 +516,7 @@ class SpelExpressionTransformer implements AggregationExpressionTransformer {
|
||||
protected Object convert(AggregationExpressionTransformationContext<NotOperatorNode> context) {
|
||||
|
||||
NotOperatorNode node = context.getCurrentNode();
|
||||
List<Object> args = new ArrayList<Object>();
|
||||
List<Object> args = new ArrayList<>();
|
||||
|
||||
for (ExpressionNode childNode : node) {
|
||||
args.add(transform(childNode, context));
|
||||
|
||||
@@ -138,12 +138,12 @@ public class UnionWithOperation implements AggregationOperation {
|
||||
|
||||
private AggregationOperationContext computeContext(AggregationOperationContext source) {
|
||||
|
||||
if (source instanceof TypeBasedAggregationOperationContext) {
|
||||
return ((TypeBasedAggregationOperationContext) source).continueOnMissingFieldReference(domainType != null ? domainType : Object.class);
|
||||
if (source instanceof TypeBasedAggregationOperationContext aggregationOperationContext) {
|
||||
return aggregationOperationContext.continueOnMissingFieldReference(domainType != null ? domainType : Object.class);
|
||||
}
|
||||
|
||||
if (source instanceof ExposedFieldsAggregationOperationContext) {
|
||||
return computeContext(((ExposedFieldsAggregationOperationContext) source).getRootContext());
|
||||
if (source instanceof ExposedFieldsAggregationOperationContext aggregationOperationContext) {
|
||||
return computeContext(aggregationOperationContext.getRootContext());
|
||||
}
|
||||
|
||||
return source;
|
||||
|
||||
@@ -96,8 +96,8 @@ public class UnsetOperation implements InheritsFieldsAggregationOperation {
|
||||
|
||||
List<String> fieldNames = new ArrayList<>(fields.size());
|
||||
for (Object it : fields) {
|
||||
if (it instanceof Field) {
|
||||
fieldNames.add(((Field) it).getName());
|
||||
if (it instanceof Field field) {
|
||||
fieldNames.add(field.getName());
|
||||
} else {
|
||||
fieldNames.add(it.toString());
|
||||
}
|
||||
@@ -123,16 +123,16 @@ public class UnsetOperation implements InheritsFieldsAggregationOperation {
|
||||
|
||||
private Object computeFieldName(Object field, AggregationOperationContext context) {
|
||||
|
||||
if (field instanceof Field) {
|
||||
return context.getReference((Field) field).getRaw();
|
||||
if (field instanceof Field fieldObject) {
|
||||
return context.getReference(fieldObject).getRaw();
|
||||
}
|
||||
|
||||
if (field instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) field).toDocument(context);
|
||||
if (field instanceof AggregationExpression aggregationExpression) {
|
||||
return aggregationExpression.toDocument(context);
|
||||
}
|
||||
|
||||
if (field instanceof String) {
|
||||
return context.getReference((String) field).getRaw();
|
||||
if (field instanceof String stringValue) {
|
||||
return context.getReference(stringValue).getRaw();
|
||||
}
|
||||
|
||||
return field;
|
||||
|
||||
@@ -174,8 +174,8 @@ public class VariableOperators {
|
||||
exposedFields, context);
|
||||
|
||||
Document input;
|
||||
if (sourceArray instanceof Field) {
|
||||
input = new Document("input", context.getReference((Field) sourceArray).toString());
|
||||
if (sourceArray instanceof Field field) {
|
||||
input = new Document("input", context.getReference(field).toString());
|
||||
} else {
|
||||
input = new Document("input", ((AggregationExpression) sourceArray).toDocument(context));
|
||||
}
|
||||
|
||||
@@ -177,10 +177,10 @@ public class DefaultMongoTypeMapper extends DefaultTypeMapper<Bson> implements M
|
||||
return Alias.NONE;
|
||||
}
|
||||
|
||||
if (source instanceof Document) {
|
||||
return Alias.ofNullable(((Document) source).get(typeKey));
|
||||
} else if (source instanceof DBObject) {
|
||||
return Alias.ofNullable(((DBObject) source).get(typeKey));
|
||||
if (source instanceof Document document) {
|
||||
return Alias.ofNullable(document.get(typeKey));
|
||||
} else if (source instanceof DBObject dbObject) {
|
||||
return Alias.ofNullable(dbObject.get(typeKey));
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Cannot read alias from " + source.getClass());
|
||||
@@ -190,10 +190,10 @@ public class DefaultMongoTypeMapper extends DefaultTypeMapper<Bson> implements M
|
||||
|
||||
if (typeKey != null) {
|
||||
|
||||
if (sink instanceof Document) {
|
||||
((Document) sink).put(typeKey, alias);
|
||||
} else if (sink instanceof DBObject) {
|
||||
((DBObject) sink).put(typeKey, alias);
|
||||
if (sink instanceof Document document) {
|
||||
document.put(typeKey, alias);
|
||||
} else if (sink instanceof DBObject dbObject) {
|
||||
dbObject.put(typeKey, alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ public class DefaultReferenceResolver implements ReferenceResolver {
|
||||
|
||||
private Object createLazyLoadingProxy(MongoPersistentProperty property, Object source,
|
||||
ReferenceLookupDelegate referenceLookupDelegate, LookupFunction lookupFunction, MongoEntityReader entityReader) {
|
||||
return proxyFactory.createLazyLoadingProxy(property, it -> {
|
||||
return referenceLookupDelegate.readReference(it, source, lookupFunction, entityReader);
|
||||
}, source instanceof DocumentReferenceSource ? ((DocumentReferenceSource)source).getTargetSource() : source);
|
||||
return proxyFactory.createLazyLoadingProxy(property,
|
||||
it -> referenceLookupDelegate.readReference(it, source, lookupFunction, entityReader),
|
||||
source instanceof DocumentReferenceSource documentSource ? documentSource.getTargetSource() : source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,8 +169,8 @@ class DocumentAccessor {
|
||||
|
||||
Object existing = BsonUtils.asMap(source).get(key);
|
||||
|
||||
if (existing instanceof Document) {
|
||||
return (Document) existing;
|
||||
if (existing instanceof Document document) {
|
||||
return document;
|
||||
}
|
||||
|
||||
Document nested = new Document();
|
||||
|
||||
@@ -73,8 +73,8 @@ class DocumentPointerFactory {
|
||||
MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext,
|
||||
MongoPersistentProperty property, Object value, Class<?> typeHint) {
|
||||
|
||||
if (value instanceof LazyLoadingProxy) {
|
||||
return () -> ((LazyLoadingProxy) value).getSource();
|
||||
if (value instanceof LazyLoadingProxy proxy) {
|
||||
return proxy::getSource;
|
||||
}
|
||||
|
||||
if (conversionService.canConvert(typeHint, DocumentPointer.class)) {
|
||||
@@ -94,8 +94,8 @@ class DocumentPointerFactory {
|
||||
return () -> conversionService.convert(idValue, idProperty.getFieldType());
|
||||
}
|
||||
|
||||
if (idValue instanceof String && ObjectId.isValid((String) idValue)) {
|
||||
return () -> new ObjectId((String) idValue);
|
||||
if (idValue instanceof String stringValue && ObjectId.isValid((String) idValue)) {
|
||||
return () -> new ObjectId(stringValue);
|
||||
}
|
||||
|
||||
return () -> idValue;
|
||||
@@ -210,13 +210,13 @@ class DocumentPointerFactory {
|
||||
lookup, entry.getKey()));
|
||||
}
|
||||
|
||||
if (entry.getValue() instanceof Document) {
|
||||
if (entry.getValue() instanceof Document document) {
|
||||
|
||||
MongoPersistentProperty persistentProperty = persistentEntity.getPersistentProperty(entry.getKey());
|
||||
if (persistentProperty != null && persistentProperty.isEntity()) {
|
||||
|
||||
MongoPersistentEntity<?> nestedEntity = mappingContext.getPersistentEntity(persistentProperty.getType());
|
||||
target.put(entry.getKey(), updatePlaceholders((Document) entry.getValue(), new Document(), mappingContext,
|
||||
target.put(entry.getKey(), updatePlaceholders(document, new Document(), mappingContext,
|
||||
nestedEntity, nestedEntity.getPropertyAccessor(propertyAccessor.getProperty(persistentProperty))));
|
||||
} else {
|
||||
target.put(entry.getKey(), updatePlaceholders((Document) entry.getValue(), new Document(), mappingContext,
|
||||
|
||||
@@ -69,7 +69,7 @@ public class DocumentReferenceSource {
|
||||
*/
|
||||
@Nullable
|
||||
static Object getTargetSource(Object source) {
|
||||
return source instanceof DocumentReferenceSource ? ((DocumentReferenceSource) source).getTargetSource() : source;
|
||||
return source instanceof DocumentReferenceSource referenceSource ? referenceSource.getTargetSource() : source;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,6 +79,6 @@ public class DocumentReferenceSource {
|
||||
* @return
|
||||
*/
|
||||
static Object getSelf(Object self) {
|
||||
return self instanceof DocumentReferenceSource ? ((DocumentReferenceSource) self).getSelf() : self;
|
||||
return self instanceof DocumentReferenceSource referenceSource ? referenceSource.getSelf() : self;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,32 +422,32 @@ abstract class GeoConverters {
|
||||
|
||||
Shape shape = source.getShape();
|
||||
|
||||
if (shape instanceof GeoJson) {
|
||||
return GeoJsonToDocumentConverter.INSTANCE.convert((GeoJson) shape);
|
||||
if (shape instanceof GeoJson geoJson) {
|
||||
return GeoJsonToDocumentConverter.INSTANCE.convert(geoJson);
|
||||
}
|
||||
|
||||
if (shape instanceof Box) {
|
||||
if (shape instanceof Box box) {
|
||||
|
||||
argument.add(toList(((Box) shape).getFirst()));
|
||||
argument.add(toList(((Box) shape).getSecond()));
|
||||
argument.add(toList(box.getFirst()));
|
||||
argument.add(toList(box.getSecond()));
|
||||
|
||||
} else if (shape instanceof Circle) {
|
||||
} else if (shape instanceof Circle circle) {
|
||||
|
||||
argument.add(toList(((Circle) shape).getCenter()));
|
||||
argument.add(((Circle) shape).getRadius().getNormalizedValue());
|
||||
argument.add(toList(circle.getCenter()));
|
||||
argument.add(circle.getRadius().getNormalizedValue());
|
||||
|
||||
} else if (shape instanceof Polygon) {
|
||||
} else if (shape instanceof Polygon polygon) {
|
||||
|
||||
List<Point> points = ((Polygon) shape).getPoints();
|
||||
argument = new ArrayList(points.size());
|
||||
List<Point> points = polygon.getPoints();
|
||||
argument = new ArrayList<>(points.size());
|
||||
for (Point point : points) {
|
||||
argument.add(toList(point));
|
||||
}
|
||||
|
||||
} else if (shape instanceof Sphere) {
|
||||
} else if (shape instanceof Sphere sphere) {
|
||||
|
||||
argument.add(toList(((Sphere) shape).getCenter()));
|
||||
argument.add(((Sphere) shape).getRadius().getNormalizedValue());
|
||||
argument.add(toList(sphere.getCenter()));
|
||||
argument.add(sphere.getRadius().getNormalizedValue());
|
||||
}
|
||||
|
||||
return new Document(source.getCommand(), argument);
|
||||
@@ -471,11 +471,11 @@ abstract class GeoConverters {
|
||||
|
||||
Document dbo = new Document("type", source.getType());
|
||||
|
||||
if (source instanceof GeoJsonGeometryCollection) {
|
||||
if (source instanceof GeoJsonGeometryCollection collection) {
|
||||
|
||||
List<Object> dbl = new ArrayList<>();
|
||||
|
||||
for (GeoJson<?> geometry : ((GeoJsonGeometryCollection) source).getCoordinates()) {
|
||||
for (GeoJson<?> geometry : collection.getCoordinates()) {
|
||||
dbl.add(convert(geometry));
|
||||
}
|
||||
|
||||
@@ -490,23 +490,23 @@ abstract class GeoConverters {
|
||||
|
||||
private Object convertIfNecessary(Object candidate) {
|
||||
|
||||
if (candidate instanceof GeoJson) {
|
||||
return convertIfNecessary(((GeoJson<?>) candidate).getCoordinates());
|
||||
if (candidate instanceof GeoJson geoJson) {
|
||||
return convertIfNecessary(geoJson.getCoordinates());
|
||||
}
|
||||
|
||||
if (candidate instanceof Iterable<?>) {
|
||||
if (candidate instanceof Iterable<?> iterable) {
|
||||
|
||||
List<Object> dbl = new ArrayList<>();
|
||||
|
||||
for (Object element : (Iterable<?>) candidate) {
|
||||
for (Object element : iterable) {
|
||||
dbl.add(convertIfNecessary(element));
|
||||
}
|
||||
|
||||
return dbl;
|
||||
}
|
||||
|
||||
if (candidate instanceof Point) {
|
||||
return toList((Point) candidate);
|
||||
if (candidate instanceof Point point) {
|
||||
return toList(point);
|
||||
}
|
||||
|
||||
return candidate;
|
||||
|
||||
@@ -278,15 +278,15 @@ public final class LazyLoadingProxyFactory {
|
||||
|
||||
StringBuilder description = new StringBuilder();
|
||||
if (source != null) {
|
||||
if (source instanceof DBRef) {
|
||||
description.append(((DBRef) source).getCollectionName());
|
||||
if (source instanceof DBRef dbRef) {
|
||||
description.append(dbRef.getCollectionName());
|
||||
description.append(":");
|
||||
description.append(((DBRef) source).getId());
|
||||
description.append(dbRef.getId());
|
||||
} else {
|
||||
description.append(source);
|
||||
}
|
||||
} else {
|
||||
description.append(System.identityHashCode(source));
|
||||
description.append(0);
|
||||
}
|
||||
description.append("$").append(LazyLoadingProxy.class.getSimpleName());
|
||||
|
||||
|
||||
@@ -255,8 +255,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
ClassLoader classLoader = applicationContext.getClassLoader();
|
||||
if (this.defaultTypeMapper instanceof BeanClassLoaderAware && classLoader != null) {
|
||||
((BeanClassLoaderAware) this.defaultTypeMapper).setBeanClassLoader(classLoader);
|
||||
if (this.defaultTypeMapper instanceof BeanClassLoaderAware beanClassLoaderAware && classLoader != null) {
|
||||
beanClassLoaderAware.setBeanClassLoader(classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
protected <S extends Object> S readDocument(ConversionContext context, Bson bson,
|
||||
TypeInformation<? extends S> typeHint) {
|
||||
|
||||
Document document = bson instanceof BasicDBObject ? new Document((BasicDBObject) bson) : (Document) bson;
|
||||
Document document = bson instanceof BasicDBObject dbObject ? new Document(dbObject) : (Document) bson;
|
||||
TypeInformation<? extends S> typeToRead = getTypeMapper().readType(document, typeHint);
|
||||
Class<? extends S> rawType = typeToRead.getType();
|
||||
|
||||
@@ -426,8 +426,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return (S) bson;
|
||||
}
|
||||
|
||||
if (bson instanceof Document) {
|
||||
return (S) new BasicDBObject((Document) bson);
|
||||
if (bson instanceof Document doc) {
|
||||
return (S) new BasicDBObject(doc);
|
||||
}
|
||||
|
||||
return (S) bson;
|
||||
@@ -714,8 +714,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
@Override
|
||||
public DocumentPointer toDocumentPointer(Object source, @Nullable MongoPersistentProperty referringProperty) {
|
||||
|
||||
if (source instanceof LazyLoadingProxy) {
|
||||
return () -> ((LazyLoadingProxy) source).getSource();
|
||||
if (source instanceof LazyLoadingProxy proxy) {
|
||||
return proxy::getSource;
|
||||
}
|
||||
|
||||
Assert.notNull(referringProperty, "Cannot create DocumentReference; The referringProperty must not be null");
|
||||
@@ -737,8 +737,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return () -> source;
|
||||
}
|
||||
|
||||
if (source instanceof DocumentPointer) {
|
||||
return (DocumentPointer<?>) source;
|
||||
if (source instanceof DocumentPointer<?> pointer) {
|
||||
return pointer;
|
||||
}
|
||||
|
||||
if (ClassUtils.isAssignableValue(referringProperty.getType(), source)
|
||||
@@ -769,7 +769,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
Class<?> entityType = ClassUtils.getUserClass(obj.getClass());
|
||||
TypeInformation<? extends Object> type = TypeInformation.of(entityType);
|
||||
|
||||
Object target = obj instanceof LazyLoadingProxy ? ((LazyLoadingProxy) obj).getTarget() : obj;
|
||||
Object target = obj instanceof LazyLoadingProxy proxy ? proxy.getTarget() : obj;
|
||||
|
||||
writeInternal(target, bson, type);
|
||||
BsonUtils.removeNullId(bson);
|
||||
@@ -949,8 +949,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* If we already have a LazyLoadingProxy, we use it's cached DBRef value instead of
|
||||
* unnecessarily initializing it only to convert it to a DBRef a few instructions later.
|
||||
*/
|
||||
if (obj instanceof LazyLoadingProxy) {
|
||||
dbRefObj = ((LazyLoadingProxy) obj).toDBRef();
|
||||
if (obj instanceof LazyLoadingProxy proxy) {
|
||||
dbRefObj = proxy.toDBRef();
|
||||
}
|
||||
|
||||
dbRefObj = dbRefObj != null ? dbRefObj : createDBRef(obj, prop);
|
||||
@@ -969,8 +969,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
/*
|
||||
* If we have a LazyLoadingProxy we make sure it is initialized first.
|
||||
*/
|
||||
if (obj instanceof LazyLoadingProxy) {
|
||||
obj = ((LazyLoadingProxy) obj).getTarget();
|
||||
if (obj instanceof LazyLoadingProxy proxy) {
|
||||
obj = proxy.getTarget();
|
||||
}
|
||||
|
||||
// Lookup potential custom target type
|
||||
@@ -987,7 +987,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
: mappingContext.getRequiredPersistentEntity(type);
|
||||
|
||||
Object existingValue = accessor.get(prop);
|
||||
Document document = existingValue instanceof Document ? (Document) existingValue : new Document();
|
||||
Document document = existingValue instanceof Document existingDocument ? existingDocument : new Document();
|
||||
|
||||
writeInternal(obj, document, entity);
|
||||
addCustomTypeKeyIfNecessary(TypeInformation.of(prop.getRawType()), obj, document);
|
||||
@@ -1199,8 +1199,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
*/
|
||||
private String potentiallyConvertMapKey(Object key) {
|
||||
|
||||
if (key instanceof String) {
|
||||
return (String) key;
|
||||
if (key instanceof String stringValue) {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
return conversions.hasCustomWriteTarget(key.getClass(), String.class)
|
||||
@@ -1343,8 +1343,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
|
||||
Assert.notNull(target, "Target object must not be null");
|
||||
|
||||
if (target instanceof DBRef) {
|
||||
return (DBRef) target;
|
||||
if (target instanceof DBRef dbRef) {
|
||||
return dbRef;
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> targetEntity = mappingContext.getPersistentEntity(target.getClass());
|
||||
@@ -1505,26 +1505,26 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return getPotentiallyConvertedSimpleWrite(obj, conversionTargetType);
|
||||
}
|
||||
|
||||
if (obj instanceof List) {
|
||||
return maybeConvertList((List<Object>) obj, typeInformation);
|
||||
if (obj instanceof List<?> list) {
|
||||
return maybeConvertList(list, typeInformation);
|
||||
}
|
||||
|
||||
if (obj instanceof Document) {
|
||||
if (obj instanceof Document document) {
|
||||
|
||||
Document newValueDocument = new Document();
|
||||
for (String vk : ((Document) obj).keySet()) {
|
||||
Object o = ((Document) obj).get(vk);
|
||||
for (String vk : document.keySet()) {
|
||||
Object o = document.get(vk);
|
||||
newValueDocument.put(vk, convertToMongoType(o, typeInformation));
|
||||
}
|
||||
return newValueDocument;
|
||||
}
|
||||
|
||||
if (obj instanceof DBObject) {
|
||||
if (obj instanceof DBObject dbObject) {
|
||||
|
||||
Document newValueDbo = new Document();
|
||||
for (String vk : ((DBObject) obj).keySet()) {
|
||||
for (String vk : dbObject.keySet()) {
|
||||
|
||||
Object o = ((DBObject) obj).get(vk);
|
||||
Object o = dbObject.get(vk);
|
||||
newValueDbo.put(vk, convertToMongoType(o, typeInformation));
|
||||
}
|
||||
|
||||
@@ -1546,8 +1546,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return maybeConvertList(Arrays.asList((Object[]) obj), typeInformation);
|
||||
}
|
||||
|
||||
if (obj instanceof Collection) {
|
||||
return maybeConvertList((Collection<?>) obj, typeInformation);
|
||||
if (obj instanceof Collection<?> collection) {
|
||||
return maybeConvertList(collection, typeInformation);
|
||||
}
|
||||
|
||||
Document newDocument = new Document();
|
||||
@@ -1650,8 +1650,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
|
||||
if (conversions.hasCustomReadTarget(value.getClass(), rawType)) {
|
||||
return (T) doConvert(value, rawType);
|
||||
} else if (value instanceof DBRef) {
|
||||
return (T) readDBRef(context, (DBRef) value, type);
|
||||
} else if (value instanceof DBRef dbRef) {
|
||||
return (T) readDBRef(context, dbRef, type);
|
||||
}
|
||||
|
||||
return (T) context.convert(value, type);
|
||||
@@ -1830,11 +1830,11 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
|
||||
for (Object dbObjItem : source) {
|
||||
|
||||
if (!(dbObjItem instanceof DBRef)) {
|
||||
if (!(dbObjItem instanceof DBRef dbRef)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
collectionsFound.add(((DBRef) dbObjItem).getCollectionName());
|
||||
collectionsFound.add(dbRef.getCollectionName());
|
||||
|
||||
if (collectionsFound.size() > 1) {
|
||||
return false;
|
||||
@@ -1971,7 +1971,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
evaluator, (prop, bson, evaluator, path) -> MappingMongoConverter.this.getValueInternal(context, prop, bson,
|
||||
evaluator));
|
||||
|
||||
DBRef dbref = rawRefValue instanceof DBRef ? (DBRef) rawRefValue : null;
|
||||
DBRef dbref = rawRefValue instanceof DBRef dbRef ? dbRef : null;
|
||||
return (T) dbRefResolver.resolveDbRef(property, dbref, callback, dbRefProxyHandler);
|
||||
}
|
||||
|
||||
@@ -2310,7 +2310,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return (S) elementConverter.convert(source, typeHint);
|
||||
}
|
||||
|
||||
if (source instanceof Collection) {
|
||||
if (source instanceof Collection<?> collection) {
|
||||
|
||||
Class<?> rawType = typeHint.getType();
|
||||
if (!Object.class.equals(rawType)) {
|
||||
@@ -2321,7 +2321,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
if (typeHint.isCollectionLike() || typeHint.getType().isAssignableFrom(Collection.class)) {
|
||||
return (S) collectionConverter.convert(context, (Collection<?>) source, typeHint);
|
||||
return (S) collectionConverter.convert(context, collection, typeHint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2339,8 +2339,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
String.format("Expected map like structure but found %s", source.getClass()));
|
||||
}
|
||||
|
||||
if (source instanceof DBRef) {
|
||||
return (S) dbRefConverter.convert(context, (DBRef) source, typeHint);
|
||||
if (source instanceof DBRef dbRef) {
|
||||
return (S) dbRefConverter.convert(context, dbRef, typeHint);
|
||||
}
|
||||
|
||||
if (source instanceof Collection) {
|
||||
|
||||
@@ -70,7 +70,7 @@ public class MongoConversionContext implements ValueConversionContext<MongoPersi
|
||||
|
||||
@Override
|
||||
public <T> T read(@Nullable Object value, TypeInformation<T> target) {
|
||||
return value instanceof Bson ? mongoConverter.read(target.getType(), (Bson) value)
|
||||
return value instanceof Bson bson ? mongoConverter.read(target.getType(), bson)
|
||||
: ValueConversionContext.super.read(value, target);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,39 +112,35 @@ public interface MongoConverter
|
||||
return (T) source;
|
||||
}
|
||||
|
||||
if (source instanceof BsonValue) {
|
||||
if (source instanceof BsonValue bson) {
|
||||
|
||||
Object value = BsonUtils.toJavaType((BsonValue) source);
|
||||
Object value = BsonUtils.toJavaType(bson);
|
||||
|
||||
if (value instanceof Document) {
|
||||
if (value instanceof Document document) {
|
||||
|
||||
Document sourceDocument = (Document) value;
|
||||
if (document.containsKey("$ref") && document.containsKey("$id")) {
|
||||
|
||||
if (sourceDocument.containsKey("$ref") && sourceDocument.containsKey("$id")) {
|
||||
|
||||
Object id = sourceDocument.get("$id");
|
||||
String collection = sourceDocument.getString("$ref");
|
||||
Object id = document.get("$id");
|
||||
String collection = document.getString("$ref");
|
||||
|
||||
MongoPersistentEntity<?> entity = getMappingContext().getPersistentEntity(targetType);
|
||||
if (entity != null && entity.hasIdProperty()) {
|
||||
id = convertId(id, entity.getIdProperty().getFieldType());
|
||||
}
|
||||
|
||||
DBRef ref = sourceDocument.containsKey("$db") ? new DBRef(sourceDocument.getString("$db"), collection, id)
|
||||
DBRef ref = document.containsKey("$db") ? new DBRef(document.getString("$db"), collection, id)
|
||||
: new DBRef(collection, id);
|
||||
|
||||
sourceDocument = dbRefResolver.fetch(ref);
|
||||
if (sourceDocument == null) {
|
||||
document = dbRefResolver.fetch(ref);
|
||||
if (document == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return read(targetType, sourceDocument);
|
||||
return read(targetType, document);
|
||||
} else {
|
||||
if (!ClassUtils.isAssignable(targetType, value.getClass())) {
|
||||
if (getConversionService().canConvert(value.getClass(), targetType)) {
|
||||
return getConversionService().convert(value, targetType);
|
||||
}
|
||||
if (!ClassUtils.isAssignable(targetType, value.getClass()) && getConversionService().canConvert(value.getClass(), targetType)) {
|
||||
return getConversionService().convert(value, targetType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -401,12 +401,12 @@ abstract class MongoConverters {
|
||||
@Override
|
||||
public T convert(Number source) {
|
||||
|
||||
if (source instanceof AtomicInteger) {
|
||||
return NumberUtils.convertNumberToTargetClass(((AtomicInteger) source).get(), this.targetType);
|
||||
if (source instanceof AtomicInteger atomicInteger) {
|
||||
return NumberUtils.convertNumberToTargetClass(atomicInteger.get(), this.targetType);
|
||||
}
|
||||
|
||||
if (source instanceof AtomicLong) {
|
||||
return NumberUtils.convertNumberToTargetClass(((AtomicLong) source).get(), this.targetType);
|
||||
if (source instanceof AtomicLong atomicLong) {
|
||||
return NumberUtils.convertNumberToTargetClass(atomicLong.get(), this.targetType);
|
||||
}
|
||||
|
||||
return NumberUtils.convertNumberToTargetClass(source, this.targetType);
|
||||
|
||||
@@ -177,8 +177,8 @@ public class MongoExampleMapper {
|
||||
|
||||
if (entry.getValue() instanceof String) {
|
||||
applyStringMatcher(entry, stringMatcher, ignoreCase);
|
||||
} else if (entry.getValue() instanceof Document) {
|
||||
applyPropertySpecs(propertyPath, (Document) entry.getValue(), probeType, exampleSpecAccessor);
|
||||
} else if (entry.getValue() instanceof Document document) {
|
||||
applyPropertySpecs(propertyPath, document, probeType, exampleSpecAccessor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ public class MongoExampleMapper {
|
||||
return StringUtils.collectionToDelimitedString(resultParts, ".");
|
||||
}
|
||||
|
||||
private Document updateTypeRestrictions(Document query, Example example) {
|
||||
private Document updateTypeRestrictions(Document query, Example<?> example) {
|
||||
|
||||
Document result = new Document();
|
||||
|
||||
@@ -245,7 +245,7 @@ public class MongoExampleMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isTypeRestricting(Example example) {
|
||||
private boolean isTypeRestricting(Example<?> example) {
|
||||
|
||||
if (example.getMatcher() instanceof UntypedExampleMatcher) {
|
||||
return false;
|
||||
@@ -324,20 +324,13 @@ public class MongoExampleMapper {
|
||||
*/
|
||||
private static MatchMode toMatchMode(StringMatcher matcher) {
|
||||
|
||||
switch (matcher) {
|
||||
case CONTAINING:
|
||||
return MatchMode.CONTAINING;
|
||||
case STARTING:
|
||||
return MatchMode.STARTING_WITH;
|
||||
case ENDING:
|
||||
return MatchMode.ENDING_WITH;
|
||||
case EXACT:
|
||||
return MatchMode.EXACT;
|
||||
case REGEX:
|
||||
return MatchMode.REGEX;
|
||||
case DEFAULT:
|
||||
default:
|
||||
return MatchMode.DEFAULT;
|
||||
}
|
||||
return switch (matcher) {
|
||||
case CONTAINING -> MatchMode.CONTAINING;
|
||||
case STARTING -> MatchMode.STARTING_WITH;
|
||||
case ENDING -> MatchMode.ENDING_WITH;
|
||||
case EXACT -> MatchMode.EXACT;
|
||||
case REGEX -> MatchMode.REGEX;
|
||||
default -> MatchMode.DEFAULT;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,8 +331,8 @@ public class QueryMapper {
|
||||
String key = field.getMappedKey();
|
||||
Object value;
|
||||
|
||||
if (rawValue instanceof MongoExpression) {
|
||||
return createMapEntry(key, getMappedObject(((MongoExpression) rawValue).toDocument(), field.getEntity()));
|
||||
if (rawValue instanceof MongoExpression mongoExpression) {
|
||||
return createMapEntry(key, getMappedObject(mongoExpression.toDocument(), field.getEntity()));
|
||||
}
|
||||
|
||||
if (isNestedKeyword(rawValue) && !field.isIdField()) {
|
||||
@@ -378,8 +378,8 @@ public class QueryMapper {
|
||||
if (keyword.isOrOrNor() || (keyword.hasIterableValue() && !keyword.isGeometry())) {
|
||||
|
||||
Iterable<?> conditions = keyword.getValue();
|
||||
List<Object> newConditions = conditions instanceof Collection
|
||||
? new ArrayList<>(((Collection<?>) conditions).size())
|
||||
List<Object> newConditions = conditions instanceof Collection<?> collection
|
||||
? new ArrayList<>(collection.size())
|
||||
: new ArrayList<>();
|
||||
|
||||
for (Object condition : conditions) {
|
||||
@@ -417,8 +417,8 @@ public class QueryMapper {
|
||||
Object convertedValue = needsAssociationConversion ? convertAssociation(value, property)
|
||||
: getMappedValue(property.with(keyword.getKey()), value);
|
||||
|
||||
if (keyword.isSample() && convertedValue instanceof Document) {
|
||||
return (Document) convertedValue;
|
||||
if (keyword.isSample() && convertedValue instanceof Document document) {
|
||||
return document;
|
||||
}
|
||||
|
||||
return new Document(keyword.key, convertedValue);
|
||||
@@ -574,8 +574,8 @@ public class QueryMapper {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object convertSimpleOrDocument(Object source, @Nullable MongoPersistentEntity<?> entity) {
|
||||
|
||||
if (source instanceof Example) {
|
||||
return exampleMapper.getMappedExample((Example<?>) source, entity);
|
||||
if (source instanceof Example<?> example) {
|
||||
return exampleMapper.getMappedExample(example, entity);
|
||||
}
|
||||
|
||||
if (source instanceof AggregationExpression age) {
|
||||
@@ -615,8 +615,8 @@ public class QueryMapper {
|
||||
|
||||
String key = ObjectUtils.nullSafeToString(converter.convertToMongoType(it.getKey()));
|
||||
|
||||
if (it.getValue() instanceof Document) {
|
||||
map.put(key, getMappedObject((Document) it.getValue(), entity));
|
||||
if (it.getValue() instanceof Document document) {
|
||||
map.put(key, getMappedObject(document, entity));
|
||||
} else {
|
||||
map.put(key, delegateConvertToMongoType(it.getValue(), entity));
|
||||
}
|
||||
@@ -668,9 +668,8 @@ public class QueryMapper {
|
||||
return source;
|
||||
}
|
||||
|
||||
if (source instanceof DBRef) {
|
||||
if (source instanceof DBRef ref) {
|
||||
|
||||
DBRef ref = (DBRef) source;
|
||||
Object id = convertId(ref.getId(),
|
||||
property != null && property.isIdProperty() ? property.getFieldType() : ObjectId.class);
|
||||
|
||||
@@ -681,9 +680,9 @@ public class QueryMapper {
|
||||
}
|
||||
}
|
||||
|
||||
if (source instanceof Iterable) {
|
||||
if (source instanceof Iterable<?> iterable) {
|
||||
BasicDBList result = new BasicDBList();
|
||||
for (Object element : (Iterable<?>) source) {
|
||||
for (Object element : iterable) {
|
||||
result.add(createReferenceFor(element, property));
|
||||
}
|
||||
return result;
|
||||
@@ -747,8 +746,8 @@ public class QueryMapper {
|
||||
|
||||
private Object createReferenceFor(Object source, MongoPersistentProperty property) {
|
||||
|
||||
if (source instanceof DBRef) {
|
||||
return (DBRef) source;
|
||||
if (source instanceof DBRef dbRef) {
|
||||
return dbRef;
|
||||
}
|
||||
|
||||
if (property != null && (property.isDocumentReference()
|
||||
@@ -850,9 +849,8 @@ public class QueryMapper {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value instanceof Collection) {
|
||||
if (value instanceof Collection<?> source) {
|
||||
|
||||
Collection<Object> source = (Collection<Object>) value;
|
||||
Collection<Object> converted = new ArrayList<>(source.size());
|
||||
|
||||
for (Object o : source) {
|
||||
|
||||
@@ -101,7 +101,7 @@ public final class ReferenceLookupDelegate {
|
||||
public Object readReference(MongoPersistentProperty property, Object source, LookupFunction lookupFunction,
|
||||
MongoEntityReader entityReader) {
|
||||
|
||||
Object value = source instanceof DocumentReferenceSource ? ((DocumentReferenceSource) source).getTargetSource()
|
||||
Object value = source instanceof DocumentReferenceSource documentReferenceSource ? documentReferenceSource.getTargetSource()
|
||||
: source;
|
||||
|
||||
DocumentReferenceQuery filter = computeFilter(property, source, spELContext);
|
||||
@@ -125,22 +125,20 @@ public final class ReferenceLookupDelegate {
|
||||
SpELContext spELContext) {
|
||||
|
||||
// Use the first value as a reference for others in case of collection like
|
||||
if (value instanceof Iterable) {
|
||||
if (value instanceof Iterable<?> iterable) {
|
||||
|
||||
Iterator<?> iterator = ((Iterable<?>) value).iterator();
|
||||
Iterator<?> iterator = iterable.iterator();
|
||||
value = iterator.hasNext() ? iterator.next() : new Document();
|
||||
}
|
||||
|
||||
// handle DBRef value
|
||||
if (value instanceof DBRef) {
|
||||
return ReferenceCollection.fromDBRef((DBRef) value);
|
||||
if (value instanceof DBRef dbRef) {
|
||||
return ReferenceCollection.fromDBRef(dbRef);
|
||||
}
|
||||
|
||||
String collection = mappingContext.getRequiredPersistentEntity(property.getAssociationTargetType()).getCollection();
|
||||
|
||||
if (value instanceof Document) {
|
||||
|
||||
Document documentPointer = (Document) value;
|
||||
if (value instanceof Document documentPointer) {
|
||||
|
||||
if (property.isDocumentReference()) {
|
||||
|
||||
@@ -216,9 +214,9 @@ public final class ReferenceLookupDelegate {
|
||||
|
||||
ValueProvider valueProviderFor(Object source) {
|
||||
|
||||
return (index) -> {
|
||||
if (source instanceof Document) {
|
||||
return Streamable.of(((Document) source).values()).toList().get(index);
|
||||
return index -> {
|
||||
if (source instanceof Document document) {
|
||||
return Streamable.of(document.values()).toList().get(index);
|
||||
}
|
||||
return source;
|
||||
};
|
||||
@@ -226,7 +224,7 @@ public final class ReferenceLookupDelegate {
|
||||
|
||||
EvaluationContext evaluationContextFor(MongoPersistentProperty property, Object source, SpELContext spELContext) {
|
||||
|
||||
Object target = source instanceof DocumentReferenceSource ? ((DocumentReferenceSource) source).getTargetSource()
|
||||
Object target = source instanceof DocumentReferenceSource documentReferenceSource ? documentReferenceSource.getTargetSource()
|
||||
: source;
|
||||
|
||||
if (target == null) {
|
||||
@@ -405,7 +403,7 @@ public final class ReferenceLookupDelegate {
|
||||
public Iterable<Document> restoreOrder(Iterable<Document> documents) {
|
||||
|
||||
Map<String, Object> targetMap = new LinkedHashMap<>();
|
||||
List<Document> collected = documents instanceof List ? (List<Document>) documents
|
||||
List<Document> collected = documents instanceof List<Document> list ? list
|
||||
: Streamable.of(documents).toList();
|
||||
|
||||
for (Entry<Object, Document> filterMapping : filterOrderMap.entrySet()) {
|
||||
@@ -438,7 +436,7 @@ public final class ReferenceLookupDelegate {
|
||||
@Override
|
||||
public Iterable<Document> restoreOrder(Iterable<Document> documents) {
|
||||
|
||||
List<Document> target = documents instanceof List ? (List<Document>) documents
|
||||
List<Document> target = documents instanceof List<Document> list ? list
|
||||
: Streamable.of(documents).toList();
|
||||
|
||||
if (!sort.isEmpty() || !query.containsKey("$or")) {
|
||||
|
||||
@@ -161,17 +161,17 @@ public class UpdateMapper extends QueryMapper {
|
||||
}
|
||||
|
||||
private Entry<String, Object> getMappedUpdateModifier(Field field, Object rawValue) {
|
||||
Object value = null;
|
||||
Object value;
|
||||
|
||||
if (rawValue instanceof Modifier) {
|
||||
if (rawValue instanceof Modifier modifier) {
|
||||
|
||||
value = getMappedValue(field, (Modifier) rawValue);
|
||||
value = getMappedValue(field, modifier);
|
||||
|
||||
} else if (rawValue instanceof Modifiers) {
|
||||
} else if (rawValue instanceof Modifiers modifiers) {
|
||||
|
||||
Document modificationOperations = new Document();
|
||||
|
||||
for (Modifier modifier : ((Modifiers) rawValue).getModifiers()) {
|
||||
for (Modifier modifier : modifiers.getModifiers()) {
|
||||
modificationOperations.putAll(getMappedValue(field, modifier));
|
||||
}
|
||||
|
||||
|
||||
@@ -70,12 +70,10 @@ public class GeoJsonGeometryCollection implements GeoJson<Iterable<GeoJson<?>>>
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof GeoJsonGeometryCollection)) {
|
||||
if (!(obj instanceof GeoJsonGeometryCollection other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GeoJsonGeometryCollection other = (GeoJsonGeometryCollection) obj;
|
||||
|
||||
return ObjectUtils.nullSafeEquals(this.geometries, other.geometries);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +85,10 @@ public class GeoJsonMultiLineString implements GeoJson<Iterable<GeoJsonLineStrin
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof GeoJsonMultiLineString)) {
|
||||
if (!(obj instanceof GeoJsonMultiLineString other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ObjectUtils.nullSafeEquals(this.coordinates, ((GeoJsonMultiLineString) obj).coordinates);
|
||||
return ObjectUtils.nullSafeEquals(this.coordinates, other.coordinates);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,10 +107,10 @@ public class GeoJsonMultiPoint implements GeoJson<Iterable<Point>> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof GeoJsonMultiPoint)) {
|
||||
if (!(obj instanceof GeoJsonMultiPoint other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ObjectUtils.nullSafeEquals(this.points, ((GeoJsonMultiPoint) obj).points);
|
||||
return ObjectUtils.nullSafeEquals(this.points, other.points);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,10 +69,10 @@ public class GeoJsonMultiPolygon implements GeoJson<Iterable<GeoJsonPolygon>> {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof GeoJsonMultiPolygon)) {
|
||||
if (!(obj instanceof GeoJsonMultiPolygon other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ObjectUtils.nullSafeEquals(this.coordinates, ((GeoJsonMultiPolygon) obj).coordinates);
|
||||
return ObjectUtils.nullSafeEquals(this.coordinates, other.coordinates);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,13 +105,11 @@ public class Sphere implements Shape {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obj == null || !(obj instanceof Sphere)) {
|
||||
if (!(obj instanceof Sphere other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Sphere that = (Sphere) obj;
|
||||
|
||||
return this.center.equals(that.center) && this.radius.equals(that.radius);
|
||||
return this.center.equals(other.center) && this.radius.equals(other.radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -181,14 +181,12 @@ public final class IndexField {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof IndexField)) {
|
||||
if (!(obj instanceof IndexField other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IndexField that = (IndexField) obj;
|
||||
|
||||
return this.key.equals(that.key) && ObjectUtils.nullSafeEquals(this.direction, that.direction)
|
||||
&& this.type == that.type;
|
||||
return this.key.equals(other.key) && ObjectUtils.nullSafeEquals(this.direction, other.direction)
|
||||
&& this.type == other.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,8 +68,8 @@ public class MongoMappingEventPublisher implements ApplicationEventPublisher {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void publishEvent(ApplicationEvent event) {
|
||||
if (event instanceof MappingContextEvent) {
|
||||
indexCreator.onApplicationEvent((MappingContextEvent<MongoPersistentEntity<?>, MongoPersistentProperty>) event);
|
||||
if (event instanceof MappingContextEvent<?,?> mappingContextEvent) {
|
||||
indexCreator.onApplicationEvent(mappingContextEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,9 +106,9 @@ public class MongoPersistentEntityIndexCreator implements ApplicationListener<Ma
|
||||
PersistentEntity<?, ?> entity = event.getPersistentEntity();
|
||||
|
||||
// Double check type as Spring infrastructure does not consider nested generics
|
||||
if (entity instanceof MongoPersistentEntity) {
|
||||
if (entity instanceof MongoPersistentEntity<?> mongoPersistentEntity) {
|
||||
|
||||
checkForIndexes((MongoPersistentEntity<?>) entity);
|
||||
checkForIndexes(mongoPersistentEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,8 +136,8 @@ public class MongoPersistentEntityIndexCreator implements ApplicationListener<Ma
|
||||
|
||||
for (IndexDefinition indexDefinition : indexResolver.resolveIndexFor(entity.getTypeInformation())) {
|
||||
|
||||
IndexDefinitionHolder indexToCreate = indexDefinition instanceof IndexDefinitionHolder
|
||||
? (IndexDefinitionHolder) indexDefinition
|
||||
IndexDefinitionHolder indexToCreate = indexDefinition instanceof IndexDefinitionHolder definitionHolder
|
||||
? definitionHolder
|
||||
: new IndexDefinitionHolder("", indexDefinition, collection);
|
||||
|
||||
createIndex(indexToCreate);
|
||||
@@ -154,8 +154,8 @@ public class MongoPersistentEntityIndexCreator implements ApplicationListener<Ma
|
||||
|
||||
} catch (UncategorizedMongoDbException ex) {
|
||||
|
||||
if (ex.getCause() instanceof MongoException
|
||||
&& MongoDbErrorCodes.isDataIntegrityViolationCode(((MongoException) ex.getCause()).getCode())) {
|
||||
if (ex.getCause() instanceof MongoException mongoException
|
||||
&& MongoDbErrorCodes.isDataIntegrityViolationCode(mongoException.getCode())) {
|
||||
|
||||
IndexInfo existingIndex = fetchIndexInformation(indexDefinition);
|
||||
String message = "Cannot create index for '%s' in collection '%s' with keys '%s' and options '%s'";
|
||||
|
||||
@@ -493,7 +493,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
|
||||
Object keyDefToUse = ExpressionUtils.evaluate(keyDefinitionString, () -> getEvaluationContextForProperty(entity));
|
||||
|
||||
org.bson.Document dbo = (keyDefToUse instanceof org.bson.Document) ? (org.bson.Document) keyDefToUse
|
||||
org.bson.Document dbo = (keyDefToUse instanceof org.bson.Document document) ? document
|
||||
: org.bson.Document.parse(ObjectUtils.nullSafeToString(keyDefToUse));
|
||||
|
||||
if (!StringUtils.hasText(dotPath)) {
|
||||
@@ -578,8 +578,8 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
|
||||
Object result = ExpressionUtils.evaluate(filterExpression, () -> getEvaluationContextForProperty(entity));
|
||||
|
||||
if (result instanceof org.bson.Document) {
|
||||
return PartialIndexFilter.of((org.bson.Document) result);
|
||||
if (result instanceof org.bson.Document document) {
|
||||
return PartialIndexFilter.of(document);
|
||||
}
|
||||
|
||||
return PartialIndexFilter.of(BsonUtils.parse(filterExpression, null));
|
||||
@@ -589,8 +589,8 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
|
||||
Object result = ExpressionUtils.evaluate(projectionExpression, () -> getEvaluationContextForProperty(entity));
|
||||
|
||||
if (result instanceof org.bson.Document) {
|
||||
return (org.bson.Document) result;
|
||||
if (result instanceof org.bson.Document document) {
|
||||
return document;
|
||||
}
|
||||
|
||||
return BsonUtils.parse(projectionExpression, null);
|
||||
@@ -599,14 +599,14 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
private Collation evaluateCollation(String collationExpression, PersistentEntity<?, ?> entity) {
|
||||
|
||||
Object result = ExpressionUtils.evaluate(collationExpression, () -> getEvaluationContextForProperty(entity));
|
||||
if (result instanceof org.bson.Document) {
|
||||
return Collation.from((org.bson.Document) result);
|
||||
if (result instanceof org.bson.Document document) {
|
||||
return Collation.from(document);
|
||||
}
|
||||
if (result instanceof Collation) {
|
||||
return (Collation) result;
|
||||
if (result instanceof Collation collation) {
|
||||
return collation;
|
||||
}
|
||||
if (result instanceof String) {
|
||||
return Collation.parse(result.toString());
|
||||
if (result instanceof String stringValue) {
|
||||
return Collation.parse(stringValue);
|
||||
}
|
||||
if (result instanceof Map) {
|
||||
return Collation.from(new org.bson.Document((Map<String, ?>) result));
|
||||
@@ -788,8 +788,8 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
return Duration.ZERO;
|
||||
}
|
||||
|
||||
if (evaluatedTimeout instanceof Duration) {
|
||||
return (Duration) evaluatedTimeout;
|
||||
if (evaluatedTimeout instanceof Duration duration) {
|
||||
return duration;
|
||||
}
|
||||
|
||||
String val = evaluatedTimeout.toString();
|
||||
|
||||
@@ -59,12 +59,12 @@ public class PartialIndexFilter implements IndexFilter {
|
||||
|
||||
public Document getFilterObject() {
|
||||
|
||||
if (filterExpression instanceof Document) {
|
||||
return (Document) filterExpression;
|
||||
if (filterExpression instanceof Document document) {
|
||||
return document;
|
||||
}
|
||||
|
||||
if (filterExpression instanceof CriteriaDefinition) {
|
||||
return ((CriteriaDefinition) filterExpression).getCriteriaObject();
|
||||
if (filterExpression instanceof CriteriaDefinition criteriaDefinition) {
|
||||
return criteriaDefinition.getCriteriaObject();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
|
||||
@@ -130,8 +130,8 @@ public class ReactiveMongoPersistentEntityIndexCreator {
|
||||
String collection = entity.getCollection();
|
||||
for (IndexDefinition indexDefinition : indexResolver.resolveIndexFor(entity.getTypeInformation())) {
|
||||
|
||||
IndexDefinitionHolder indexToCreate = indexDefinition instanceof IndexDefinitionHolder
|
||||
? (IndexDefinitionHolder) indexDefinition
|
||||
IndexDefinitionHolder indexToCreate = indexDefinition instanceof IndexDefinitionHolder definitionHolder
|
||||
? definitionHolder
|
||||
: new IndexDefinitionHolder("", indexDefinition, collection);
|
||||
|
||||
publishers.add(createIndex(indexToCreate));
|
||||
@@ -187,8 +187,8 @@ public class ReactiveMongoPersistentEntityIndexCreator {
|
||||
|
||||
if (t instanceof UncategorizedMongoDbException) {
|
||||
|
||||
return t.getCause() instanceof MongoException
|
||||
&& MongoDbErrorCodes.isDataIntegrityViolationCode(((MongoException) t.getCause()).getCode());
|
||||
return t.getCause() instanceof MongoException mongoException
|
||||
&& MongoDbErrorCodes.isDataIntegrityViolationCode(mongoException.getCode());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -159,12 +159,12 @@ public class BasicMongoPersistentEntity<T> extends BasicPersistentEntity<T, Mong
|
||||
return null;
|
||||
}
|
||||
|
||||
if (collationValue instanceof org.bson.Document) {
|
||||
return org.springframework.data.mongodb.core.query.Collation.from((org.bson.Document) collationValue);
|
||||
if (collationValue instanceof org.bson.Document document) {
|
||||
return org.springframework.data.mongodb.core.query.Collation.from(document);
|
||||
}
|
||||
|
||||
if (collationValue instanceof org.springframework.data.mongodb.core.query.Collation) {
|
||||
return org.springframework.data.mongodb.core.query.Collation.class.cast(collationValue);
|
||||
if (collationValue instanceof org.springframework.data.mongodb.core.query.Collation collation) {
|
||||
return collation;
|
||||
}
|
||||
|
||||
return StringUtils.hasText(collationValue.toString())
|
||||
|
||||
@@ -272,8 +272,8 @@ public class BasicMongoPersistentProperty extends AnnotationBasedPersistentPrope
|
||||
*/
|
||||
public EvaluationContext getEvaluationContext(@Nullable Object rootObject) {
|
||||
|
||||
if (getOwner() instanceof BasicMongoPersistentEntity) {
|
||||
return ((BasicMongoPersistentEntity) getOwner()).getEvaluationContext(rootObject);
|
||||
if (getOwner() instanceof BasicMongoPersistentEntity mongoPersistentEntity) {
|
||||
return mongoPersistentEntity.getEvaluationContext(rootObject);
|
||||
}
|
||||
return rootObject != null ? new StandardEvaluationContext(rootObject) : new StandardEvaluationContext();
|
||||
}
|
||||
|
||||
@@ -212,8 +212,8 @@ class UnwrappedMongoPersistentEntity<T> implements MongoPersistentEntity<T> {
|
||||
public void doWithProperties(SimplePropertyHandler handler) {
|
||||
|
||||
delegate.doWithProperties((SimplePropertyHandler) property -> {
|
||||
if (property instanceof MongoPersistentProperty) {
|
||||
handler.doWithPersistentProperty(wrap((MongoPersistentProperty) property));
|
||||
if (property instanceof MongoPersistentProperty mongoPersistentProperty) {
|
||||
handler.doWithPersistentProperty(wrap(mongoPersistentProperty));
|
||||
} else {
|
||||
handler.doWithPersistentProperty(property);
|
||||
}
|
||||
|
||||
@@ -47,8 +47,7 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
@Override
|
||||
public void onApplicationEvent(MongoMappingEvent<?> event) {
|
||||
|
||||
if (event instanceof AfterLoadEvent) {
|
||||
AfterLoadEvent<?> afterLoadEvent = (AfterLoadEvent<?>) event;
|
||||
if (event instanceof AfterLoadEvent<?> afterLoadEvent) {
|
||||
|
||||
if (domainClass.isAssignableFrom(afterLoadEvent.getType())) {
|
||||
onAfterLoad((AfterLoadEvent<E>) event);
|
||||
@@ -57,16 +56,16 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
return;
|
||||
}
|
||||
|
||||
if (event instanceof AbstractDeleteEvent) {
|
||||
if (event instanceof AbstractDeleteEvent deleteEvent) {
|
||||
|
||||
Class<?> eventDomainType = ((AbstractDeleteEvent) event).getType();
|
||||
Class<?> eventDomainType = deleteEvent.getType();
|
||||
|
||||
if (eventDomainType != null && domainClass.isAssignableFrom(eventDomainType)) {
|
||||
if (event instanceof BeforeDeleteEvent) {
|
||||
onBeforeDelete((BeforeDeleteEvent<E>) event);
|
||||
if (event instanceof BeforeDeleteEvent beforeDeleteEvent) {
|
||||
onBeforeDelete(beforeDeleteEvent);
|
||||
}
|
||||
if (event instanceof AfterDeleteEvent) {
|
||||
onAfterDelete((AfterDeleteEvent<E>) event);
|
||||
if (event instanceof AfterDeleteEvent afterDeleteEvent) {
|
||||
onAfterDelete(afterDeleteEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,14 +80,14 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
return;
|
||||
}
|
||||
|
||||
if (event instanceof BeforeConvertEvent) {
|
||||
onBeforeConvert((BeforeConvertEvent<E>) event);
|
||||
} else if (event instanceof BeforeSaveEvent) {
|
||||
onBeforeSave((BeforeSaveEvent<E>) event);
|
||||
} else if (event instanceof AfterSaveEvent) {
|
||||
onAfterSave((AfterSaveEvent<E>) event);
|
||||
} else if (event instanceof AfterConvertEvent) {
|
||||
onAfterConvert((AfterConvertEvent<E>) event);
|
||||
if (event instanceof BeforeConvertEvent beforeConvertEvent) {
|
||||
onBeforeConvert(beforeConvertEvent);
|
||||
} else if (event instanceof BeforeSaveEvent beforeSaveEvent) {
|
||||
onBeforeSave(beforeSaveEvent);
|
||||
} else if (event instanceof AfterSaveEvent afterSaveEvent) {
|
||||
onAfterSave(afterSaveEvent);
|
||||
} else if (event instanceof AfterConvertEvent afterConvertEvent) {
|
||||
onAfterConvert(afterConvertEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class MapReduceResults<T> implements Iterable<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
return resultField instanceof Document ? ((Document) resultField).get("collection").toString()
|
||||
return resultField instanceof Document document ? document.get("collection").toString()
|
||||
: resultField.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,12 +69,10 @@ public class MapReduceTiming {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof MapReduceTiming)) {
|
||||
if (!(obj instanceof MapReduceTiming that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MapReduceTiming that = (MapReduceTiming) obj;
|
||||
|
||||
return this.emitLoopTime == that.emitLoopTime && //
|
||||
this.mapTime == that.mapTime && //
|
||||
this.totalTime == that.totalTime;
|
||||
|
||||
@@ -113,8 +113,8 @@ public class ChangeStreamRequest<T>
|
||||
Assert.notNull(messageListener, "MessageListener must not be null");
|
||||
Assert.notNull(options, "Options must not be null");
|
||||
|
||||
this.options = options instanceof ChangeStreamRequestOptions ? (ChangeStreamRequestOptions) options
|
||||
: ChangeStreamRequestOptions.of(options);
|
||||
this.options = options instanceof ChangeStreamRequestOptions changeStreamRequestOptions ?
|
||||
changeStreamRequestOptions : ChangeStreamRequestOptions.of(options);
|
||||
|
||||
this.messageListener = messageListener;
|
||||
}
|
||||
|
||||
@@ -92,16 +92,16 @@ class ChangeStreamTask extends CursorReadingTask<ChangeStreamDocument<Document>,
|
||||
BsonTimestamp startAt = null;
|
||||
boolean resumeAfter = true;
|
||||
|
||||
if (options instanceof ChangeStreamRequest.ChangeStreamRequestOptions) {
|
||||
if (options instanceof ChangeStreamRequest.ChangeStreamRequestOptions changeStreamRequestOptions) {
|
||||
|
||||
ChangeStreamOptions changeStreamOptions = ((ChangeStreamRequestOptions) options).getChangeStreamOptions();
|
||||
ChangeStreamOptions changeStreamOptions = changeStreamRequestOptions.getChangeStreamOptions();
|
||||
filter = prepareFilter(template, changeStreamOptions);
|
||||
|
||||
if (changeStreamOptions.getFilter().isPresent()) {
|
||||
|
||||
Object val = changeStreamOptions.getFilter().get();
|
||||
if (val instanceof Aggregation) {
|
||||
collation = ((Aggregation) val).getOptions().getCollation()
|
||||
if (val instanceof Aggregation aggregation) {
|
||||
collation = aggregation.getOptions().getCollation()
|
||||
.map(org.springframework.data.mongodb.core.query.Collation::toMongoCollation).orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -172,14 +172,13 @@ class ChangeStreamTask extends CursorReadingTask<ChangeStreamDocument<Document>,
|
||||
|
||||
Object filter = options.getFilter().orElse(null);
|
||||
|
||||
if (filter instanceof Aggregation) {
|
||||
Aggregation agg = (Aggregation) filter;
|
||||
AggregationOperationContext context = agg instanceof TypedAggregation
|
||||
? new TypeBasedAggregationOperationContext(((TypedAggregation<?>) agg).getInputType(),
|
||||
if (filter instanceof Aggregation aggregation) {
|
||||
AggregationOperationContext context = aggregation instanceof TypedAggregation<?> typedAggregation
|
||||
? new TypeBasedAggregationOperationContext(typedAggregation.getInputType(),
|
||||
template.getConverter().getMappingContext(), queryMapper)
|
||||
: Aggregation.DEFAULT_CONTEXT;
|
||||
|
||||
return agg.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", denylist));
|
||||
return aggregation.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", denylist));
|
||||
}
|
||||
|
||||
if (filter instanceof List) {
|
||||
|
||||
@@ -117,7 +117,7 @@ public class DefaultMessageListenerContainer implements MessageListenerContainer
|
||||
|
||||
subscriptions.values().stream() //
|
||||
.filter(it -> !it.isActive()) //
|
||||
.filter(it -> it instanceof TaskSubscription) //
|
||||
.filter(TaskSubscription.class::isInstance) //
|
||||
.map(TaskSubscription.class::cast) //
|
||||
.map(TaskSubscription::getTask) //
|
||||
.forEach(taskExecutor::execute);
|
||||
|
||||
@@ -72,8 +72,8 @@ public class TailableCursorRequest<T> implements SubscriptionRequest<Document, T
|
||||
Assert.notNull(options, "Options must not be null");
|
||||
|
||||
this.messageListener = messageListener;
|
||||
this.options = options instanceof TailableCursorRequestOptions ? (TailableCursorRequestOptions) options
|
||||
: TailableCursorRequestOptions.of(options);
|
||||
this.options = options instanceof TailableCursorRequestOptions tailableCursorRequestOptions ?
|
||||
tailableCursorRequestOptions : TailableCursorRequestOptions.of(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,9 +51,8 @@ class TailableCursorTask extends CursorReadingTask<Document, Object> {
|
||||
Document filter = new Document();
|
||||
Collation collation = null;
|
||||
|
||||
if (options instanceof TailableCursorRequest.TailableCursorRequestOptions) {
|
||||
if (options instanceof TailableCursorRequest.TailableCursorRequestOptions requestOptions) {
|
||||
|
||||
TailableCursorRequestOptions requestOptions = (TailableCursorRequestOptions) options;
|
||||
if (requestOptions.getQuery().isPresent()) {
|
||||
|
||||
Query query = requestOptions.getQuery().get();
|
||||
|
||||
@@ -55,10 +55,10 @@ class TaskFactory {
|
||||
Assert.notNull(request, "Request must not be null");
|
||||
Assert.notNull(targetType, "TargetType must not be null");
|
||||
|
||||
if (request instanceof ChangeStreamRequest) {
|
||||
return new ChangeStreamTask(tempate, (ChangeStreamRequest) request, targetType, errorHandler);
|
||||
} else if (request instanceof TailableCursorRequest) {
|
||||
return new TailableCursorTask(tempate, (TailableCursorRequest) request, targetType, errorHandler);
|
||||
if (request instanceof ChangeStreamRequest changeStreamRequest) {
|
||||
return new ChangeStreamTask(tempate, changeStreamRequest, targetType, errorHandler);
|
||||
} else if (request instanceof TailableCursorRequest tailableCursorRequest) {
|
||||
return new TailableCursorTask(tempate, tailableCursorRequest, targetType, errorHandler);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
|
||||
@@ -158,12 +158,10 @@ public class BasicQuery extends Query {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof BasicQuery)) {
|
||||
if (!(o instanceof BasicQuery that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BasicQuery that = (BasicQuery) o;
|
||||
|
||||
return querySettingsEquals(that) && //
|
||||
nullSafeEquals(fieldsObject, that.fieldsObject) && //
|
||||
nullSafeEquals(queryObject, that.queryObject) && //
|
||||
|
||||
@@ -367,7 +367,7 @@ public class Criteria implements CriteriaDefinition {
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/query/mod/">MongoDB Query operator: $mod</a>
|
||||
*/
|
||||
public Criteria mod(Number value, Number remainder) {
|
||||
List<Object> l = new ArrayList<Object>(2);
|
||||
List<Object> l = new ArrayList<>(2);
|
||||
l.add(value);
|
||||
l.add(remainder);
|
||||
criteria.put("$mod", l);
|
||||
@@ -983,9 +983,9 @@ public class Criteria implements CriteriaDefinition {
|
||||
|
||||
Object existingNearOperationValue = criteria.get(command);
|
||||
|
||||
if (existingNearOperationValue instanceof Document) {
|
||||
if (existingNearOperationValue instanceof Document document) {
|
||||
|
||||
((Document) existingNearOperationValue).put(operation, maxDistance);
|
||||
document.put(operation, maxDistance);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1052,27 +1052,22 @@ public class Criteria implements CriteriaDefinition {
|
||||
return right == null;
|
||||
}
|
||||
|
||||
if (left instanceof Pattern) {
|
||||
if (left instanceof Pattern leftPattern) {
|
||||
|
||||
if (!(right instanceof Pattern)) {
|
||||
if (!(right instanceof Pattern rightPattern)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Pattern leftPattern = (Pattern) left;
|
||||
Pattern rightPattern = (Pattern) right;
|
||||
|
||||
return leftPattern.pattern().equals(rightPattern.pattern()) //
|
||||
&& leftPattern.flags() == rightPattern.flags();
|
||||
}
|
||||
|
||||
if (left instanceof Document) {
|
||||
if (left instanceof Document leftDocument) {
|
||||
|
||||
if (!(right instanceof Document)) {
|
||||
if (!(right instanceof Document rightDocument)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Document leftDocument = (Document) left;
|
||||
Document rightDocument = (Document) right;
|
||||
Iterator<Entry<String, Object>> leftIterator = leftDocument.entrySet().iterator();
|
||||
Iterator<Entry<String, Object>> rightIterator = rightDocument.entrySet().iterator();
|
||||
|
||||
@@ -1128,7 +1123,7 @@ public class Criteria implements CriteriaDefinition {
|
||||
|
||||
private static boolean requiresGeoJsonFormat(Object value) {
|
||||
return value instanceof GeoJson
|
||||
|| (value instanceof GeoCommand && ((GeoCommand) value).getShape() instanceof GeoJson);
|
||||
|| (value instanceof GeoCommand geoCommand && geoCommand.getShape() instanceof GeoJson);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -106,12 +106,10 @@ public final class GeoCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof GeoCommand)) {
|
||||
if (!(obj instanceof GeoCommand other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GeoCommand that = (GeoCommand) obj;
|
||||
|
||||
return nullSafeEquals(this.command, that.command) && nullSafeEquals(this.shape, that.shape);
|
||||
return nullSafeEquals(this.command, other.command) && nullSafeEquals(this.shape, other.shape);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public class Meta {
|
||||
values = new LinkedHashMap<>(2);
|
||||
}
|
||||
|
||||
if (value == null || (value instanceof String && !StringUtils.hasText((String) value))) {
|
||||
if (value == null || (value instanceof String stringValue && !StringUtils.hasText(stringValue))) {
|
||||
this.values.remove(key);
|
||||
}
|
||||
this.values.put(key, value);
|
||||
@@ -250,11 +250,10 @@ public class Meta {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof Meta)) {
|
||||
if (!(obj instanceof Meta other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Meta other = (Meta) obj;
|
||||
if (!ObjectUtils.nullSafeEquals(this.values, other.values)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -111,16 +111,16 @@ public class MetricConversion {
|
||||
|
||||
ConversionMultiplier(Number source, Number target) {
|
||||
|
||||
if (source instanceof BigDecimal) {
|
||||
this.source = (BigDecimal) source;
|
||||
if (source instanceof BigDecimal bigDecimal) {
|
||||
this.source = bigDecimal;
|
||||
} else {
|
||||
this.source = new BigDecimal(source.doubleValue());
|
||||
this.source = BigDecimal.valueOf(source.doubleValue());
|
||||
}
|
||||
|
||||
if (target instanceof BigDecimal) {
|
||||
this.target = (BigDecimal) target;
|
||||
if (target instanceof BigDecimal bigDecimal) {
|
||||
this.target = bigDecimal;
|
||||
} else {
|
||||
this.target = new BigDecimal(target.doubleValue());
|
||||
this.target = BigDecimal.valueOf(target.doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ public enum MongoRegexCreator {
|
||||
* @since 2.2.14
|
||||
*/
|
||||
public Object toCaseInsensitiveMatch(Object source) {
|
||||
return source instanceof String ? new BsonRegularExpression(Pattern.quote((String) source), "i") : source;
|
||||
return source instanceof String stringValue ? new BsonRegularExpression(Pattern.quote(stringValue), "i") : source;
|
||||
}
|
||||
|
||||
private String prepareAndEscapeStringBeforeApplyingLikeRegex(String source, MatchMode matcherType) {
|
||||
|
||||
@@ -77,9 +77,8 @@ public abstract class SerializationUtils {
|
||||
|
||||
private static void toFlatMap(String currentPath, Object source, Map<String, Object> map) {
|
||||
|
||||
if (source instanceof Document) {
|
||||
if (source instanceof Document document) {
|
||||
|
||||
Document document = (Document) source;
|
||||
Iterator<Map.Entry<String, Object>> it = document.entrySet().iterator();
|
||||
String pathPrefix = currentPath.isEmpty() ? "" : currentPath + '.';
|
||||
|
||||
@@ -119,18 +118,18 @@ public abstract class SerializationUtils {
|
||||
}
|
||||
|
||||
try {
|
||||
String json = value instanceof Document ? ((Document) value).toJson() : serializeValue(value);
|
||||
String json = value instanceof Document document ? document.toJson() : serializeValue(value);
|
||||
return json.replaceAll("\":", "\" :").replaceAll("\\{\"", "{ \"");
|
||||
} catch (Exception e) {
|
||||
|
||||
if (value instanceof Collection) {
|
||||
return toString((Collection<?>) value);
|
||||
} else if (value instanceof Map) {
|
||||
return toString((Map<?, ?>) value);
|
||||
if (value instanceof Collection<?> collection) {
|
||||
return toString(collection);
|
||||
} else if (value instanceof Map<?,?> map) {
|
||||
return toString(map);
|
||||
} else if (ObjectUtils.isArray(value)) {
|
||||
return toString(Arrays.asList(ObjectUtils.toObjectArray(value)));
|
||||
} else {
|
||||
return String.format("{ \"$java\" : %s }", value.toString());
|
||||
return String.format("{ \"$java\" : %s }", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,14 +98,12 @@ public class Term {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof Term)) {
|
||||
if (!(o instanceof Term other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Term term = (Term) o;
|
||||
|
||||
return ObjectUtils.nullSafeEquals(negated, term.negated) && ObjectUtils.nullSafeEquals(type, term.type)
|
||||
&& ObjectUtils.nullSafeEquals(raw, term.raw);
|
||||
return ObjectUtils.nullSafeEquals(negated, other.negated) && ObjectUtils.nullSafeEquals(type, other.type)
|
||||
&& ObjectUtils.nullSafeEquals(raw, other.raw);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -230,12 +230,10 @@ public class TextCriteria implements CriteriaDefinition {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof TextCriteria)) {
|
||||
if (!(o instanceof TextCriteria that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TextCriteria that = (TextCriteria) o;
|
||||
|
||||
return ObjectUtils.nullSafeEquals(terms, that.terms) && ObjectUtils.nullSafeEquals(language, that.language)
|
||||
&& ObjectUtils.nullSafeEquals(caseSensitive, that.caseSensitive)
|
||||
&& ObjectUtils.nullSafeEquals(diacriticSensitive, that.diacriticSensitive);
|
||||
|
||||
@@ -95,8 +95,8 @@ public class Update implements UpdateDefinition {
|
||||
|
||||
Object value = object.get(key);
|
||||
update.modifierOps.put(key, value);
|
||||
if (isKeyword(key) && value instanceof Document) {
|
||||
update.keysToUpdate.addAll(((Document) value).keySet());
|
||||
if (isKeyword(key) && value instanceof Document document) {
|
||||
update.keysToUpdate.addAll(document.keySet());
|
||||
} else {
|
||||
update.keysToUpdate.add(key);
|
||||
}
|
||||
@@ -448,8 +448,8 @@ public class Update implements UpdateDefinition {
|
||||
keyValueMap = new Document();
|
||||
this.modifierOps.put(operator, keyValueMap);
|
||||
} else {
|
||||
if (existingValue instanceof Document) {
|
||||
keyValueMap = (Document) existingValue;
|
||||
if (existingValue instanceof Document document) {
|
||||
keyValueMap = document;
|
||||
} else {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"Modifier Operations should be a LinkedHashMap but was " + existingValue.getClass());
|
||||
@@ -656,8 +656,8 @@ public class Update implements UpdateDefinition {
|
||||
return values;
|
||||
}
|
||||
|
||||
if (values.length == 1 && values[0] instanceof Collection) {
|
||||
return ((Collection<?>) values[0]).toArray();
|
||||
if (values.length == 1 && values[0] instanceof Collection<?> collection) {
|
||||
return collection.toArray();
|
||||
}
|
||||
|
||||
return Arrays.copyOf(values, values.length);
|
||||
|
||||
@@ -435,7 +435,7 @@ public class TypedJsonSchemaObject extends UntypedJsonSchemaObject {
|
||||
if (additionalProperties != null) {
|
||||
|
||||
doc.append("additionalProperties",
|
||||
additionalProperties instanceof JsonSchemaObject ? ((JsonSchemaObject) additionalProperties).toDocument()
|
||||
additionalProperties instanceof JsonSchemaObject schemaObject ? schemaObject.toDocument()
|
||||
: additionalProperties);
|
||||
}
|
||||
return doc;
|
||||
@@ -488,8 +488,8 @@ public class TypedJsonSchemaObject extends UntypedJsonSchemaObject {
|
||||
StringUtils.collectionToDelimitedString(requiredProperties, ", "));
|
||||
}
|
||||
}
|
||||
if (additionalProperties instanceof Boolean) {
|
||||
description += (((Boolean) additionalProperties) ? " " : " not ") + "allowing additional properties";
|
||||
if (additionalProperties instanceof Boolean booleanValue) {
|
||||
description += (booleanValue ? " " : " not ") + "allowing additional properties";
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(properties)) {
|
||||
@@ -714,20 +714,20 @@ public class TypedJsonSchemaObject extends UntypedJsonSchemaObject {
|
||||
|
||||
private static Bound<?> createBound(Number number, boolean inclusive) {
|
||||
|
||||
if (number instanceof Long) {
|
||||
return inclusive ? Bound.inclusive((Long) number) : Bound.exclusive((Long) number);
|
||||
if (number instanceof Long longValue) {
|
||||
return inclusive ? Bound.inclusive(longValue) : Bound.exclusive(longValue);
|
||||
}
|
||||
if (number instanceof Double) {
|
||||
return inclusive ? Bound.inclusive((Double) number) : Bound.exclusive((Double) number);
|
||||
if (number instanceof Double doubleValue) {
|
||||
return inclusive ? Bound.inclusive(doubleValue) : Bound.exclusive(doubleValue);
|
||||
}
|
||||
if (number instanceof Float) {
|
||||
return inclusive ? Bound.inclusive((Float) number) : Bound.exclusive((Float) number);
|
||||
if (number instanceof Float floatValue) {
|
||||
return inclusive ? Bound.inclusive(floatValue) : Bound.exclusive(floatValue);
|
||||
}
|
||||
if (number instanceof Integer) {
|
||||
return inclusive ? Bound.inclusive((Integer) number) : Bound.exclusive((Integer) number);
|
||||
if (number instanceof Integer integerValue) {
|
||||
return inclusive ? Bound.inclusive(integerValue) : Bound.exclusive(integerValue);
|
||||
}
|
||||
if (number instanceof BigDecimal) {
|
||||
return inclusive ? Bound.inclusive((BigDecimal) number) : Bound.exclusive((BigDecimal) number);
|
||||
if (number instanceof BigDecimal bigDecimalValue) {
|
||||
return inclusive ? Bound.inclusive(bigDecimalValue) : Bound.exclusive(bigDecimalValue);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unsupported numeric value");
|
||||
|
||||
@@ -67,20 +67,20 @@ public class ExpressionNode implements Iterable<ExpressionNode> {
|
||||
*/
|
||||
public static ExpressionNode from(SpelNode node, ExpressionState state) {
|
||||
|
||||
if (node instanceof Operator) {
|
||||
return new OperatorNode((Operator) node, state);
|
||||
if (node instanceof Operator operator) {
|
||||
return new OperatorNode(operator, state);
|
||||
}
|
||||
|
||||
if (node instanceof MethodReference) {
|
||||
return new MethodReferenceNode((MethodReference) node, state);
|
||||
if (node instanceof MethodReference methodReference) {
|
||||
return new MethodReferenceNode(methodReference, state);
|
||||
}
|
||||
|
||||
if (node instanceof Literal) {
|
||||
return new LiteralNode((Literal) node, state);
|
||||
if (node instanceof Literal literal) {
|
||||
return new LiteralNode(literal, state);
|
||||
}
|
||||
|
||||
if (node instanceof OperatorNot) {
|
||||
return new NotOperatorNode((OperatorNot) node, state);
|
||||
if (node instanceof OperatorNot operatorNot) {
|
||||
return new NotOperatorNode(operatorNot, state);
|
||||
}
|
||||
|
||||
return new ExpressionNode(node, state);
|
||||
|
||||
@@ -75,12 +75,11 @@ public class LiteralNode extends ExpressionNode {
|
||||
*/
|
||||
public boolean isUnaryMinus(@Nullable ExpressionNode parent) {
|
||||
|
||||
if (!(parent instanceof OperatorNode)) {
|
||||
if (!(parent instanceof OperatorNode operatorNode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OperatorNode operator = (OperatorNode) parent;
|
||||
return operator.isUnaryMinus();
|
||||
return operatorNode.isUnaryMinus();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -91,8 +91,8 @@ class GridFsOperationsSupport {
|
||||
*/
|
||||
protected Document toDocument(@Nullable Object value) {
|
||||
|
||||
if (value instanceof Document) {
|
||||
return (Document) value;
|
||||
if (value instanceof Document document) {
|
||||
return document;
|
||||
}
|
||||
|
||||
Document document = new Document();
|
||||
|
||||
@@ -116,7 +116,7 @@ public class ReactiveGridFsResource implements GridFsObject<Object, Publisher<Da
|
||||
|
||||
@Override
|
||||
public Object getFileId() {
|
||||
return id instanceof BsonValue ? BsonUtils.toJavaType((BsonValue) id) : id;
|
||||
return id instanceof BsonValue bsonValue ? BsonUtils.toJavaType(bsonValue) : id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MongoRepositoryExtension extends CdiRepositoryExtensionSupport {
|
||||
}
|
||||
|
||||
// Store the EntityManager bean using its qualifiers.
|
||||
mongoOperations.put(new HashSet<Annotation>(bean.getQualifiers()), (Bean<MongoOperations>) bean);
|
||||
mongoOperations.put(new HashSet<>(bean.getQualifiers()), (Bean<MongoOperations>) bean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,11 +92,11 @@ abstract class CollationUtils {
|
||||
if (placeholderValue instanceof String) {
|
||||
return Collation.parse(placeholderValue.toString());
|
||||
}
|
||||
if (placeholderValue instanceof Locale) {
|
||||
return Collation.of((Locale) placeholderValue);
|
||||
if (placeholderValue instanceof Locale locale) {
|
||||
return Collation.of(locale);
|
||||
}
|
||||
if (placeholderValue instanceof Document) {
|
||||
return Collation.from((Document) placeholderValue);
|
||||
if (placeholderValue instanceof Document document) {
|
||||
return Collation.from(document);
|
||||
}
|
||||
throw new IllegalArgumentException(String.format("Collation must be a String, Locale or Document but was %s",
|
||||
ObjectUtils.nullSafeClassName(placeholderValue)));
|
||||
|
||||
@@ -172,7 +172,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor {
|
||||
|
||||
Collection<?> values = asCollection(next);
|
||||
|
||||
List<DBRef> dbRefs = new ArrayList<DBRef>(values.size());
|
||||
List<DBRef> dbRefs = new ArrayList<>(values.size());
|
||||
for (Object element : values) {
|
||||
dbRefs.add(writer.toDBRef(element, property));
|
||||
}
|
||||
@@ -201,14 +201,14 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor {
|
||||
*/
|
||||
private static Collection<?> asCollection(@Nullable Object source) {
|
||||
|
||||
if (source instanceof Iterable) {
|
||||
if (source instanceof Iterable<?> iterable) {
|
||||
|
||||
if (source instanceof Collection) {
|
||||
return new ArrayList<>((Collection<?>) source);
|
||||
if(source instanceof Collection<?> collection) {
|
||||
return new ArrayList<>(collection);
|
||||
}
|
||||
|
||||
List<Object> result = new ArrayList<>();
|
||||
for (Object element : (Iterable<?>) source) {
|
||||
for (Object element : iterable) {
|
||||
result.add(element);
|
||||
}
|
||||
return result;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user