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
* @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);
}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
// 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);
}