From: Roland Haeder Date: Thu, 27 Aug 2015 06:51:19 +0000 (+0200) Subject: Better compare this way: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=862b71952791e8a0f67f38a469ec6734fbfca304;p=jcore.git Better compare this way: if (null == foo) Otherwise could lead to a bug if you miss only one equal sign Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index 3bb76be..cee4a1a 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -779,7 +779,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.getLogger().trace(MessageFormat.format("str={0}", str)); //NOI18N // Is it null? - if (str == null) { + if (null == str) { // Return empty string return ""; //NOI18N } @@ -1014,10 +1014,10 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N // Both should not be null - if (key == null) { + if (null == key) { // key is null throw new NullPointerException("key is null"); //NOI18N - } else if (value == null) { + } else if (null == value) { // value is null throw new NullPointerException("value is null"); //NOI18N } @@ -1187,7 +1187,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.getLogger().debug(MessageFormat.format("type={0}", type)); // type should not be null - if (type == null) { + if (null == type) { // No null allowed throw new NullPointerException("type is null"); //NOI18N } diff --git a/src/org/mxchange/jcore/contact/BaseContact.java b/src/org/mxchange/jcore/contact/BaseContact.java index 9bf7426..a6238a9 100644 --- a/src/org/mxchange/jcore/contact/BaseContact.java +++ b/src/org/mxchange/jcore/contact/BaseContact.java @@ -594,7 +594,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N // The client must be set - if (client == null) { + if (null == client) { // Not set throw new NullPointerException("client is null"); //NOI18N } diff --git a/src/org/mxchange/jcore/contact/Gender.java b/src/org/mxchange/jcore/contact/Gender.java index b257fd9..3ba9ef5 100644 --- a/src/org/mxchange/jcore/contact/Gender.java +++ b/src/org/mxchange/jcore/contact/Gender.java @@ -81,7 +81,7 @@ public enum Gender { } // Still null? - if (g == null) { + if (null == g) { // Didn't found a valid one throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); } diff --git a/src/org/mxchange/jcore/criteria/logical/Logical.java b/src/org/mxchange/jcore/criteria/logical/Logical.java index 2f26db4..0de068a 100644 --- a/src/org/mxchange/jcore/criteria/logical/Logical.java +++ b/src/org/mxchange/jcore/criteria/logical/Logical.java @@ -31,8 +31,8 @@ public interface Logical extends FrameworkInterface { * Checks logical match condition * * @param entrySet Entry set where the values are - * @param criteraMatches Criteria matches + * @param criteriaMatches Criteria matches * @return Whether it matches */ - public boolean matches (final Set> entrySet, final Map criteraMatches); + public boolean matches (final Set> entrySet, final Map criteriaMatches); } diff --git a/src/org/mxchange/jcore/criteria/logical/and/AndLogicalMatcher.java b/src/org/mxchange/jcore/criteria/logical/and/AndLogicalMatcher.java index 6dfb4f3..91430ef 100644 --- a/src/org/mxchange/jcore/criteria/logical/and/AndLogicalMatcher.java +++ b/src/org/mxchange/jcore/criteria/logical/and/AndLogicalMatcher.java @@ -35,9 +35,9 @@ public class AndLogicalMatcher extends BaseFrameworkSystem implements Logical { } @Override - public boolean matches (final Set> entrySet, final Map criteraMatches) { + public boolean matches (final Set> entrySet, final Map criteriaMatches) { // Trace message - this.getLogger().trace(MessageFormat.format("entrySet={0},criteriaMatches={1} - CALLED!", entrySet, criteraMatches)); //NOI18N + this.getLogger().trace(MessageFormat.format("entrySet={0},criteriaMatches={1} - CALLED!", entrySet, criteriaMatches)); //NOI18N // Default is matching, then check if something is not matching and set result to false boolean matches = true; @@ -48,18 +48,18 @@ public class AndLogicalMatcher extends BaseFrameworkSystem implements Logical { this.getLogger().debug(MessageFormat.format("entry.key={0},entry.value={1}", entry.getKey(), entry.getValue())); //NOI18N // Check all matches - for (Map.Entry criteriaMatch : criteraMatches.entrySet()) { + for (Map.Entry criteriaMatch : criteriaMatches.entrySet()) { // Get key and value String criteriaKey = criteriaMatch.getKey(); - Boolean criteriaMatches = criteriaMatch.getValue(); + Boolean criteriaMatching = criteriaMatch.getValue(); // Debug message - this.getLogger().debug(MessageFormat.format("criteriaKey={0},criteriaMatches={1}", criteriaKey, criteriaMatches)); //NOI18N + this.getLogger().debug(MessageFormat.format("criteriaKey={0},criteriaMatching={1}", criteriaKey, criteriaMatching)); //NOI18N // Is both the same and false? - if ((entry.getKey().equals(criteriaKey)) && (!criteriaMatches)) { + if ((entry.getKey().equals(criteriaKey)) && (!criteriaMatching)) { // Debug message - this.getLogger().debug("Not matching, aborting search."); + this.getLogger().debug("Not matching, aborting search."); //NOI18N // Doesn't match matches = false; diff --git a/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java b/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java index ae25c6b..b276026 100644 --- a/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java +++ b/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java @@ -71,7 +71,7 @@ public class SearchCriteria extends BaseCriteria implements SearchableCriteria { this.getLogger().trace(MessageFormat.format("storeable={0} - CALLED!", storeable)); //NOI18N // Must not be null - if (storeable == null) { + if (null == storeable) { // Abort here throw new NullPointerException("storeable is null"); //NOI18N } @@ -89,7 +89,7 @@ public class SearchCriteria extends BaseCriteria implements SearchableCriteria { } // Init matches array - Map criteraMatches = new HashMap<>(this.entrySet().size()); + Map criteriaMatches = new HashMap<>(this.entrySet().size()); // Check all conditions for (final Map.Entry criteria : this.entrySet()) { @@ -108,26 +108,26 @@ public class SearchCriteria extends BaseCriteria implements SearchableCriteria { this.getLogger().debug(MessageFormat.format("value={0} - MATCHES!", value)); //NOI18N // Matching criteria found - criteraMatches.put(criteria.getKey(), true); + criteriaMatches.put(criteria.getKey(), true); } } // Init matches - boolean matches; + boolean matches = false; // Is only one entry given? if (this.entrySet().size() == 1) { // Okay, one criteria only, no need for a "complex" logical match check - matches = (criteraMatches.size() == 1); + matches = (criteriaMatches.size() == 1); } else if (this.getLogical() == null) { // Logical instance is null - throw new NullPointerException(MessageFormat.format("logical is not set, but more than one column ({0}/{1}) shall be matched.", this.entrySet().size(), criteraMatches.size())); //NOI18N - } else { + throw new NullPointerException(MessageFormat.format("logical is not set, but more than one column ({0}/{1}) shall be matched.", this.entrySet().size(), criteriaMatches.size())); //NOI18N + } else if (this.entrySet().size() == criteriaMatches.size()) { // Debug message - this.getLogger().debug(MessageFormat.format("entrySet.size()={0},criteriaMatches.size()={1} - Calling matches() on {2} ...", this.entrySet().size(), criteraMatches.size(), this.getLogical())); + this.getLogger().debug(MessageFormat.format("entrySet.size()={0},criteriaMatches.size()={1} - Calling matches() on {2} ...", this.entrySet().size(), criteriaMatches.size(), this.getLogical())); // Now for the final test - matches = this.getLogical().matches(this.entrySet(), criteraMatches); + matches = this.getLogical().matches(this.entrySet(), criteriaMatches); } // Trace message diff --git a/src/org/mxchange/jcore/database/backend/BaseDatabaseBackend.java b/src/org/mxchange/jcore/database/backend/BaseDatabaseBackend.java index d63fafc..73df2bf 100644 --- a/src/org/mxchange/jcore/database/backend/BaseDatabaseBackend.java +++ b/src/org/mxchange/jcore/database/backend/BaseDatabaseBackend.java @@ -47,7 +47,7 @@ public class BaseDatabaseBackend extends BaseFrameworkSystem { this.getLogger().trace(MessageFormat.format("driverName={0} - CALLED!", driverName)); //NOI18N // driverName shall not be null - if (driverName == null) { + if (null == driverName) { // Is null throw new NullPointerException("driverName is null"); } diff --git a/src/org/mxchange/jcore/database/backend/DatabaseBackend.java b/src/org/mxchange/jcore/database/backend/DatabaseBackend.java index a787304..ef014e7 100644 --- a/src/org/mxchange/jcore/database/backend/DatabaseBackend.java +++ b/src/org/mxchange/jcore/database/backend/DatabaseBackend.java @@ -61,7 +61,7 @@ public interface DatabaseBackend extends FrameworkInterface { * * The callee should not modify any content of the criteria instance. * - * @param critera Search critera + * @param criteria Search criteria * @return A result instance * @throws java.io.IOException If any IO error occurs * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found @@ -71,7 +71,7 @@ public interface DatabaseBackend extends FrameworkInterface { * @throws java.lang.IllegalAccessException If the method cannot be accessed * @throws java.lang.reflect.InvocationTargetException Any other problems? */ - public Result doSelectByCriteria (final SearchableCriteria critera) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException; + public Result doSelectByCriteria (final SearchableCriteria criteria) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException; /** * Shuts down this backend diff --git a/src/org/mxchange/jcore/database/backend/base64/Base64CsvDatabaseBackend.java b/src/org/mxchange/jcore/database/backend/base64/Base64CsvDatabaseBackend.java index e96886c..f1186a8 100644 --- a/src/org/mxchange/jcore/database/backend/base64/Base64CsvDatabaseBackend.java +++ b/src/org/mxchange/jcore/database/backend/base64/Base64CsvDatabaseBackend.java @@ -109,7 +109,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset)); //NOI18N // dataset should not be null and not empty - if (dataset == null) { + if (null == dataset) { // It is null, so abort here throw new NullPointerException("dataset is null"); //NOI18N } else if (dataset.isEmpty()) { @@ -173,9 +173,9 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat } @Override - public Result doSelectByCriteria (final SearchableCriteria critera) throws IOException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + public Result doSelectByCriteria (final SearchableCriteria criteria) throws IOException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera)); //NOI18N + this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", criteria)); //NOI18N // Init result instance Result result = new DatabaseResult(); @@ -201,7 +201,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat this.getLogger().debug(MessageFormat.format("storeable={0}", storeable)); //NOI18N // Now matches the found instance - if (critera.matches(storeable)) { + if (criteria.matches(storeable)) { // Then add it to result result.add(storeable); } @@ -269,7 +269,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat this.getLogger().debug(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N // "line" must not be null or empty - if (line == null) { + if (null == line) { // Is null throw new NullPointerException("line is null"); //NOI18N } else if (line.isEmpty()) { @@ -402,7 +402,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat String base64 = this.getStorageFile().readLine(); // Is the line null? - if (base64 == null) { + if (null == base64) { // Then throw NPE here throw new NullPointerException("base64 is null, maybe missed to call isEndOfFile() ?"); //NOI18N } @@ -447,7 +447,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat this.getLogger().trace(MessageFormat.format("output={0} - CALLED!", output)); //NOI18N // No null or empty strings - if (output == null) { + if (null == output) { // Is null throw new NullPointerException("output is null"); //NOI18N } else if (output.length() == 0) { diff --git a/src/org/mxchange/jcore/database/backend/datasource/DataSourceDatabaseBackend.java b/src/org/mxchange/jcore/database/backend/datasource/DataSourceDatabaseBackend.java index 6843d19..d5265d3 100644 --- a/src/org/mxchange/jcore/database/backend/datasource/DataSourceDatabaseBackend.java +++ b/src/org/mxchange/jcore/database/backend/datasource/DataSourceDatabaseBackend.java @@ -82,7 +82,7 @@ public class DataSourceDatabaseBackend extends BaseDatabaseBackend implements Da this.getLogger().trace("CALLED!"); // Is the connection given? - if (connection == null) { + if (null == connection) { // Initial context Context context = new InitialContext(); @@ -115,8 +115,8 @@ public class DataSourceDatabaseBackend extends BaseDatabaseBackend implements Da } @Override - public Result doSelectByCriteria (final SearchableCriteria critera) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - throw new UnsupportedOperationException("Not supported yet: criteria=" + critera); //To change body of generated methods, choose Tools | Templates. + public Result doSelectByCriteria (final SearchableCriteria criteria) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + throw new UnsupportedOperationException("Not supported yet: criteria=" + criteria); //To change body of generated methods, choose Tools | Templates. } @Override diff --git a/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java b/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java index 25091e4..86f487e 100644 --- a/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java +++ b/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java @@ -139,7 +139,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset)); //NOI18N // dataset should not be null and not empty - if (dataset == null) { + if (null == dataset) { // It is null, so abort here throw new NullPointerException("dataset is null"); //NOI18N } else if (dataset.isEmpty()) { @@ -181,7 +181,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas this.getLogger().debug(MessageFormat.format("value={0} - AFTER!", value)); //NOI18N // Is the value null? - if (value == null) { + if (null == value) { // Add null valueQuery.append("NULL,"); //NOI18N } else { @@ -222,12 +222,12 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas } @Override - public Result doSelectByCriteria (final SearchableCriteria critera) throws SQLException { + public Result doSelectByCriteria (final SearchableCriteria criteria) throws SQLException { // Trace message - this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera)); //NOI18N + this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", criteria)); //NOI18N // criteria must not be null - if (critera == null) { + if (null == criteria) { // Abort here throw new NullPointerException("criteria is null"); //NOI18N } @@ -236,7 +236,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas StringBuilder query = new StringBuilder(String.format("SELECT * FROM `%s`", this.getTableName())); //NOI18N // Get entry set - Set> set = critera.entrySet(); + Set> set = criteria.entrySet(); // Debug message this.getLogger().debug(MessageFormat.format("set.isEmpty()={0}", set.isEmpty())); //NOI18N @@ -279,14 +279,14 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas } // Is limit set? - if (critera.getLimit() > 0) { + if (criteria.getLimit() > 0) { // Is skip set? - if (critera.getSkip() > 0) { + if (criteria.getSkip() > 0) { // Limit with skip - query.append(String.format(" LIMIT %d,%d", critera.getSkip(), critera.getLimit())); //NOI18N + query.append(String.format(" LIMIT %d,%d", criteria.getSkip(), criteria.getLimit())); //NOI18N } else { // Only limit - query.append(String.format(" LIMIT %d", critera.getLimit())); //NOI18N + query.append(String.format(" LIMIT %d", criteria.getLimit())); //NOI18N } } @@ -413,7 +413,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas // Found ineteger statement.setFloat(index, (float) value); - } else if (value == null) { + } else if (null == value) { // Debug message this.getLogger().warn(MessageFormat.format("Null value in index={0} is not supported (yet)", index)); //NOI18N } else { diff --git a/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java b/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java index 598d575..ca28543 100644 --- a/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java +++ b/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java @@ -85,10 +85,10 @@ public abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implement this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N // Is key null? - if (key == null) { + if (null == key) { // Key is null throw new NullPointerException("key is null"); //NOI18N - } else if (value == null) { + } else if (null == value) { // Issue warning about null reference this.getLogger().warn(MessageFormat.format("value for key={0} is null, this may cause problems.", key)); } diff --git a/src/org/mxchange/jcore/factory/database/backend/BackendFactory.java b/src/org/mxchange/jcore/factory/database/backend/BackendFactory.java index 65e216a..8e1f3a4 100644 --- a/src/org/mxchange/jcore/factory/database/backend/BackendFactory.java +++ b/src/org/mxchange/jcore/factory/database/backend/BackendFactory.java @@ -49,7 +49,7 @@ public class BackendFactory extends BaseFrameworkSystem { factory.getLogger().trace(MessageFormat.format("frontend={0} - CALLED!", frontend)); //NOI18N // frontend must be set - if (frontend == null) { + if (null == frontend) { // Is null throw new NullPointerException("frontend is null"); } diff --git a/src/org/mxchange/jcore/manager/application/ApplicationManager.java b/src/org/mxchange/jcore/manager/application/ApplicationManager.java index ecbfff7..c47f0ae 100644 --- a/src/org/mxchange/jcore/manager/application/ApplicationManager.java +++ b/src/org/mxchange/jcore/manager/application/ApplicationManager.java @@ -34,7 +34,7 @@ public class ApplicationManager extends BaseManager implements ManageableApplica */ public static final ManageableApplication getManager (final Application application) { // Application instance must be set - if (application == null) { + if (null == application) { // Abort here throw new NullPointerException("application is null"); //NOI18N } @@ -53,7 +53,7 @@ public class ApplicationManager extends BaseManager implements ManageableApplica */ private ApplicationManager (final Application application) { // Application instance must be set - if (application == null) { + if (null == application) { // Abort here throw new NullPointerException("application is null"); //NOI18N } diff --git a/src/org/mxchange/jcore/model/BaseModel.java b/src/org/mxchange/jcore/model/BaseModel.java index 821d57c..5caaba8 100644 --- a/src/org/mxchange/jcore/model/BaseModel.java +++ b/src/org/mxchange/jcore/model/BaseModel.java @@ -54,7 +54,7 @@ public class BaseModel extends BaseFrameworkSystem { this.getLogger().trace("listener=" + listener + " - CALLED!"); //NOI18N // Listener must not be null - if (listener == null) { + if (null == listener) { // Abort here throw new NullPointerException("listener is null"); } @@ -79,7 +79,7 @@ public class BaseModel extends BaseFrameworkSystem { this.getLogger().trace("listener=" + listener + " - CALLED!"); //NOI18N // Listener must not be null - if (listener == null) { + if (null == listener) { // Abort here throw new NullPointerException("listener is null"); } @@ -104,7 +104,7 @@ public class BaseModel extends BaseFrameworkSystem { this.getLogger().trace("listener=" + listener + " - CALLED!"); //NOI18N // Listener must not be null - if (listener == null) { + if (null == listener) { // Abort here throw new NullPointerException("listener is null"); } @@ -129,7 +129,7 @@ public class BaseModel extends BaseFrameworkSystem { this.getLogger().trace("listener=" + listener + " - CALLED!"); //NOI18N // Listener must not be null - if (listener == null) { + if (null == listener) { // Abort here throw new NullPointerException("listener is null"); } diff --git a/src/org/mxchange/jcore/model/swing/contact/ContactTableModel.java b/src/org/mxchange/jcore/model/swing/contact/ContactTableModel.java index 9638240..67061c4 100644 --- a/src/org/mxchange/jcore/model/swing/contact/ContactTableModel.java +++ b/src/org/mxchange/jcore/model/swing/contact/ContactTableModel.java @@ -41,7 +41,7 @@ public class ContactTableModel extends BaseModel implements TableModel { this.getLogger().trace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N // Client must not be null - if (client == null) { + if (null == client) { // Abort here throw new NullPointerException("client is null"); //NOI18N }