Skip to content

Commit a819a5e

Browse files
mp911dechristophstrobl
authored andcommitted
Polishing.
Add missing Override annotations. Remove superfluous final keywords. Original Pull Request: #4699
1 parent 7f1c66e commit a819a5e

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121

2222
import org.bson.Document;
23+
2324
import org.springframework.dao.DataAccessException;
2425
import org.springframework.data.mongodb.MongoDatabaseFactory;
2526
import org.springframework.data.mongodb.UncategorizedMongoDbException;
@@ -54,7 +55,7 @@ public class DefaultIndexOperations implements IndexOperations {
5455
private final QueryMapper mapper;
5556
private final @Nullable Class<?> type;
5657

57-
private MongoOperations mongoOperations;
58+
private final MongoOperations mongoOperations;
5859

5960
/**
6061
* Creates a new {@link DefaultIndexOperations}.
@@ -114,7 +115,7 @@ public DefaultIndexOperations(MongoOperations mongoOperations, String collection
114115
this.type = type;
115116
}
116117

117-
public String ensureIndex(final IndexDefinition indexDefinition) {
118+
public String ensureIndex(IndexDefinition indexDefinition) {
118119

119120
return execute(collection -> {
120121

@@ -148,7 +149,8 @@ private MongoPersistentEntity<?> lookupPersistentEntity(@Nullable Class<?> entit
148149
return null;
149150
}
150151

151-
public void dropIndex(final String name) {
152+
@Override
153+
public void dropIndex(String name) {
152154

153155
execute(collection -> {
154156
collection.dropIndex(name);
@@ -166,15 +168,18 @@ public void alterIndex(String name, org.springframework.data.mongodb.core.index.
166168
Document result = mongoOperations
167169
.execute(db -> db.runCommand(new Document("collMod", collectionName).append("index", indexOptions)));
168170

169-
if(NumberUtils.convertNumberToTargetClass(result.get("ok", (Number) 0), Integer.class) != 1) {
170-
throw new UncategorizedMongoDbException("Index '%s' could not be modified. Response was %s".formatted(name, result.toJson()), null);
171+
if (NumberUtils.convertNumberToTargetClass(result.get("ok", (Number) 0), Integer.class) != 1) {
172+
throw new UncategorizedMongoDbException(
173+
"Index '%s' could not be modified. Response was %s".formatted(name, result.toJson()), null);
171174
}
172175
}
173176

177+
@Override
174178
public void dropAllIndexes() {
175179
dropIndex("*");
176180
}
177181

182+
@Override
178183
public List<IndexInfo> getIndexInfo() {
179184

180185
return execute(new CollectionCallback<List<IndexInfo>>() {
@@ -223,7 +228,8 @@ private IndexOptions addPartialFilterIfPresent(IndexOptions ops, Document source
223228
mapper.getMappedSort((Document) sourceOptions.get(PARTIAL_FILTER_EXPRESSION_KEY), entity));
224229
}
225230

226-
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops, MongoPersistentEntity<?> entity) {
231+
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops,
232+
@Nullable MongoPersistentEntity<?> entity) {
227233

228234
if (ops.getCollation() != null || entity == null || !entity.hasCollation()) {
229235
return ops;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultReactiveIndexOperations.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ public Mono<Void> alterIndex(String name, org.springframework.data.mongodb.core.
115115

116116
return Flux.from(db.runCommand(new Document("collMod", collectionName).append("index", indexOptions)))
117117
.doOnNext(result -> {
118-
if(NumberUtils.convertNumberToTargetClass(result.get("ok", (Number) 0), Integer.class) != 1) {
119-
throw new UncategorizedMongoDbException("Index '%s' could not be modified. Response was %s".formatted(name, result.toJson()), null);
118+
if (NumberUtils.convertNumberToTargetClass(result.get("ok", (Number) 0), Integer.class) != 1) {
119+
throw new UncategorizedMongoDbException(
120+
"Index '%s' could not be modified. Response was %s".formatted(name, result.toJson()), null);
120121
}
121122
});
122123
}).then();
@@ -133,14 +134,17 @@ private MongoPersistentEntity<?> lookupPersistentEntity(String collection) {
133134
.orElse(null);
134135
}
135136

136-
public Mono<Void> dropIndex(final String name) {
137+
@Override
138+
public Mono<Void> dropIndex(String name) {
137139
return mongoOperations.execute(collectionName, collection -> collection.dropIndex(name)).then();
138140
}
139141

142+
@Override
140143
public Mono<Void> dropAllIndexes() {
141144
return dropIndex("*");
142145
}
143146

147+
@Override
144148
public Flux<IndexInfo> getIndexInfo() {
145149

146150
return mongoOperations.execute(collectionName, collection -> collection.listIndexes(Document.class)) //
@@ -159,7 +163,8 @@ private IndexOptions addPartialFilterIfPresent(IndexOptions ops, Document source
159163
queryMapper.getMappedObject((Document) sourceOptions.get(PARTIAL_FILTER_EXPRESSION_KEY), entity));
160164
}
161165

162-
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops, MongoPersistentEntity<?> entity) {
166+
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops,
167+
@Nullable MongoPersistentEntity<?> entity) {
163168

164169
if (ops.getCollation() != null || entity == null || !entity.hasCollation()) {
165170
return ops;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultScriptOperations.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public NamedMongoScript register(NamedMongoScript script) {
8585
}
8686

8787
@Override
88-
public Object execute(final ExecutableMongoScript script, final Object... args) {
88+
public Object execute(ExecutableMongoScript script, Object... args) {
8989

9090
Assert.notNull(script, "Script must not be null");
9191

@@ -104,7 +104,7 @@ public Object doInDB(MongoDatabase db) throws MongoException, DataAccessExceptio
104104
}
105105

106106
@Override
107-
public Object call(final String scriptName, final Object... args) {
107+
public Object call(String scriptName, Object... args) {
108108

109109
Assert.hasText(scriptName, "ScriptName must not be null or empty");
110110

0 commit comments

Comments
 (0)