DATAMONGO-1337 - General code quality improvements.

A round of code polish regarding the PMD and Squid rules referred to in the ticket.

Original pull request: #336.
This commit is contained in:
Christian Ivan
2015-11-26 14:49:09 +07:00
committed by Oliver Gierke
parent eeb37e9104
commit 1d1c80db7b
11 changed files with 17 additions and 17 deletions

View File

@@ -45,7 +45,7 @@ public class MongoChangeSetPersister implements ChangeSetPersister<Object> {
private static final String ENTITY_FIELD_NAME = "_entity_field_name"; private static final String ENTITY_FIELD_NAME = "_entity_field_name";
private static final String ENTITY_FIELD_CLASS = "_entity_field_class"; private static final String ENTITY_FIELD_CLASS = "_entity_field_class";
protected final Logger log = LoggerFactory.getLogger(getClass()); private static final Logger log = LoggerFactory.getLogger(getClass());
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;

View File

@@ -160,7 +160,7 @@ public class MongoLog4jAppender extends AppenderSkeleton {
// Copy properties into document // Copy properties into document
Map<Object, Object> props = event.getProperties(); Map<Object, Object> props = event.getProperties();
if (null != props && props.size() > 0) { if (null != props && !props.isEmpty()) {
BasicDBObject propsDbo = new BasicDBObject(); BasicDBObject propsDbo = new BasicDBObject();
for (Map.Entry<Object, Object> entry : props.entrySet()) { for (Map.Entry<Object, Object> entry : props.entrySet()) {
propsDbo.put(entry.getKey().toString(), entry.getValue().toString()); propsDbo.put(entry.getKey().toString(), entry.getValue().toString());

View File

@@ -39,7 +39,7 @@ public class MongoLog4jAppenderIntegrationTests {
static final String NAME = MongoLog4jAppenderIntegrationTests.class.getName(); static final String NAME = MongoLog4jAppenderIntegrationTests.class.getName();
Logger log = Logger.getLogger(NAME); private static final Logger log = Logger.getLogger(NAME);
Mongo mongo; Mongo mongo;
DB db; DB db;
String collection; String collection;

View File

@@ -153,7 +153,7 @@ public class Aggregation {
protected Aggregation(List<AggregationOperation> aggregationOperations, AggregationOptions options) { protected Aggregation(List<AggregationOperation> aggregationOperations, AggregationOptions options) {
Assert.notNull(aggregationOperations, "AggregationOperations must not be null!"); Assert.notNull(aggregationOperations, "AggregationOperations must not be null!");
Assert.isTrue(aggregationOperations.size() > 0, "At least one AggregationOperation has to be provided"); Assert.isTrue(!aggregationOperations.isEmpty(), "At least one AggregationOperation has to be provided");
Assert.notNull(options, "AggregationOptions must not be null!"); Assert.notNull(options, "AggregationOptions must not be null!");
this.operations = aggregationOperations; this.operations = aggregationOperations;

View File

@@ -966,7 +966,7 @@ public class QueryMapper {
private static boolean isPositionalParameter(String partial) { private static boolean isPositionalParameter(String partial) {
if (partial.equals("$")) { if ("$".equals(partial)) {
return true; return true;
} }

View File

@@ -118,7 +118,7 @@ public class Criteria implements CriteriaDefinition {
} }
private boolean lastOperatorWasNot() { private boolean lastOperatorWasNot() {
return this.criteria.size() > 0 && "$not".equals(this.criteria.keySet().toArray()[this.criteria.size() - 1]); return !this.criteria.isEmpty() && "$not".equals(this.criteria.keySet().toArray()[this.criteria.size() - 1]);
} }
/** /**

View File

@@ -32,7 +32,7 @@ import com.mongodb.MongoException;
*/ */
public abstract class AbstractMonitor { public abstract class AbstractMonitor {
private final Logger logger = LoggerFactory.getLogger(getClass()); private static final Logger logger = LoggerFactory.getLogger(getClass());
protected Mongo mongo; protected Mongo mongo;
private String username; private String username;

View File

@@ -420,7 +420,7 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
return PUNCTATION_PATTERN.matcher(source).find() ? Pattern.quote(source) : source; return PUNCTATION_PATTERN.matcher(source).find() ? Pattern.quote(source) : source;
} }
if (source.equals("*")) { if ("*".equals(source)) {
return ".*"; return ".*";
} }

View File

@@ -36,7 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration("classpath:infrastructure.xml") @ContextConfiguration("classpath:infrastructure.xml")
public class MongoAdminIntegrationTests { public class MongoAdminIntegrationTests {
private static Log logger = LogFactory.getLog(MongoAdminIntegrationTests.class); private static final Log logger = LogFactory.getLog(MongoAdminIntegrationTests.class);
@SuppressWarnings("unused") @SuppressWarnings("unused")
private DB testAdminDb; private DB testAdminDb;

View File

@@ -2402,10 +2402,10 @@ public class MappingMongoConverterUnitTests {
return null; return null;
} }
if (source.equals("foo-enum-value")) { if ("foo-enum-value".equals(source)) {
return FooBarEnum.FOO; return FooBarEnum.FOO;
} }
if (source.equals("bar-enum-value")) { if ("bar-enum-value".equals(source)) {
return FooBarEnum.BAR; return FooBarEnum.BAR;
} }

View File

@@ -118,13 +118,13 @@ public class MapReduceTests {
int size = 0; int size = 0;
for (ContentAndVersion cv : results) { for (ContentAndVersion cv : results) {
if (cv.getId().equals("Resume")) { if ("Resume".equals(cv.getId())) {
assertEquals(6, cv.getValue().longValue()); assertEquals(6, cv.getValue().longValue());
} }
if (cv.getId().equals("Schema")) { if ("Schema".equals(cv.getId())) {
assertEquals(2, cv.getValue().longValue()); assertEquals(2, cv.getValue().longValue());
} }
if (cv.getId().equals("mongoDB How-To")) { if ("mongoDB How-To".equals(cv.getId())) {
assertEquals(2, cv.getValue().longValue()); assertEquals(2, cv.getValue().longValue());
} }
size++; size++;
@@ -141,13 +141,13 @@ public class MapReduceTests {
new MapReduceOptions().outputCollection("jmr2_out"), NumberAndVersion.class); new MapReduceOptions().outputCollection("jmr2_out"), NumberAndVersion.class);
int size = 0; int size = 0;
for (NumberAndVersion nv : results) { for (NumberAndVersion nv : results) {
if (nv.getId().equals("1")) { if ("1".equals(nv.getId())) {
assertEquals(2, nv.getValue().longValue()); assertEquals(2, nv.getValue().longValue());
} }
if (nv.getId().equals("2")) { if ("2".equals(nv.getId())) {
assertEquals(6, nv.getValue().longValue()); assertEquals(6, nv.getValue().longValue());
} }
if (nv.getId().equals("3")) { if ("3".equals(nv.getId())) {
assertEquals(2, nv.getValue().longValue()); assertEquals(2, nv.getValue().longValue());
} }
size++; size++;