From: Roland Haeder Date: Wed, 26 Aug 2015 13:33:01 +0000 (+0200) Subject: Added more logging + support for logical AND matcher, readObject() currently causes... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=107a4590832d06eb508567cce86c22273fbc7802;p=jcore.git Added more logging + support for logical AND matcher, readObject() currently causes a NPE Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index 047bcad..3bb76be 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -1168,7 +1168,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { // Search for proper field instance for (final Field field : fields) { // Debug message - this.getLogger().debug(MessageFormat.format("getName()={0},fieldName={1}", field.getName(), fieldName)); //NOI18N + this.getLogger().debug(MessageFormat.format("field.getName()={0},fieldName={1}", field.getName(), fieldName)); //NOI18N // Does it match? if (field.getName().equals(fieldName)) { diff --git a/src/org/mxchange/jcore/criteria/BaseCriteria.java b/src/org/mxchange/jcore/criteria/BaseCriteria.java index 469404b..0467781 100644 --- a/src/org/mxchange/jcore/criteria/BaseCriteria.java +++ b/src/org/mxchange/jcore/criteria/BaseCriteria.java @@ -73,7 +73,7 @@ public class BaseCriteria extends BaseFrameworkSystem implements Criteria { * * @param logcial the Logical instance to set */ - public final void setLogcial (final Logical logcial) { + public final void setLogical (final Logical logcial) { this.logcial = logcial; } diff --git a/src/org/mxchange/jcore/criteria/Criteria.java b/src/org/mxchange/jcore/criteria/Criteria.java index c6f1397..4af20fb 100644 --- a/src/org/mxchange/jcore/criteria/Criteria.java +++ b/src/org/mxchange/jcore/criteria/Criteria.java @@ -19,6 +19,7 @@ package org.mxchange.jcore.criteria; import java.util.Map; import java.util.Set; import org.mxchange.jcore.FrameworkInterface; +import org.mxchange.jcore.criteria.logical.Logical; /** * A general interface for criteria @@ -63,4 +64,11 @@ public interface Criteria extends FrameworkInterface { * @return Key-value paira of all entries */ public Set> entrySet (); + + /** + * Setter for logical matcher instance + * + * @param logical Logical matcher instance + */ + public void setLogical (final Logical logical); } diff --git a/src/org/mxchange/jcore/criteria/logical/and/AndLogicalMatcher.java b/src/org/mxchange/jcore/criteria/logical/and/AndLogicalMatcher.java new file mode 100644 index 0000000..93d6297 --- /dev/null +++ b/src/org/mxchange/jcore/criteria/logical/and/AndLogicalMatcher.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcore.criteria.logical.and; + +import java.text.MessageFormat; +import java.util.Map; +import java.util.Set; +import org.mxchange.jcore.BaseFrameworkSystem; +import org.mxchange.jcore.criteria.logical.Logical; + +/** + * A boolean AND "logical matcher" class + * + * @author Roland Haeder + */ +public class AndLogicalMatcher extends BaseFrameworkSystem implements Logical { + /** + * Default constructor + */ + public AndLogicalMatcher () { + } + + @Override + public boolean matches (final Set> entrySet, final Map criteraMatches) { + // Trace message + this.getLogger().trace(MessageFormat.format("entrySet={0},criteriaMatches={1} - CALLED!", entrySet, criteraMatches)); //NOI18N + + // Default is matching, then check if something is not matching and set result to false + boolean matches = true; + + // Walk through set + for (Map.Entry entry : entrySet) { + // Debug message + 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()) { + // Get key and value + String criteriaKey = criteriaMatch.getKey(); + Boolean criteriaMatches = criteriaMatch.getValue(); + + // Debug message + this.getLogger().debug(MessageFormat.format("criteriaKey={0},criteriaMatches={1}", criteriaKey, criteriaMatches)); //NOI18N + } + } + + // Trace message + this.getLogger().trace(MessageFormat.format("matches={0} - EXIT!", matches)); //NOI18N + + // Return it + return matches; + } + +} diff --git a/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java b/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java index e1886dd..ae25c6b 100644 --- a/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java +++ b/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java @@ -123,6 +123,9 @@ public class SearchCriteria extends BaseCriteria implements SearchableCriteria { // 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 { + // Debug message + this.getLogger().debug(MessageFormat.format("entrySet.size()={0},criteriaMatches.size()={1} - Calling matches() on {2} ...", this.entrySet().size(), criteraMatches.size(), this.getLogical())); + // Now for the final test matches = this.getLogical().matches(this.entrySet(), criteraMatches); } diff --git a/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java b/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java index 0c3a632..598d575 100644 --- a/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java +++ b/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java @@ -88,6 +88,9 @@ public abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implement if (key == null) { // Key is null throw new NullPointerException("key is null"); //NOI18N + } else if (value == null) { + // Issue warning about null reference + this.getLogger().warn(MessageFormat.format("value for key={0} is null, this may cause problems.", key)); } // Add it to map diff --git a/src/org/mxchange/jcore/factory/database/backend/BackendFactory.java b/src/org/mxchange/jcore/factory/database/backend/BackendFactory.java index 5e16166..65e216a 100644 --- a/src/org/mxchange/jcore/factory/database/backend/BackendFactory.java +++ b/src/org/mxchange/jcore/factory/database/backend/BackendFactory.java @@ -61,7 +61,7 @@ public class BackendFactory extends BaseFrameworkSystem { factory.getLogger().debug(MessageFormat.format("className={0}", className)); //NOI18N // Is it null? - if (className == null) { + if (null == className) { // Not valid throw new NullPointerException("className is null"); //NOI18N }