]> git.mxchange.org Git - jcore.git/commitdiff
Added more logging + support for logical AND matcher, readObject() currently causes...
authorRoland Haeder <roland@mxchange.org>
Wed, 26 Aug 2015 13:33:01 +0000 (15:33 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 26 Aug 2015 13:33:01 +0000 (15:33 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/jcore/BaseFrameworkSystem.java
src/org/mxchange/jcore/criteria/BaseCriteria.java
src/org/mxchange/jcore/criteria/Criteria.java
src/org/mxchange/jcore/criteria/logical/and/AndLogicalMatcher.java [new file with mode: 0644]
src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java
src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java
src/org/mxchange/jcore/factory/database/backend/BackendFactory.java

index 047bcadb7340100988203b1f3435daad0b62e23b..3bb76beab8424eec61d837a7019143b856376a43 100644 (file)
@@ -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)) {
index 469404b9578ff62d590b5ee1b6ba584e04270c0d..0467781d4291e5c52ab0ba59a328da4bb9db80d8 100644 (file)
@@ -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;
        }
 
index c6f139759d1ee854db9982f566a8f3ef34243f0d..4af20fb3d5cc9f4059bff1b345a5cdadeba5d814 100644 (file)
@@ -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<Map.Entry<String, Object>> 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 (file)
index 0000000..93d6297
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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<Map.Entry<String, Object>> entrySet, final Map<String, Boolean> 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<String, Object> 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<String, Boolean> 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;
+       }
+       
+}
index e1886ddf0c19d5da9648314e009c2457f48d94ab..ae25c6b8ad74ab3803b1c6ce3bc7c2afc041b67b 100644 (file)
@@ -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);
                }
index 0c3a63235dd6557c6c5f0ac217b4dd60698802ad..598d5750596eaa7fa244e34cf2438e52ac3288c9 100644 (file)
@@ -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
index 5e161662355dca3b439f91ec6a1716e7b88aa59e..65e216a9b254a831cefc3bd4d77fc66cf8633e8f 100644 (file)
@@ -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
                }