Skip to content

Commit 68e29d4

Browse files
mp911deapp
authored and
app
committed
Polishing.
Add missing Override annotations. Remove superfluous final keywords. Original Pull Request: spring-projects#4699
1 parent 09c618c commit 68e29d4

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}.
@@ -115,7 +116,7 @@ public DefaultIndexOperations(MongoOperations mongoOperations, String collection
115116
}
116117

117118
@Override
118-
public String ensureIndex(final IndexDefinition indexDefinition) {
119+
public String ensureIndex(IndexDefinition indexDefinition) {
119120

120121
return execute(collection -> {
121122

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

152-
public void dropIndex(final String name) {
153+
@Override
154+
public void dropIndex(String name) {
153155

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

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

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

183+
@Override
179184
public List<IndexInfo> getIndexInfo() {
180185

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

227-
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops, MongoPersistentEntity<?> entity) {
232+
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops,
233+
@Nullable MongoPersistentEntity<?> entity) {
228234

229235
if (ops.getCollation() != null || entity == null || !entity.hasCollation()) {
230236
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
@@ -116,8 +116,9 @@ public Mono<Void> alterIndex(String name, org.springframework.data.mongodb.core.
116116

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

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

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

148+
@Override
145149
public Flux<IndexInfo> getIndexInfo() {
146150

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

163-
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops, MongoPersistentEntity<?> entity) {
167+
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops,
168+
@Nullable MongoPersistentEntity<?> entity) {
164169

165170
if (ops.getCollation() != null || entity == null || !entity.hasCollation()) {
166171
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)