From 791a1a15cde83dd41b009acdab3a36fe4648e0cf Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Mon, 25 Jul 2022 13:46:59 +0200 Subject: [PATCH 01/13] semantic filtering specifics --- .../META-INF/MANIFEST.MF | 3 +- .../cau/cs/kieler/klighd/KlighdOptions.java | 4 + .../klighd/filtering/AndConnective.java | 74 ++++++++++ .../klighd/filtering/BinaryConnective.java | 67 ++++++++++ .../filtering/GreaterThanConnective.java | 67 ++++++++++ .../klighd/filtering/IfThenConnective.java | 73 ++++++++++ .../filtering/IfThenElseConnective.java | 82 ++++++++++++ .../klighd/filtering/LessThanConnective.java | 67 ++++++++++ .../filtering/LogicEqualConnective.java | 73 ++++++++++ .../klighd/filtering/NegationConnective.java | 69 ++++++++++ .../filtering/NumericEqualConnective.java | 67 ++++++++++ .../kieler/klighd/filtering/OrConnective.java | 74 ++++++++++ .../klighd/filtering/SemanticFilterRule.java | 86 ++++++++++++ .../filtering/SemanticFilterRuleUtil.java | 126 ++++++++++++++++++ .../klighd/filtering/SemanticFilterTag.java | 103 ++++++++++++++ .../klighd/filtering/TernaryConnective.java | 67 ++++++++++ .../klighd/filtering/UnaryConnective.java | 67 ++++++++++ 17 files changed, 1168 insertions(+), 1 deletion(-) create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/AndConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/BinaryConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IfThenConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IfThenElseConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LogicEqualConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NegationConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/OrConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRule.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRuleUtil.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterTag.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/TernaryConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/UnaryConnective.java diff --git a/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF b/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF index 9995c36b2..273c125bc 100644 --- a/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF +++ b/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: KIELER Lightweight Diagrams (KLighD) Bundle-SymbolicName: de.cau.cs.kieler.klighd;singleton:=true -Bundle-Version: 2.2.1.qualifier +Bundle-Version: 2.1.1.qualifier Bundle-Vendor: Kiel University Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: de.cau.cs.kieler.klighd.kgraph, @@ -21,6 +21,7 @@ Bundle-ActivationPolicy: lazy Bundle-Activator: de.cau.cs.kieler.klighd.KlighdPlugin Export-Package: de.cau.cs.kieler.klighd, de.cau.cs.kieler.klighd.actions, + de.cau.cs.kieler.klighd.filtering, de.cau.cs.kieler.klighd.internal;x-friends:="de.cau.cs.kieler.klighd.piccolo,de.cau.cs.kieler.klighd.ui,de.cau.cs.kieler.klighd.lsp", de.cau.cs.kieler.klighd.internal.macrolayout;x-friends:="de.cau.cs.kieler.klighd.ui,de.cau.cs.kieler.klighd.piccolo", de.cau.cs.kieler.klighd.internal.preferences;x-internal:=true, diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/KlighdOptions.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/KlighdOptions.java index fead2f59f..9cbb1766e 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/KlighdOptions.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/KlighdOptions.java @@ -16,7 +16,9 @@ */ package de.cau.cs.kieler.klighd; +import java.util.Collection; import java.util.EnumSet; +import java.util.List; import org.eclipse.elk.core.data.ILayoutMetaDataProvider; import org.eclipse.elk.core.data.LayoutOptionData; @@ -24,6 +26,8 @@ import org.eclipse.elk.graph.properties.IProperty; import org.eclipse.elk.graph.properties.Property; +import de.cau.cs.kieler.klighd.filtering.SemanticFilterRule; +import de.cau.cs.kieler.klighd.filtering.SemanticFilterTag; import de.cau.cs.kieler.klighd.labels.management.LabelManagementResult; import de.cau.cs.kieler.klighd.util.ExpansionAwareLayoutOption; diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/AndConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/AndConnective.java new file mode 100644 index 000000000..d3722337b --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/AndConnective.java @@ -0,0 +1,74 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * An And Connective takes two rules R1 and R2 and evaluates to true + * iff + * R1 and R2 evaluate to true. + * + * @author mka + * @author tik + * + */ +public class AndConnective extends BinaryConnective { + protected static final String NAME = "AND"; + + /** + * Constructor for unnamed rule. + * @param leftOperand left operand + * @param rightOperand right operand + */ + public AndConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + */ + public AndConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param leftOperand left operand + * @param rightOperand right operand + * @param ruleName rule name + */ + public AndConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public AndConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/BinaryConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/BinaryConnective.java new file mode 100644 index 000000000..c16a4f752 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/BinaryConnective.java @@ -0,0 +1,67 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A binary connective C takes two filter rules R1 and R2 as operands and creates the new rule R1 C R2. + * @author mka + * @author tik + * + */ +public abstract class BinaryConnective extends SemanticFilterRule { + + protected String name; + protected SemanticFilterRule leftOperand; + protected SemanticFilterRule rightOperand; + + /** + * {@inheritDoc} + */ + public BinaryConnective() { + + } + + /** + * {@inheritDoc} + */ + public BinaryConnective(Boolean defaultValue) { + super(defaultValue); + } + + /** + * {@inheritDoc} + */ + public BinaryConnective(String ruleName) { + super(ruleName); + } + + /** + * {@inheritDoc} + */ + public BinaryConnective(Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + } + + /** + * Returns a string representation of the rule of the form 'C(R1, R2)'. + * @return the rule string + */ + public String toString() { + return name + "(" + leftOperand + ", " + rightOperand + ")"; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java new file mode 100644 index 000000000..80b06338d --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java @@ -0,0 +1,67 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A GreaterThan Connective takes one rule R and evaluates to true + * iff + * R.num > correspondingTag.num. + * @author tik + * + */ +public class GreaterThanConnective extends UnaryConnective { + protected static final String NAME = "GREATERTHAN"; + + /** + * Constructor for unnamed rule. + * @param operand the operand + */ + public GreaterThanConnective(SemanticFilterTag operand) { + this(operand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param operand the operand + * @param defaultValue the default value + */ + public GreaterThanConnective(SemanticFilterTag operand, Boolean defaultValue) { + this(operand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param operand the operand + * @param ruleName rule name + */ + public GreaterThanConnective(SemanticFilterTag operand, String ruleName) { + this(operand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param operand the operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public GreaterThanConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.operand = operand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IfThenConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IfThenConnective.java new file mode 100644 index 000000000..3fa3da6f6 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IfThenConnective.java @@ -0,0 +1,73 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * An IfThen Connective takes two rules R1 and R2 and evaluates to true + * iff + * R1 evaluates to false or R2 evaluates to true. + * + * @author tik + * + */ +public class IfThenConnective extends BinaryConnective { + protected static final String NAME = "IFTHEN"; + + /** + * Constructor for unnamed rule. + * @param leftOperand left operand + * @param rightOperand right operand + */ + public IfThenConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + */ + public IfThenConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param leftOperand left operand + * @param rightOperand right operand + * @param ruleName rule name + */ + public IfThenConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public IfThenConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IfThenElseConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IfThenElseConnective.java new file mode 100644 index 000000000..2174016fa --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IfThenElseConnective.java @@ -0,0 +1,82 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * An IfThenElse Connective takes three rules R1, R2 and R3 and evaluates to true + * iff + * R1 and R2 evaluate to true or R1 evaluates to false and R3 evaluates to true. + * + * @author tik + * + */ +public class IfThenElseConnective extends TernaryConnective { + protected static final String NAME = "IFTHENELSE"; + + /** + * Constructor for unnamed rule. + * @param firstOperand first operand + * @param secondOperand second operand + * @param thirdOperand third operand + */ + public IfThenElseConnective(SemanticFilterRule firstOperand, SemanticFilterRule secondOperand, + SemanticFilterRule thirdOperand) { + this(firstOperand, secondOperand, thirdOperand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param firstOperand first operand + * @param secondOperand second operand + * @param thirdOperand third operand + * @param defaultValue the default value + */ + public IfThenElseConnective(SemanticFilterRule firstOperand, SemanticFilterRule secondOperand, + SemanticFilterRule thirdOperand, Boolean defaultValue) { + this(firstOperand, secondOperand, thirdOperand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param firstOperand first operand + * @param secondOperand second operand + * @param thirdOperand third operand + * @param ruleName rule name + */ + public IfThenElseConnective(SemanticFilterRule firstOperand, SemanticFilterRule secondOperand, + SemanticFilterRule thirdOperand, String ruleName) { + this(firstOperand, secondOperand, thirdOperand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param firstOperand first operand + * @param secondOperand second operand + * @param thirdOperand third operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public IfThenElseConnective(SemanticFilterRule firstOperand, SemanticFilterRule secondOperand, + SemanticFilterRule thirdOperand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.firstOperand = firstOperand; + this.secondOperand = secondOperand; + this.thirdOperand = thirdOperand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java new file mode 100644 index 000000000..49a7a0184 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java @@ -0,0 +1,67 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A LessThan Connective takes one rule R and evaluates to true + * iff + * R.num < correspondingTag.num. + * @author tik + * + */ +public class LessThanConnective extends UnaryConnective { + protected static final String NAME = "LESSTHAN"; + + /** + * Constructor for unnamed rule. + * @param operand the operand + */ + public LessThanConnective(SemanticFilterTag operand) { + this(operand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param operand the operand + * @param defaultValue the default value + */ + public LessThanConnective(SemanticFilterTag operand, Boolean defaultValue) { + this(operand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param operand the operand + * @param ruleName rule name + */ + public LessThanConnective(SemanticFilterTag operand, String ruleName) { + this(operand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param operand the operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public LessThanConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.operand = operand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LogicEqualConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LogicEqualConnective.java new file mode 100644 index 000000000..d238a246b --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LogicEqualConnective.java @@ -0,0 +1,73 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * An Equal Connective takes two rules R1 and R2 and evaluates to true + * iff + * R1 and R2 evaluate to true or R1 and R2 evaluate to false. + * + * @author tik + * + */ +public class LogicEqualConnective extends BinaryConnective { + protected static final String NAME = "LOGICEQUAL"; + + /** + * Constructor for unnamed rule. + * @param leftOperand left operand + * @param rightOperand right operand + */ + public LogicEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + */ + public LogicEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param leftOperand left operand + * @param rightOperand right operand + * @param ruleName rule name + */ + public LogicEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public LogicEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NegationConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NegationConnective.java new file mode 100644 index 000000000..e144b2145 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NegationConnective.java @@ -0,0 +1,69 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A Not Connective takes a rule R and evaluates to true + * iff + * R evaluates to false. + * + * @author mka + * @author tik + * + */ +public class NegationConnective extends UnaryConnective { + protected static final String NAME = "NOT"; + + /** + * Constructor for unnamed rule. + * @param operand the operand + */ + public NegationConnective(SemanticFilterRule operand) { + this(operand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param operand the operand + * @param defaultValue the default value + */ + public NegationConnective(SemanticFilterRule operand, Boolean defaultValue) { + this(operand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param operand the operand + * @param ruleName rule name + */ + public NegationConnective(SemanticFilterRule operand, String ruleName) { + this(operand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param operand the operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public NegationConnective(SemanticFilterRule operand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.operand = operand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java new file mode 100644 index 000000000..707e555be --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java @@ -0,0 +1,67 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A NumericEqual Connective takes one rule R and evaluates to true + * iff + * R.num == correspondingTag.num. + * @author tik + * + */ +public class NumericEqualConnective extends UnaryConnective { + protected static final String NAME = "NUMERICEQUAL"; + + /** + * Constructor for unnamed rule. + * @param operand the operand + */ + public NumericEqualConnective(SemanticFilterTag operand) { + this(operand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param operand the operand + * @param defaultValue the default value + */ + public NumericEqualConnective(SemanticFilterTag operand, Boolean defaultValue) { + this(operand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param operand the operand + * @param ruleName rule name + */ + public NumericEqualConnective(SemanticFilterTag operand, String ruleName) { + this(operand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param operand the operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public NumericEqualConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.operand = operand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/OrConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/OrConnective.java new file mode 100644 index 000000000..dba9a1b43 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/OrConnective.java @@ -0,0 +1,74 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * An Or Connective takes two rules R1 and R2 and evaluates to true + * iff + * R1 or R2 evaluate to true. + * + * @author mka + * @author tik + * + */ +public class OrConnective extends BinaryConnective { + protected static final String NAME = "OR"; + + /** + * Constructor for unnamed rule. + * @param leftOperand left operand + * @param rightOperand right operand + */ + public OrConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + */ + public OrConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param leftOperand left operand + * @param rightOperand right operand + * @param ruleName rule name + */ + public OrConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public OrConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRule.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRule.java new file mode 100644 index 000000000..fd4d29a81 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRule.java @@ -0,0 +1,86 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * Semantic filter rules describe a filter that can be evaluated to include only elements tagged with certain tags. + * The rules are constructed through the combination of filter rules with logical connectives. + * + * @author mka + * @author tik + * + */ +public abstract class SemanticFilterRule { + + /** The rule name is used to identify rules and distinguish them from one another. */ + private String ruleName; + /** The default value is used to indicate whether the semantic filter should be on or off by default. */ + private Boolean defaultValue; + + /** + * Basic constructor + */ + public SemanticFilterRule() { + this(null, null); + } + + /** + * Constructor that takes a default value. + * The default value is used to indicate whether the semantic filter should be on or off by default. + * @param defaultValue the default value + */ + public SemanticFilterRule(Boolean defaultValue) { + this(defaultValue, null); + } + + /** + * Constructor that takes a rule name. + * The rule name is used to identify rules and distinguish them from one another. + * @param ruleName the rule name + */ + public SemanticFilterRule(String ruleName) { + this(null, ruleName); + } + + /** + * Constructor that takes a rule name and default value. + * The default value is used to indicate whether the semantic filter should be on or off by default. + * The rule name is used to identify rules and distinguish them from one another. + * @param defaultValue the default value + * @param ruleName the rule name + */ + public SemanticFilterRule(Boolean defaultValue, String ruleName) { + this.defaultValue = defaultValue; + this.ruleName = ruleName; + } + + /** + * Returns the rule name. + * @return the rule name + */ + public String getRuleName() { + return this.ruleName; + } + + /** + * Returns the default value. + * @return the default value + */ + public boolean getDefaultValue() { + return this.defaultValue; + } +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRuleUtil.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRuleUtil.java new file mode 100644 index 000000000..c80697521 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRuleUtil.java @@ -0,0 +1,126 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * Util for easily getting some rules. + * + * @author tik + * + */ +public abstract class SemanticFilterRuleUtil { + /** An empty tag used to define constants. */ + private static final SemanticFilterTag EMPTY = new SemanticFilterTag(""); + /** A rule that is always evaluated to false. */ + public static final SemanticFilterRule FALSE = + new AndConnective(EMPTY, new NegationConnective(EMPTY)); + /** A rule that is always evaluated to true. */ + public static final SemanticFilterRule TRUE = + new OrConnective(EMPTY, new NegationConnective(EMPTY)); + + /** + * Constructs an unnamed rule with all operands connected via OR. If no operands are given, this + * is always false. + * + * @param operands + * The operands. + * @return The SemanticFilterRule. + */ + public static SemanticFilterRule getBigOrConnective(SemanticFilterRule... operands) { + return getBigOrConnective(null, operands); + } + + /** + * Constructs a named rule with all operands connected via OR. If no operands are given, this is + * always false. + * + * @param ruleName + * The rule name. + * @param operands + * The operands. + * @return The SemanticFilterRule. + */ + public static SemanticFilterRule getBigOrConnective(String ruleName, + SemanticFilterRule... operands) { + if (operands.length <= 0) { + // No rules, automatically evaluate to false + return FALSE; + } else if (operands.length <= 1) { + // Just one rule, true iff rule is true + // Add ruleName instead of just using first operand twice to avoid double evaluation + return addRuleName(ruleName, operands[0]); + } + OrConnective bigOr = new OrConnective(operands[0], operands[1], ruleName); + for (int i = 2; i < operands.length; i++) { + bigOr.rightOperand = new OrConnective(bigOr.rightOperand, operands[i]); + } + return bigOr; + } + + /** + * Constructs an unnamed rule with all operands connected via AND. If no operands are given, + * this is always false. + * + * @param operands + * The operands. + * @return The SemanticFilterRule. + */ + public static SemanticFilterRule getBigAndConnective(SemanticFilterRule... operands) { + return getBigAndConnective(null, operands); + } + + /** + * Constructs a named rule with all operands connected via AND. If no operands are given, this + * is always false. + * + * @param ruleName + * The rule name. + * @param operands + * The operands. + * @return The SemanticFilterRule. + */ + public static SemanticFilterRule getBigAndConnective(String ruleName, + SemanticFilterRule... operands) { + if (operands.length <= 0) { + // No rules, automatically evaluate to false + return FALSE; + } else if (operands.length <= 1) { + // Just one rule, true iff rule is true + // Add ruleName instead of just using first operand twice to avoid double evaluation + return addRuleName(ruleName, operands[0]); + } + // Use first operand twice in case of just one rule, e.g. true iff rule is true + AndConnective bigAnd = new AndConnective(operands[0], operands[1], ruleName); + for (int i = 2; i < operands.length; i++) { + bigAnd.rightOperand = new AndConnective(bigAnd.rightOperand, operands[i]); + } + return bigAnd; + } + + /** + * Constructs a new named rule from a given potentially unnamed rule. + * + * @param ruleName + * The rule name. + * @param rule + * The rule. + * @return A named rule. + */ + public static SemanticFilterRule addRuleName(String ruleName, SemanticFilterRule rule) { + return new NegationConnective(new NegationConnective(rule), ruleName); + } +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterTag.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterTag.java new file mode 100644 index 000000000..dec5abec1 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterTag.java @@ -0,0 +1,103 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * Semantic filter tags serve both as tags on graph elements to provide semantic meaning in a diagram that can not + * be conveyed otherwise and as an atomic filter rule that can be combined with other rules to construct more complex + * rules. + * + * When using a tag in numeric expressions, keep in mind that not defining the number results in it defaulting to 0. + * It's best practice to always set the number explicitly, if one can be assigned. + * + * @author mka + * @author tik + * + */ +public class SemanticFilterTag extends SemanticFilterRule { + + private String tag; + /** If unset, defaults to 0. */ + private Double num; + + /** + * Constructor for tag. + * @param tag string identifier + */ + public SemanticFilterTag(String tag) { + this.tag = tag; + } + + /** + * Constructor for tag with a number. + * @param tag string identifier + * @param num the number + */ + public SemanticFilterTag(String tag, Double num) { + this.tag = tag; + this.num = num; + } + + /** + * Constructor for tag as a semantic filter rule. + * Here, an additional rule name is required as this is later used to differentiate between multiple rules. + * @param tag string identifier of the tag the rule applies to + * @param ruleName string identifier of the rule itself, can be anything + */ + public SemanticFilterTag(String tag, String ruleName) { + super(ruleName); + this.tag = tag; + } + + /** + * Constructor for tag with a number as a semantic filter rule. + * Here, an additional rule name is required as this is later used to differentiate between multiple rules. + * @param tag string identifier of the tag the rule applies to + * @param num the number + * @param ruleName string identifier of the rule itself, can be anything + */ + public SemanticFilterTag(String tag, Double num, String ruleName) { + super(ruleName); + this.tag = tag; + this.num = num; + } + + /** + * Returns the tag. + * @return the tag + */ + public String getTag() { + return this.tag; + } + + /** + * Returns the num. + * @return the num + */ + public Double getNum() { + return this.num; + } + + /** + * Returns a string representation of the rule/tag. + * @return the rule string + */ + public String toString() { + return "(tag=" + this.tag + ", num=" + this.num + ")"; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/TernaryConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/TernaryConnective.java new file mode 100644 index 000000000..52b0ad374 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/TernaryConnective.java @@ -0,0 +1,67 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A ternary connective C takes three filter rules R1, R2 and R3 as operands and creates the new rule C R1 R2 R3. + * + * @author tik + * + */ +public abstract class TernaryConnective extends SemanticFilterRule { + + protected String name; + protected SemanticFilterRule firstOperand; + protected SemanticFilterRule secondOperand; + protected SemanticFilterRule thirdOperand; + + /** + * {@inheritDoc} + */ + public TernaryConnective() { + + } + + /** + * {@inheritDoc} + */ + public TernaryConnective(Boolean defaultValue) { + super(defaultValue); + } + + /** + * {@inheritDoc} + */ + public TernaryConnective(String ruleName) { + super(ruleName); + } + + /** + * {@inheritDoc} + */ + public TernaryConnective(Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + } + + /** + * Returns a string representation of the rule of the form 'C(R1, R2, R3)'. + * @return the rule string + */ + public String toString() { + return name + "(" + firstOperand + ", " + secondOperand + ", " + thirdOperand + ")"; + } +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/UnaryConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/UnaryConnective.java new file mode 100644 index 000000000..785d7a8fb --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/UnaryConnective.java @@ -0,0 +1,67 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * An unary connective C takes a single filter rule R as an operand and creates the new rule C(R). + * + * @author mka + * @author tik + * + */ +public abstract class UnaryConnective extends SemanticFilterRule { + + protected String name; + protected SemanticFilterRule operand; + + /** + * {@inheritDoc} + */ + public UnaryConnective() { + + } + + /** + * {@inheritDoc} + */ + public UnaryConnective(Boolean defaultValue) { + super(defaultValue); + } + + /** + * {@inheritDoc} + */ + public UnaryConnective(String ruleName) { + super(ruleName); + } + + /** + * {@inheritDoc} + */ + public UnaryConnective(Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + } + + /** + * Returns a string representation of the rule in the form 'C(R)'. + * @return the rule string + */ + public String toString() { + return name + "(" + this.operand + ")"; + } + +} From d522bbc9937d9a2931863f6762ea3510b4264832 Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Tue, 26 Jul 2022 11:03:13 +0200 Subject: [PATCH 02/13] add utility connectives and fix bundle version --- .../META-INF/MANIFEST.MF | 2 +- .../klighd/filtering/FalseConnective.java | 62 ++++++++++++++++ .../klighd/filtering/IdentityConnective.java | 71 +++++++++++++++++++ .../klighd/filtering/NullaryConnective.java | 63 ++++++++++++++++ .../filtering/SemanticFilterRuleUtil.java | 16 ++--- .../klighd/filtering/TrueConnective.java | 62 ++++++++++++++++ 6 files changed, 263 insertions(+), 13 deletions(-) create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/FalseConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IdentityConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NullaryConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/TrueConnective.java diff --git a/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF b/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF index 273c125bc..2a48d88d7 100644 --- a/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF +++ b/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: KIELER Lightweight Diagrams (KLighD) Bundle-SymbolicName: de.cau.cs.kieler.klighd;singleton:=true -Bundle-Version: 2.1.1.qualifier +Bundle-Version: 2.2.1.qualifier Bundle-Vendor: Kiel University Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: de.cau.cs.kieler.klighd.kgraph, diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/FalseConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/FalseConnective.java new file mode 100644 index 000000000..c2daf10b5 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/FalseConnective.java @@ -0,0 +1,62 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A False Connective always evaluates to false. + * + * @author mka + * + */ +public class FalseConnective extends NullaryConnective { + + protected static final String NAME = "FALSE"; + + /** + * Constructor for unnamed rule. + */ + public FalseConnective() { + this(null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param defaultValue + */ + public FalseConnective(Boolean defaultValue) { + this(defaultValue, null); + } + + /** + * Constructor for named rule. + * @param ruleName + */ + public FalseConnective(String ruleName) { + this(null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param defaultValue + * @param ruleName + */ + public FalseConnective(Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IdentityConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IdentityConnective.java new file mode 100644 index 000000000..a025602b6 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/IdentityConnective.java @@ -0,0 +1,71 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * An Identity Connective evaluates its operand. For example ID (R) is equivalent to R. + * + * @author mka + * + */ +public class IdentityConnective extends UnaryConnective { + + protected static final String NAME = "ID"; + + /** + * Constructor for unnamed rule. + * @param leftOperand left operand + * @param rightOperand right operand + */ + public IdentityConnective(SemanticFilterRule operand) { + this(operand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + */ + public IdentityConnective(SemanticFilterRule operand, Boolean defaultValue) { + this(operand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param leftOperand left operand + * @param rightOperand right operand + * @param ruleName rule name + */ + public IdentityConnective(SemanticFilterRule operand, String ruleName) { + this(operand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public IdentityConnective(SemanticFilterRule operand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.operand = operand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NullaryConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NullaryConnective.java new file mode 100644 index 000000000..e2768cd8b --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NullaryConnective.java @@ -0,0 +1,63 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * @author mka + * + */ +public abstract class NullaryConnective extends SemanticFilterRule { + + protected String name; + + /** + * {@inheritDoc} + */ + public NullaryConnective() { + + } + + /** + * {@inheritDoc} + */ + public NullaryConnective(Boolean defaultValue) { + super(defaultValue); + } + + /** + * {@inheritDoc} + */ + public NullaryConnective(String ruleName) { + super(ruleName); + } + + /** + * {@inheritDoc} + */ + public NullaryConnective(Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + } + + /** + * Returns a string representation of the rule in the form 'C(R)'. + * @return the rule string + */ + public String toString() { + return name; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRuleUtil.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRuleUtil.java index c80697521..d119f3b97 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRuleUtil.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterRuleUtil.java @@ -19,18 +19,10 @@ /** * Util for easily getting some rules. * - * @author tik + * @author tik, mka * */ public abstract class SemanticFilterRuleUtil { - /** An empty tag used to define constants. */ - private static final SemanticFilterTag EMPTY = new SemanticFilterTag(""); - /** A rule that is always evaluated to false. */ - public static final SemanticFilterRule FALSE = - new AndConnective(EMPTY, new NegationConnective(EMPTY)); - /** A rule that is always evaluated to true. */ - public static final SemanticFilterRule TRUE = - new OrConnective(EMPTY, new NegationConnective(EMPTY)); /** * Constructs an unnamed rule with all operands connected via OR. If no operands are given, this @@ -58,7 +50,7 @@ public static SemanticFilterRule getBigOrConnective(String ruleName, SemanticFilterRule... operands) { if (operands.length <= 0) { // No rules, automatically evaluate to false - return FALSE; + return new FalseConnective(); } else if (operands.length <= 1) { // Just one rule, true iff rule is true // Add ruleName instead of just using first operand twice to avoid double evaluation @@ -97,7 +89,7 @@ public static SemanticFilterRule getBigAndConnective(String ruleName, SemanticFilterRule... operands) { if (operands.length <= 0) { // No rules, automatically evaluate to false - return FALSE; + return new FalseConnective(); } else if (operands.length <= 1) { // Just one rule, true iff rule is true // Add ruleName instead of just using first operand twice to avoid double evaluation @@ -121,6 +113,6 @@ public static SemanticFilterRule getBigAndConnective(String ruleName, * @return A named rule. */ public static SemanticFilterRule addRuleName(String ruleName, SemanticFilterRule rule) { - return new NegationConnective(new NegationConnective(rule), ruleName); + return new IdentityConnective((rule), ruleName); } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/TrueConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/TrueConnective.java new file mode 100644 index 000000000..e1b7325da --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/TrueConnective.java @@ -0,0 +1,62 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A True Connective always evaluates to true. + * + * @author mka + * + */ +public class TrueConnective extends NullaryConnective { + + protected static final String NAME = "TRUE"; + + /** + * Constructor for unnamed rule. + */ + public TrueConnective() { + this(null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param defaultValue + */ + public TrueConnective(Boolean defaultValue) { + this(defaultValue, null); + } + + /** + * Constructor for named rule. + * @param ruleName + */ + public TrueConnective(String ruleName) { + this(null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param defaultValue + * @param ruleName + */ + public TrueConnective(Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + } + +} From aad71104fdc6e652b0441de3bfb6d905a1228eb2 Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Tue, 26 Jul 2022 14:50:05 +0200 Subject: [PATCH 03/13] add properties api to add filter tags and rules to graphs --- .../kieler/klighd/util/KlighdProperties.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/util/KlighdProperties.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/util/KlighdProperties.java index 09e56a876..c5d018693 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/util/KlighdProperties.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/util/KlighdProperties.java @@ -17,6 +17,8 @@ package de.cau.cs.kieler.klighd.util; import java.awt.Color; +import java.util.ArrayList; +import java.util.List; import org.eclipse.elk.core.math.KVector; import org.eclipse.elk.core.math.Spacing; @@ -26,6 +28,8 @@ import org.eclipse.emf.ecore.EObject; import de.cau.cs.kieler.klighd.KlighdConstants; +import de.cau.cs.kieler.klighd.filtering.SemanticFilterRule; +import de.cau.cs.kieler.klighd.filtering.SemanticFilterTag; import de.cau.cs.kieler.klighd.kgraph.KGraphElement; import de.cau.cs.kieler.klighd.kgraph.KNode; import de.cau.cs.kieler.klighd.krendering.KText; @@ -379,4 +383,20 @@ public static boolean isSelectable(final EObject viewElement) { */ public static final IProperty IS_NODE_TITLE = new Property("klighd.isNodeTitle", false); + + /** + * Property determining an element's semantic filter tags. + */ + public static final IProperty> SEMANTIC_FILTER_TAGS = + new Property>("de.cau.cs.kieler.klighd.semanticFilter.tags", + // ArrayList is cloneable, no problem here + new ArrayList<>()); + + /** + * Property determining an element's semantic filter rules. + * Only relevant for the root. + */ + public static final IProperty> SEMANTIC_FILTER_RULES = + new Property>("de.cau.cs.kieler.klighd.semanticFilter.rules", + new ArrayList<>()); } From 0b1faa8e1e3262d875eada28d8e336c4aa395e1e Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Tue, 26 Jul 2022 15:30:00 +0200 Subject: [PATCH 04/13] add >=, <= and != numeric connectives --- .../filtering/GreaterEqualsConnective.java | 68 ++++++++++++++++++ .../filtering/LessEqualsConnective.java | 69 +++++++++++++++++++ .../filtering/NumericNotEqualConnective.java | 69 +++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java new file mode 100644 index 000000000..0578a14b9 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java @@ -0,0 +1,68 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A GreaterEquals Connective takes one rule R and evaluates to true + * iff + * R.num >= correspondingTag.num. + * + * @author mka + * + */ +public class GreaterEqualsConnective extends UnaryConnective { +protected static final String NAME = "GREATEREQUALS"; + + /** + * Constructor for unnamed rule. + * @param operand the operand + */ + public GreaterEqualsConnective(SemanticFilterTag operand) { + this(operand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param operand the operand + * @param defaultValue the default value + */ + public GreaterEqualsConnective(SemanticFilterTag operand, Boolean defaultValue) { + this(operand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param operand the operand + * @param ruleName rule name + */ + public GreaterEqualsConnective(SemanticFilterTag operand, String ruleName) { + this(operand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param operand the operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public GreaterEqualsConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.operand = operand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java new file mode 100644 index 000000000..80fa8c5ff --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java @@ -0,0 +1,69 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * * A LessEquals Connective takes one rule R and evaluates to true + * iff + * R.num <= correspondingTag.num. + * + * @author mka + * + */ +public class LessEqualsConnective extends UnaryConnective { + +protected static final String NAME = "LESSEQUALS"; + + /** + * Constructor for unnamed rule. + * @param operand the operand + */ + public LessEqualsConnective(SemanticFilterTag operand) { + this(operand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param operand the operand + * @param defaultValue the default value + */ + public LessEqualsConnective(SemanticFilterTag operand, Boolean defaultValue) { + this(operand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param operand the operand + * @param ruleName rule name + */ + public LessEqualsConnective(SemanticFilterTag operand, String ruleName) { + this(operand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param operand the operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public LessEqualsConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.operand = operand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java new file mode 100644 index 000000000..204afe7bc --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java @@ -0,0 +1,69 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * * A NumericNotEqual Connective takes one rule R and evaluates to true + * iff + * R.num != correspondingTag.num. + * + * @author mka + * + */ +public class NumericNotEqualConnective extends UnaryConnective { + +protected static final String NAME = "NUMERICNOTEQUAL"; + + /** + * Constructor for unnamed rule. + * @param operand the operand + */ + public NumericNotEqualConnective(SemanticFilterTag operand) { + this(operand, null, null); + } + + /** + * Constructor for unnamed rule with default value. + * @param operand the operand + * @param defaultValue the default value + */ + public NumericNotEqualConnective(SemanticFilterTag operand, Boolean defaultValue) { + this(operand, defaultValue, null); + } + + /** + * Constructor for named rule. + * @param operand the operand + * @param ruleName rule name + */ + public NumericNotEqualConnective(SemanticFilterTag operand, String ruleName) { + this(operand, null, ruleName); + } + + /** + * Constructor for named rule with default value. + * @param operand the operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public NumericNotEqualConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.operand = operand; + } + +} From b9f7fc84d0334ed2d7173506de8d1274d9473e42 Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Fri, 29 Jul 2022 13:05:54 +0200 Subject: [PATCH 05/13] add numeric connectives Signed-off-by: Max Kasperowski --- .../filtering/GreaterEqualsConnective.java | 10 ++-- .../filtering/GreaterThanConnective.java | 10 ++-- .../filtering/LessEqualsConnective.java | 10 ++-- .../klighd/filtering/LessThanConnective.java | 10 ++-- .../filtering/NumericDividesConnective.java | 46 +++++++++++++++++++ .../filtering/NumericEqualConnective.java | 10 ++-- .../filtering/NumericMinusConnective.java | 46 +++++++++++++++++++ .../filtering/NumericNotEqualConnective.java | 10 ++-- .../filtering/NumericPlusConnective.java | 46 +++++++++++++++++++ .../klighd/filtering/NumericResult.java | 28 +++++++++++ .../filtering/NumericTimesConnective.java | 46 +++++++++++++++++++ .../klighd/filtering/SemanticFilterTag.java | 2 +- 12 files changed, 243 insertions(+), 31 deletions(-) create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDividesConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMinusConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericPlusConnective.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericResult.java create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericTimesConnective.java diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java index 0578a14b9..aab24ac28 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java @@ -31,7 +31,7 @@ public class GreaterEqualsConnective extends UnaryConnective { * Constructor for unnamed rule. * @param operand the operand */ - public GreaterEqualsConnective(SemanticFilterTag operand) { + public GreaterEqualsConnective(NumericResult operand) { this(operand, null, null); } @@ -40,7 +40,7 @@ public GreaterEqualsConnective(SemanticFilterTag operand) { * @param operand the operand * @param defaultValue the default value */ - public GreaterEqualsConnective(SemanticFilterTag operand, Boolean defaultValue) { + public GreaterEqualsConnective(NumericResult operand, Boolean defaultValue) { this(operand, defaultValue, null); } @@ -49,7 +49,7 @@ public GreaterEqualsConnective(SemanticFilterTag operand, Boolean defaultValue) * @param operand the operand * @param ruleName rule name */ - public GreaterEqualsConnective(SemanticFilterTag operand, String ruleName) { + public GreaterEqualsConnective(NumericResult operand, String ruleName) { this(operand, null, ruleName); } @@ -59,10 +59,10 @@ public GreaterEqualsConnective(SemanticFilterTag operand, String ruleName) { * @param defaultValue the default value * @param ruleName rule name */ - public GreaterEqualsConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + public GreaterEqualsConnective(NumericResult operand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.operand = operand; + this.operand = (SemanticFilterRule) operand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java index 80b06338d..b73caa03c 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java @@ -30,7 +30,7 @@ public class GreaterThanConnective extends UnaryConnective { * Constructor for unnamed rule. * @param operand the operand */ - public GreaterThanConnective(SemanticFilterTag operand) { + public GreaterThanConnective(NumericResult operand) { this(operand, null, null); } @@ -39,7 +39,7 @@ public GreaterThanConnective(SemanticFilterTag operand) { * @param operand the operand * @param defaultValue the default value */ - public GreaterThanConnective(SemanticFilterTag operand, Boolean defaultValue) { + public GreaterThanConnective(NumericResult operand, Boolean defaultValue) { this(operand, defaultValue, null); } @@ -48,7 +48,7 @@ public GreaterThanConnective(SemanticFilterTag operand, Boolean defaultValue) { * @param operand the operand * @param ruleName rule name */ - public GreaterThanConnective(SemanticFilterTag operand, String ruleName) { + public GreaterThanConnective(NumericResult operand, String ruleName) { this(operand, null, ruleName); } @@ -58,10 +58,10 @@ public GreaterThanConnective(SemanticFilterTag operand, String ruleName) { * @param defaultValue the default value * @param ruleName rule name */ - public GreaterThanConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + public GreaterThanConnective(NumericResult operand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.operand = operand; + this.operand = (SemanticFilterRule) operand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java index 80fa8c5ff..788750c05 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java @@ -32,7 +32,7 @@ public class LessEqualsConnective extends UnaryConnective { * Constructor for unnamed rule. * @param operand the operand */ - public LessEqualsConnective(SemanticFilterTag operand) { + public LessEqualsConnective(NumericResult operand) { this(operand, null, null); } @@ -41,7 +41,7 @@ public LessEqualsConnective(SemanticFilterTag operand) { * @param operand the operand * @param defaultValue the default value */ - public LessEqualsConnective(SemanticFilterTag operand, Boolean defaultValue) { + public LessEqualsConnective(NumericResult operand, Boolean defaultValue) { this(operand, defaultValue, null); } @@ -50,7 +50,7 @@ public LessEqualsConnective(SemanticFilterTag operand, Boolean defaultValue) { * @param operand the operand * @param ruleName rule name */ - public LessEqualsConnective(SemanticFilterTag operand, String ruleName) { + public LessEqualsConnective(NumericResult operand, String ruleName) { this(operand, null, ruleName); } @@ -60,10 +60,10 @@ public LessEqualsConnective(SemanticFilterTag operand, String ruleName) { * @param defaultValue the default value * @param ruleName rule name */ - public LessEqualsConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + public LessEqualsConnective(NumericResult operand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.operand = operand; + this.operand = (SemanticFilterRule) operand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java index 49a7a0184..7904aea60 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java @@ -30,7 +30,7 @@ public class LessThanConnective extends UnaryConnective { * Constructor for unnamed rule. * @param operand the operand */ - public LessThanConnective(SemanticFilterTag operand) { + public LessThanConnective(NumericResult operand) { this(operand, null, null); } @@ -39,7 +39,7 @@ public LessThanConnective(SemanticFilterTag operand) { * @param operand the operand * @param defaultValue the default value */ - public LessThanConnective(SemanticFilterTag operand, Boolean defaultValue) { + public LessThanConnective(NumericResult operand, Boolean defaultValue) { this(operand, defaultValue, null); } @@ -48,7 +48,7 @@ public LessThanConnective(SemanticFilterTag operand, Boolean defaultValue) { * @param operand the operand * @param ruleName rule name */ - public LessThanConnective(SemanticFilterTag operand, String ruleName) { + public LessThanConnective(NumericResult operand, String ruleName) { this(operand, null, ruleName); } @@ -58,10 +58,10 @@ public LessThanConnective(SemanticFilterTag operand, String ruleName) { * @param defaultValue the default value * @param ruleName rule name */ - public LessThanConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + public LessThanConnective(NumericResult operand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.operand = operand; + this.operand = (SemanticFilterRule) operand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDividesConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDividesConnective.java new file mode 100644 index 000000000..514aae416 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDividesConnective.java @@ -0,0 +1,46 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A Numeric Divides Connective takes two numeric operands and evaluates + * to their quotient. + * + * Operands must implement {@link NumericResult} and be a {@link SemanticFilterTag}. This connective is an internal + * connective and should never be treated as a rule and thus does not need a name. + * + * @author mka + * + */ +public class NumericDividesConnective extends BinaryConnective implements NumericResult { + protected static final String NAME = "NUMERICDIVIDES"; + + /** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public NumericDividesConnective(NumericResult leftOperand, NumericResult rightOperand) { + super(); + this.name = NAME; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java index 707e555be..4b6a16cfc 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java @@ -30,7 +30,7 @@ public class NumericEqualConnective extends UnaryConnective { * Constructor for unnamed rule. * @param operand the operand */ - public NumericEqualConnective(SemanticFilterTag operand) { + public NumericEqualConnective(NumericResult operand) { this(operand, null, null); } @@ -39,7 +39,7 @@ public NumericEqualConnective(SemanticFilterTag operand) { * @param operand the operand * @param defaultValue the default value */ - public NumericEqualConnective(SemanticFilterTag operand, Boolean defaultValue) { + public NumericEqualConnective(NumericResult operand, Boolean defaultValue) { this(operand, defaultValue, null); } @@ -48,7 +48,7 @@ public NumericEqualConnective(SemanticFilterTag operand, Boolean defaultValue) { * @param operand the operand * @param ruleName rule name */ - public NumericEqualConnective(SemanticFilterTag operand, String ruleName) { + public NumericEqualConnective(NumericResult operand, String ruleName) { this(operand, null, ruleName); } @@ -58,10 +58,10 @@ public NumericEqualConnective(SemanticFilterTag operand, String ruleName) { * @param defaultValue the default value * @param ruleName rule name */ - public NumericEqualConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + public NumericEqualConnective(NumericResult operand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.operand = operand; + this.operand = (SemanticFilterRule) operand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMinusConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMinusConnective.java new file mode 100644 index 000000000..df875cc27 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMinusConnective.java @@ -0,0 +1,46 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A Numeric Minus Connective takes two numeric operands and evaluates + * to their difference. + * + * Operands must implement {@link NumericResult} and be a {@link SemanticFilterTag}. This connective is an internal + * connective and should never be treated as a rule and thus does not need a name. + * + * @author mka + * + */ +public class NumericMinusConnective extends BinaryConnective implements NumericResult { + protected static final String NAME = "NUMERICMINUS"; + + /** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public NumericMinusConnective(NumericResult leftOperand, NumericResult rightOperand) { + super(); + this.name = NAME; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java index 204afe7bc..513670374 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java @@ -32,7 +32,7 @@ public class NumericNotEqualConnective extends UnaryConnective { * Constructor for unnamed rule. * @param operand the operand */ - public NumericNotEqualConnective(SemanticFilterTag operand) { + public NumericNotEqualConnective(NumericResult operand) { this(operand, null, null); } @@ -41,7 +41,7 @@ public NumericNotEqualConnective(SemanticFilterTag operand) { * @param operand the operand * @param defaultValue the default value */ - public NumericNotEqualConnective(SemanticFilterTag operand, Boolean defaultValue) { + public NumericNotEqualConnective(NumericResult operand, Boolean defaultValue) { this(operand, defaultValue, null); } @@ -50,7 +50,7 @@ public NumericNotEqualConnective(SemanticFilterTag operand, Boolean defaultValue * @param operand the operand * @param ruleName rule name */ - public NumericNotEqualConnective(SemanticFilterTag operand, String ruleName) { + public NumericNotEqualConnective(NumericResult operand, String ruleName) { this(operand, null, ruleName); } @@ -60,10 +60,10 @@ public NumericNotEqualConnective(SemanticFilterTag operand, String ruleName) { * @param defaultValue the default value * @param ruleName rule name */ - public NumericNotEqualConnective(SemanticFilterTag operand, Boolean defaultValue, String ruleName) { + public NumericNotEqualConnective(NumericResult operand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.operand = operand; + this.operand = (SemanticFilterRule) operand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericPlusConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericPlusConnective.java new file mode 100644 index 000000000..4fe6f4092 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericPlusConnective.java @@ -0,0 +1,46 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A Numeric Plus Connective takes two numeric operands and evaluates + * to their sum. + * + * Operands must implement {@link NumericResult} and be a {@link SemanticFilterTag}. This connective is an internal + * connective and should never be treated as a rule and thus does not need a name. + * + * @author mka + * + */ +public class NumericPlusConnective extends BinaryConnective implements NumericResult { + protected static final String NAME = "NUMERICPLUS"; + + /** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public NumericPlusConnective(NumericResult leftOperand, NumericResult rightOperand) { + super(); + this.name = NAME; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericResult.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericResult.java new file mode 100644 index 000000000..9c06f47b2 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericResult.java @@ -0,0 +1,28 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * Identifies rules that return a numeric result. + * + * @author mka + * + */ +public interface NumericResult { + + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericTimesConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericTimesConnective.java new file mode 100644 index 000000000..87924264e --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericTimesConnective.java @@ -0,0 +1,46 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * A Numeric Times Connective takes two numeric operands and evaluates + * to their product. + * + * Operands must implement {@link NumericResult} and be a {@link SemanticFilterTag}. This connective is an internal + * connective and should never be treated as a rule and thus does not need a name. + * + * @author mka + * + */ +public class NumericTimesConnective extends BinaryConnective implements NumericResult { + protected static final String NAME = "NUMERICTIMES"; + + /** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ + public NumericTimesConnective(NumericResult leftOperand, NumericResult rightOperand) { + super(); + this.name = NAME; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; + } + +} diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterTag.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterTag.java index dec5abec1..7cb48c6a8 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterTag.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/SemanticFilterTag.java @@ -28,7 +28,7 @@ * @author tik * */ -public class SemanticFilterTag extends SemanticFilterRule { +public class SemanticFilterTag extends SemanticFilterRule implements NumericResult { private String tag; /** If unset, defaults to 0. */ From ac1af70200f28e50b7f723aa0018c28fe275d767 Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Fri, 29 Jul 2022 13:08:14 +0200 Subject: [PATCH 06/13] organize imports Signed-off-by: Max Kasperowski --- .../src/de/cau/cs/kieler/klighd/KlighdOptions.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/KlighdOptions.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/KlighdOptions.java index 9cbb1766e..fead2f59f 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/KlighdOptions.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/KlighdOptions.java @@ -16,9 +16,7 @@ */ package de.cau.cs.kieler.klighd; -import java.util.Collection; import java.util.EnumSet; -import java.util.List; import org.eclipse.elk.core.data.ILayoutMetaDataProvider; import org.eclipse.elk.core.data.LayoutOptionData; @@ -26,8 +24,6 @@ import org.eclipse.elk.graph.properties.IProperty; import org.eclipse.elk.graph.properties.Property; -import de.cau.cs.kieler.klighd.filtering.SemanticFilterRule; -import de.cau.cs.kieler.klighd.filtering.SemanticFilterTag; import de.cau.cs.kieler.klighd.labels.management.LabelManagementResult; import de.cau.cs.kieler.klighd.util.ExpansionAwareLayoutOption; From 5853dc5bdad85b2c032f80180c2223e753ed8ff3 Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Fri, 29 Jul 2022 15:30:50 +0200 Subject: [PATCH 07/13] rename numeric connectives Signed-off-by: Max Kasperowski --- ...PlusConnective.java => NumericAdditionConnective.java} | 8 ++++---- ...idesConnective.java => NumericDivisionConnective.java} | 8 ++++---- ...nnective.java => NumericMultiplicationConnective.java} | 8 ++++---- ...sConnective.java => NumericSubtractionConnective.java} | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) rename plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/{NumericPlusConnective.java => NumericAdditionConnective.java} (78%) rename plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/{NumericDividesConnective.java => NumericDivisionConnective.java} (78%) rename plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/{NumericTimesConnective.java => NumericMultiplicationConnective.java} (77%) rename plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/{NumericMinusConnective.java => NumericSubtractionConnective.java} (78%) diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericPlusConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericAdditionConnective.java similarity index 78% rename from plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericPlusConnective.java rename to plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericAdditionConnective.java index 4fe6f4092..566e1c733 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericPlusConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericAdditionConnective.java @@ -17,7 +17,7 @@ package de.cau.cs.kieler.klighd.filtering; /** - * A Numeric Plus Connective takes two numeric operands and evaluates + * A Numeric Addition Connective takes two numeric operands and evaluates * to their sum. * * Operands must implement {@link NumericResult} and be a {@link SemanticFilterTag}. This connective is an internal @@ -26,8 +26,8 @@ * @author mka * */ -public class NumericPlusConnective extends BinaryConnective implements NumericResult { - protected static final String NAME = "NUMERICPLUS"; +public class NumericAdditionConnective extends BinaryConnective implements NumericResult { + protected static final String NAME = "NUMERICADDITION"; /** * Constructor for named rule with default value. @@ -36,7 +36,7 @@ public class NumericPlusConnective extends BinaryConnective implements NumericRe * @param defaultValue the default value * @param ruleName rule name */ - public NumericPlusConnective(NumericResult leftOperand, NumericResult rightOperand) { + public NumericAdditionConnective(NumericResult leftOperand, NumericResult rightOperand) { super(); this.name = NAME; this.leftOperand = (SemanticFilterRule) leftOperand; diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDividesConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDivisionConnective.java similarity index 78% rename from plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDividesConnective.java rename to plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDivisionConnective.java index 514aae416..c7fb01c7d 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDividesConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericDivisionConnective.java @@ -17,7 +17,7 @@ package de.cau.cs.kieler.klighd.filtering; /** - * A Numeric Divides Connective takes two numeric operands and evaluates + * A Numeric Division Connective takes two numeric operands and evaluates * to their quotient. * * Operands must implement {@link NumericResult} and be a {@link SemanticFilterTag}. This connective is an internal @@ -26,8 +26,8 @@ * @author mka * */ -public class NumericDividesConnective extends BinaryConnective implements NumericResult { - protected static final String NAME = "NUMERICDIVIDES"; +public class NumericDivisionConnective extends BinaryConnective implements NumericResult { + protected static final String NAME = "NUMERICDIVISION"; /** * Constructor for named rule with default value. @@ -36,7 +36,7 @@ public class NumericDividesConnective extends BinaryConnective implements Numeri * @param defaultValue the default value * @param ruleName rule name */ - public NumericDividesConnective(NumericResult leftOperand, NumericResult rightOperand) { + public NumericDivisionConnective(NumericResult leftOperand, NumericResult rightOperand) { super(); this.name = NAME; this.leftOperand = (SemanticFilterRule) leftOperand; diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericTimesConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMultiplicationConnective.java similarity index 77% rename from plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericTimesConnective.java rename to plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMultiplicationConnective.java index 87924264e..38bdbb88c 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericTimesConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMultiplicationConnective.java @@ -17,7 +17,7 @@ package de.cau.cs.kieler.klighd.filtering; /** - * A Numeric Times Connective takes two numeric operands and evaluates + * A Numeric Multiplication Connective takes two numeric operands and evaluates * to their product. * * Operands must implement {@link NumericResult} and be a {@link SemanticFilterTag}. This connective is an internal @@ -26,8 +26,8 @@ * @author mka * */ -public class NumericTimesConnective extends BinaryConnective implements NumericResult { - protected static final String NAME = "NUMERICTIMES"; +public class NumericMultiplicationConnective extends BinaryConnective implements NumericResult { + protected static final String NAME = "NUMERICMULTIPLICATION"; /** * Constructor for named rule with default value. @@ -36,7 +36,7 @@ public class NumericTimesConnective extends BinaryConnective implements NumericR * @param defaultValue the default value * @param ruleName rule name */ - public NumericTimesConnective(NumericResult leftOperand, NumericResult rightOperand) { + public NumericMultiplicationConnective(NumericResult leftOperand, NumericResult rightOperand) { super(); this.name = NAME; this.leftOperand = (SemanticFilterRule) leftOperand; diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMinusConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericSubtractionConnective.java similarity index 78% rename from plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMinusConnective.java rename to plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericSubtractionConnective.java index df875cc27..6b93635ee 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericMinusConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericSubtractionConnective.java @@ -17,7 +17,7 @@ package de.cau.cs.kieler.klighd.filtering; /** - * A Numeric Minus Connective takes two numeric operands and evaluates + * A Numeric Subtraction Connective takes two numeric operands and evaluates * to their difference. * * Operands must implement {@link NumericResult} and be a {@link SemanticFilterTag}. This connective is an internal @@ -26,8 +26,8 @@ * @author mka * */ -public class NumericMinusConnective extends BinaryConnective implements NumericResult { - protected static final String NAME = "NUMERICMINUS"; +public class NumericSubtractionConnective extends BinaryConnective implements NumericResult { + protected static final String NAME = "NUMERICSUBSTRACTION"; /** * Constructor for named rule with default value. @@ -36,7 +36,7 @@ public class NumericMinusConnective extends BinaryConnective implements NumericR * @param defaultValue the default value * @param ruleName rule name */ - public NumericMinusConnective(NumericResult leftOperand, NumericResult rightOperand) { + public NumericSubtractionConnective(NumericResult leftOperand, NumericResult rightOperand) { super(); this.name = NAME; this.leftOperand = (SemanticFilterRule) leftOperand; From d8296086ad6f0269c75a92f2207df87d949a4809 Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Tue, 2 Aug 2022 16:03:02 +0200 Subject: [PATCH 08/13] make comparator connectives binary Signed-off-by: Max Kasperowski --- .../filtering/GreaterEqualsConnective.java | 85 ++++++++++--------- .../filtering/GreaterThanConnective.java | 37 ++++---- .../filtering/LessEqualsConnective.java | 85 ++++++++++--------- .../klighd/filtering/LessThanConnective.java | 37 ++++---- .../filtering/NumericEqualConnective.java | 37 ++++---- .../filtering/NumericNotEqualConnective.java | 85 ++++++++++--------- 6 files changed, 198 insertions(+), 168 deletions(-) diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java index aab24ac28..bb0dc5a53 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java @@ -17,52 +17,57 @@ package de.cau.cs.kieler.klighd.filtering; /** - * A GreaterEquals Connective takes one rule R and evaluates to true + * A GreaterEquals Connective takes two numeric rules R1 and R2 and evaluates to true * iff - * R.num >= correspondingTag.num. + * R1 >= R2 * * @author mka * */ -public class GreaterEqualsConnective extends UnaryConnective { +public class GreaterEqualsConnective extends BinaryConnective { protected static final String NAME = "GREATEREQUALS"; - /** - * Constructor for unnamed rule. - * @param operand the operand - */ - public GreaterEqualsConnective(NumericResult operand) { - this(operand, null, null); - } - - /** - * Constructor for unnamed rule with default value. - * @param operand the operand - * @param defaultValue the default value - */ - public GreaterEqualsConnective(NumericResult operand, Boolean defaultValue) { - this(operand, defaultValue, null); - } - - /** - * Constructor for named rule. - * @param operand the operand - * @param ruleName rule name - */ - public GreaterEqualsConnective(NumericResult operand, String ruleName) { - this(operand, null, ruleName); - } - - /** - * Constructor for named rule with default value. - * @param operand the operand - * @param defaultValue the default value - * @param ruleName rule name - */ - public GreaterEqualsConnective(NumericResult operand, Boolean defaultValue, String ruleName) { - super(defaultValue, ruleName); - this.name = NAME; - this.operand = (SemanticFilterRule) operand; - } +/** + * Constructor for unnamed rule. + * @param leftOperand left operand + * @param rightOperand right operand + */ +public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); +} + +/** + * Constructor for unnamed rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + */ +public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); +} + +/** + * Constructor for named rule. + * @param leftOperand left operand + * @param rightOperand right operand + * @param ruleName rule name + */ +public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); +} + +/** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ +public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; +} } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java index b73caa03c..d6e44e2c4 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java @@ -17,51 +17,56 @@ package de.cau.cs.kieler.klighd.filtering; /** - * A GreaterThan Connective takes one rule R and evaluates to true + * A GreaterThan Connective takes two numeric rules R1 and R2 and evaluates to true * iff - * R.num > correspondingTag.num. - * @author tik + * R1 > R2 + * @author tik, mka * */ -public class GreaterThanConnective extends UnaryConnective { +public class GreaterThanConnective extends BinaryConnective { protected static final String NAME = "GREATERTHAN"; /** * Constructor for unnamed rule. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand */ - public GreaterThanConnective(NumericResult operand) { - this(operand, null, null); + public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); } /** * Constructor for unnamed rule with default value. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand * @param defaultValue the default value */ - public GreaterThanConnective(NumericResult operand, Boolean defaultValue) { - this(operand, defaultValue, null); + public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); } /** * Constructor for named rule. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand * @param ruleName rule name */ - public GreaterThanConnective(NumericResult operand, String ruleName) { - this(operand, null, ruleName); + public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); } /** * Constructor for named rule with default value. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand * @param defaultValue the default value * @param ruleName rule name */ - public GreaterThanConnective(NumericResult operand, Boolean defaultValue, String ruleName) { + public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.operand = (SemanticFilterRule) operand; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java index 788750c05..ce1a074f8 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java @@ -17,53 +17,58 @@ package de.cau.cs.kieler.klighd.filtering; /** - * * A LessEquals Connective takes one rule R and evaluates to true + * A LessEquals Connective takes two numeric rules R1 and R2 and evaluates to true * iff - * R.num <= correspondingTag.num. + * R1 <= R2 * * @author mka * */ -public class LessEqualsConnective extends UnaryConnective { +public class LessEqualsConnective extends BinaryConnective { protected static final String NAME = "LESSEQUALS"; - /** - * Constructor for unnamed rule. - * @param operand the operand - */ - public LessEqualsConnective(NumericResult operand) { - this(operand, null, null); - } - - /** - * Constructor for unnamed rule with default value. - * @param operand the operand - * @param defaultValue the default value - */ - public LessEqualsConnective(NumericResult operand, Boolean defaultValue) { - this(operand, defaultValue, null); - } - - /** - * Constructor for named rule. - * @param operand the operand - * @param ruleName rule name - */ - public LessEqualsConnective(NumericResult operand, String ruleName) { - this(operand, null, ruleName); - } - - /** - * Constructor for named rule with default value. - * @param operand the operand - * @param defaultValue the default value - * @param ruleName rule name - */ - public LessEqualsConnective(NumericResult operand, Boolean defaultValue, String ruleName) { - super(defaultValue, ruleName); - this.name = NAME; - this.operand = (SemanticFilterRule) operand; - } +/** + * Constructor for unnamed rule. + * @param leftOperand left operand + * @param rightOperand right operand + */ +public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); +} + +/** + * Constructor for unnamed rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + */ +public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); +} + +/** + * Constructor for named rule. + * @param leftOperand left operand + * @param rightOperand right operand + * @param ruleName rule name + */ +public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); +} + +/** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ +public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; +} } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java index 7904aea60..d535b9bf7 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java @@ -17,51 +17,56 @@ package de.cau.cs.kieler.klighd.filtering; /** - * A LessThan Connective takes one rule R and evaluates to true + * A LessThan Connective takes two numeric rules R1 and R2 and evaluates to true * iff - * R.num < correspondingTag.num. - * @author tik + * R1 < R2 + * @author tik, mka * */ -public class LessThanConnective extends UnaryConnective { +public class LessThanConnective extends BinaryConnective { protected static final String NAME = "LESSTHAN"; /** * Constructor for unnamed rule. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand */ - public LessThanConnective(NumericResult operand) { - this(operand, null, null); + public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); } /** * Constructor for unnamed rule with default value. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand * @param defaultValue the default value */ - public LessThanConnective(NumericResult operand, Boolean defaultValue) { - this(operand, defaultValue, null); + public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); } /** * Constructor for named rule. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand * @param ruleName rule name */ - public LessThanConnective(NumericResult operand, String ruleName) { - this(operand, null, ruleName); + public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); } /** * Constructor for named rule with default value. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand * @param defaultValue the default value * @param ruleName rule name */ - public LessThanConnective(NumericResult operand, Boolean defaultValue, String ruleName) { + public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.operand = (SemanticFilterRule) operand; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java index 4b6a16cfc..f165d2879 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java @@ -17,51 +17,56 @@ package de.cau.cs.kieler.klighd.filtering; /** - * A NumericEqual Connective takes one rule R and evaluates to true + * A NumericEqual Connective takes two rules R1 and R2 and evaluates to true * iff - * R.num == correspondingTag.num. - * @author tik + * R1 == R2 + * @author tik, mka * */ -public class NumericEqualConnective extends UnaryConnective { +public class NumericEqualConnective extends BinaryConnective { protected static final String NAME = "NUMERICEQUAL"; /** * Constructor for unnamed rule. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand */ - public NumericEqualConnective(NumericResult operand) { - this(operand, null, null); + public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); } /** * Constructor for unnamed rule with default value. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand * @param defaultValue the default value */ - public NumericEqualConnective(NumericResult operand, Boolean defaultValue) { - this(operand, defaultValue, null); + public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); } /** * Constructor for named rule. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand * @param ruleName rule name */ - public NumericEqualConnective(NumericResult operand, String ruleName) { - this(operand, null, ruleName); + public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); } /** * Constructor for named rule with default value. - * @param operand the operand + * @param leftOperand left operand + * @param rightOperand right operand * @param defaultValue the default value * @param ruleName rule name */ - public NumericEqualConnective(NumericResult operand, Boolean defaultValue, String ruleName) { + public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.operand = (SemanticFilterRule) operand; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java index 513670374..aeffe5a25 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java @@ -17,53 +17,58 @@ package de.cau.cs.kieler.klighd.filtering; /** - * * A NumericNotEqual Connective takes one rule R and evaluates to true + * A NumericNotEqual Connective takes two numeric rules R1 and R2 and evaluates to true * iff - * R.num != correspondingTag.num. + * R1 != R2 * * @author mka * */ -public class NumericNotEqualConnective extends UnaryConnective { +public class NumericNotEqualConnective extends BinaryConnective { protected static final String NAME = "NUMERICNOTEQUAL"; - /** - * Constructor for unnamed rule. - * @param operand the operand - */ - public NumericNotEqualConnective(NumericResult operand) { - this(operand, null, null); - } - - /** - * Constructor for unnamed rule with default value. - * @param operand the operand - * @param defaultValue the default value - */ - public NumericNotEqualConnective(NumericResult operand, Boolean defaultValue) { - this(operand, defaultValue, null); - } - - /** - * Constructor for named rule. - * @param operand the operand - * @param ruleName rule name - */ - public NumericNotEqualConnective(NumericResult operand, String ruleName) { - this(operand, null, ruleName); - } - - /** - * Constructor for named rule with default value. - * @param operand the operand - * @param defaultValue the default value - * @param ruleName rule name - */ - public NumericNotEqualConnective(NumericResult operand, Boolean defaultValue, String ruleName) { - super(defaultValue, ruleName); - this.name = NAME; - this.operand = (SemanticFilterRule) operand; - } +/** + * Constructor for unnamed rule. + * @param leftOperand left operand + * @param rightOperand right operand + */ +public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + this(leftOperand, rightOperand, null, null); +} + +/** + * Constructor for unnamed rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + */ +public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + this(leftOperand, rightOperand, defaultValue, null); +} + +/** + * Constructor for named rule. + * @param leftOperand left operand + * @param rightOperand right operand + * @param ruleName rule name + */ +public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + this(leftOperand, rightOperand, null, ruleName); +} + +/** + * Constructor for named rule with default value. + * @param leftOperand left operand + * @param rightOperand right operand + * @param defaultValue the default value + * @param ruleName rule name + */ +public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + super(defaultValue, ruleName); + this.name = NAME; + this.leftOperand = leftOperand; + this.rightOperand = rightOperand; +} } From 9f96a571787aa5b4d08366b8566b04ef07ce867f Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Tue, 2 Aug 2022 16:24:35 +0200 Subject: [PATCH 09/13] add numeric constant Signed-off-by: Max Kasperowski --- .../filtering/NumericConstantConnective.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericConstantConnective.java diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericConstantConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericConstantConnective.java new file mode 100644 index 000000000..e927a92b5 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericConstantConnective.java @@ -0,0 +1,68 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering; + +/** + * Numeric constant for building expressions. + * + * @author mka + * + */ +public class NumericConstantConnective extends NullaryConnective implements NumericResult { + +protected static final String NAME = "CONST"; +private Double num; + + /** + * Constructor for unnamed rule. + * @param num + */ + public NumericConstantConnective(Double num) { + this(null, null, num); + } + + /** + * Constructor for unnamed rule with default value. + * @param defaultValue + * @param num + */ + public NumericConstantConnective(Boolean defaultValue, Double num) { + this(defaultValue, null, num); + } + + /** + * Constructor for named rule. + * @param ruleName + * @param num + */ + public NumericConstantConnective(String ruleName, Double num) { + this(null, ruleName, num); + } + + /** + * Constructor for named rule with default value. + * @param defaultValue + * @param ruleName + * @param num + */ + public NumericConstantConnective(Boolean defaultValue, String ruleName, Double num) { + super(defaultValue, ruleName); + this.name = NAME; + this.num = num; + } + +} From e41ed10459eb20db93bf0f62a77c24424198a001 Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Mon, 29 Aug 2022 13:18:05 +0200 Subject: [PATCH 10/13] add parser with tests and update some type checks that were missing Signed-off-by: Max Kasperowski --- .../META-INF/MANIFEST.MF | 1 + .../filtering/GreaterEqualsConnective.java | 12 +- .../filtering/GreaterThanConnective.java | 12 +- .../filtering/LessEqualsConnective.java | 12 +- .../klighd/filtering/LessThanConnective.java | 12 +- .../filtering/NumericConstantConnective.java | 5 + .../filtering/NumericEqualConnective.java | 12 +- .../filtering/NumericNotEqualConnective.java | 12 +- .../parser/SemanticFilterRuleParser.java | 296 ++++++++++++++++++ .../klighd/test/SemanticFilteringTest.java | 51 +++ 10 files changed, 389 insertions(+), 36 deletions(-) create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/parser/SemanticFilterRuleParser.java create mode 100644 test/de.cau.cs.kieler.klighd.test/src/de/cau/cs/kieler/klighd/test/SemanticFilteringTest.java diff --git a/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF b/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF index 2a48d88d7..2eb533508 100644 --- a/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF +++ b/plugins/de.cau.cs.kieler.klighd/META-INF/MANIFEST.MF @@ -22,6 +22,7 @@ Bundle-Activator: de.cau.cs.kieler.klighd.KlighdPlugin Export-Package: de.cau.cs.kieler.klighd, de.cau.cs.kieler.klighd.actions, de.cau.cs.kieler.klighd.filtering, + de.cau.cs.kieler.klighd.filtering.parser, de.cau.cs.kieler.klighd.internal;x-friends:="de.cau.cs.kieler.klighd.piccolo,de.cau.cs.kieler.klighd.ui,de.cau.cs.kieler.klighd.lsp", de.cau.cs.kieler.klighd.internal.macrolayout;x-friends:="de.cau.cs.kieler.klighd.ui,de.cau.cs.kieler.klighd.piccolo", de.cau.cs.kieler.klighd.internal.preferences;x-internal:=true, diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java index bb0dc5a53..090230ed8 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterEqualsConnective.java @@ -32,7 +32,7 @@ public class GreaterEqualsConnective extends BinaryConnective { * @param leftOperand left operand * @param rightOperand right operand */ -public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { +public GreaterEqualsConnective(NumericResult leftOperand, NumericResult rightOperand) { this(leftOperand, rightOperand, null, null); } @@ -42,7 +42,7 @@ public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRul * @param rightOperand right operand * @param defaultValue the default value */ -public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { +public GreaterEqualsConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue) { this(leftOperand, rightOperand, defaultValue, null); } @@ -52,7 +52,7 @@ public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRul * @param rightOperand right operand * @param ruleName rule name */ -public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { +public GreaterEqualsConnective(NumericResult leftOperand, NumericResult rightOperand, String ruleName) { this(leftOperand, rightOperand, null, ruleName); } @@ -63,11 +63,11 @@ public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRul * @param defaultValue the default value * @param ruleName rule name */ -public GreaterEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { +public GreaterEqualsConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.leftOperand = leftOperand; - this.rightOperand = rightOperand; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java index d6e44e2c4..f5ed294b5 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/GreaterThanConnective.java @@ -31,7 +31,7 @@ public class GreaterThanConnective extends BinaryConnective { * @param leftOperand left operand * @param rightOperand right operand */ - public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + public GreaterThanConnective(NumericResult leftOperand, NumericResult rightOperand) { this(leftOperand, rightOperand, null, null); } @@ -41,7 +41,7 @@ public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule * @param rightOperand right operand * @param defaultValue the default value */ - public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + public GreaterThanConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue) { this(leftOperand, rightOperand, defaultValue, null); } @@ -51,7 +51,7 @@ public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule * @param rightOperand right operand * @param ruleName rule name */ - public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + public GreaterThanConnective(NumericResult leftOperand, NumericResult rightOperand, String ruleName) { this(leftOperand, rightOperand, null, ruleName); } @@ -62,11 +62,11 @@ public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule * @param defaultValue the default value * @param ruleName rule name */ - public GreaterThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + public GreaterThanConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.leftOperand = leftOperand; - this.rightOperand = rightOperand; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java index ce1a074f8..fe16b303a 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessEqualsConnective.java @@ -33,7 +33,7 @@ public class LessEqualsConnective extends BinaryConnective { * @param leftOperand left operand * @param rightOperand right operand */ -public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { +public LessEqualsConnective(NumericResult leftOperand, NumericResult rightOperand) { this(leftOperand, rightOperand, null, null); } @@ -43,7 +43,7 @@ public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule r * @param rightOperand right operand * @param defaultValue the default value */ -public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { +public LessEqualsConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue) { this(leftOperand, rightOperand, defaultValue, null); } @@ -53,7 +53,7 @@ public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule r * @param rightOperand right operand * @param ruleName rule name */ -public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { +public LessEqualsConnective(NumericResult leftOperand, NumericResult rightOperand, String ruleName) { this(leftOperand, rightOperand, null, ruleName); } @@ -64,11 +64,11 @@ public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule r * @param defaultValue the default value * @param ruleName rule name */ -public LessEqualsConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { +public LessEqualsConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.leftOperand = leftOperand; - this.rightOperand = rightOperand; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java index d535b9bf7..4f77983ee 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/LessThanConnective.java @@ -31,7 +31,7 @@ public class LessThanConnective extends BinaryConnective { * @param leftOperand left operand * @param rightOperand right operand */ - public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + public LessThanConnective(NumericResult leftOperand, NumericResult rightOperand) { this(leftOperand, rightOperand, null, null); } @@ -41,7 +41,7 @@ public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rig * @param rightOperand right operand * @param defaultValue the default value */ - public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + public LessThanConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue) { this(leftOperand, rightOperand, defaultValue, null); } @@ -51,7 +51,7 @@ public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rig * @param rightOperand right operand * @param ruleName rule name */ - public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + public LessThanConnective(NumericResult leftOperand, NumericResult rightOperand, String ruleName) { this(leftOperand, rightOperand, null, ruleName); } @@ -62,11 +62,11 @@ public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rig * @param defaultValue the default value * @param ruleName rule name */ - public LessThanConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + public LessThanConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.leftOperand = leftOperand; - this.rightOperand = rightOperand; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericConstantConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericConstantConnective.java index e927a92b5..5f3f9cbd5 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericConstantConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericConstantConnective.java @@ -64,5 +64,10 @@ public NumericConstantConnective(Boolean defaultValue, String ruleName, Double n this.name = NAME; this.num = num; } + + @Override + public String toString() { + return this.name + "(" + num + ")"; + } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java index f165d2879..dafba6b9b 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericEqualConnective.java @@ -31,7 +31,7 @@ public class NumericEqualConnective extends BinaryConnective { * @param leftOperand left operand * @param rightOperand right operand */ - public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { + public NumericEqualConnective(NumericResult leftOperand, NumericResult rightOperand) { this(leftOperand, rightOperand, null, null); } @@ -41,7 +41,7 @@ public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule * @param rightOperand right operand * @param defaultValue the default value */ - public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { + public NumericEqualConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue) { this(leftOperand, rightOperand, defaultValue, null); } @@ -51,7 +51,7 @@ public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule * @param rightOperand right operand * @param ruleName rule name */ - public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { + public NumericEqualConnective(NumericResult leftOperand, NumericResult rightOperand, String ruleName) { this(leftOperand, rightOperand, null, ruleName); } @@ -62,11 +62,11 @@ public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule * @param defaultValue the default value * @param ruleName rule name */ - public NumericEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { + public NumericEqualConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.leftOperand = leftOperand; - this.rightOperand = rightOperand; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java index aeffe5a25..1e832e6f2 100644 --- a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/NumericNotEqualConnective.java @@ -33,7 +33,7 @@ public class NumericNotEqualConnective extends BinaryConnective { * @param leftOperand left operand * @param rightOperand right operand */ -public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand) { +public NumericNotEqualConnective(NumericResult leftOperand, NumericResult rightOperand) { this(leftOperand, rightOperand, null, null); } @@ -43,7 +43,7 @@ public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterR * @param rightOperand right operand * @param defaultValue the default value */ -public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue) { +public NumericNotEqualConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue) { this(leftOperand, rightOperand, defaultValue, null); } @@ -53,7 +53,7 @@ public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterR * @param rightOperand right operand * @param ruleName rule name */ -public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, String ruleName) { +public NumericNotEqualConnective(NumericResult leftOperand, NumericResult rightOperand, String ruleName) { this(leftOperand, rightOperand, null, ruleName); } @@ -64,11 +64,11 @@ public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterR * @param defaultValue the default value * @param ruleName rule name */ -public NumericNotEqualConnective(SemanticFilterRule leftOperand, SemanticFilterRule rightOperand, Boolean defaultValue, String ruleName) { +public NumericNotEqualConnective(NumericResult leftOperand, NumericResult rightOperand, Boolean defaultValue, String ruleName) { super(defaultValue, ruleName); this.name = NAME; - this.leftOperand = leftOperand; - this.rightOperand = rightOperand; + this.leftOperand = (SemanticFilterRule) leftOperand; + this.rightOperand = (SemanticFilterRule) rightOperand; } } diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/parser/SemanticFilterRuleParser.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/parser/SemanticFilterRuleParser.java new file mode 100644 index 000000000..def06d934 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/parser/SemanticFilterRuleParser.java @@ -0,0 +1,296 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering.parser; + +import static java.util.Map.entry; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Stack; +import java.util.StringTokenizer; + +import de.cau.cs.kieler.klighd.filtering.AndConnective; +import de.cau.cs.kieler.klighd.filtering.FalseConnective; +import de.cau.cs.kieler.klighd.filtering.GreaterEqualsConnective; +import de.cau.cs.kieler.klighd.filtering.GreaterThanConnective; +import de.cau.cs.kieler.klighd.filtering.LessEqualsConnective; +import de.cau.cs.kieler.klighd.filtering.LessThanConnective; +import de.cau.cs.kieler.klighd.filtering.LogicEqualConnective; +import de.cau.cs.kieler.klighd.filtering.NegationConnective; +import de.cau.cs.kieler.klighd.filtering.NumericAdditionConnective; +import de.cau.cs.kieler.klighd.filtering.NumericConstantConnective; +import de.cau.cs.kieler.klighd.filtering.NumericDivisionConnective; +import de.cau.cs.kieler.klighd.filtering.NumericEqualConnective; +import de.cau.cs.kieler.klighd.filtering.NumericMultiplicationConnective; +import de.cau.cs.kieler.klighd.filtering.NumericNotEqualConnective; +import de.cau.cs.kieler.klighd.filtering.NumericResult; +import de.cau.cs.kieler.klighd.filtering.NumericSubtractionConnective; +import de.cau.cs.kieler.klighd.filtering.OrConnective; +import de.cau.cs.kieler.klighd.filtering.SemanticFilterRule; +import de.cau.cs.kieler.klighd.filtering.SemanticFilterTag; +import de.cau.cs.kieler.klighd.filtering.TrueConnective; + +/** + * @author mka + * + */ +public class SemanticFilterRuleParser { + + private abstract class Node { + public String token; + // current return type of AST + // -1: unknown + // 0: boolean + // 1: numeric + public int type; + public Node(String token, int type) { + this.token = token; + this.type = type; + } + } + + private class OperatorNode extends Node { + private List children; + + public List getChildren() { return children; } + + public OperatorNode(String token, int type) { + super(token, type); + this.children = new ArrayList<>(); + } + public OperatorNode(String token, int type, List children) { + super(token, type); + this.children = children; + } + + public void addChild(Node child) { + this.children.add(child); + } + } + + private class OperandNode extends Node { + + public OperandNode(String token, int type) { + super(token, type); + } + } + + public class InvalidSyntaxException extends Exception { + + public InvalidSyntaxException(String message) { + super(message); + } + } + + private SemanticFilterRule convertAST(Node ast) throws InvalidSyntaxException { + try { + SemanticFilterRule result; + switch(ast.token) { + case "*": + result = new NumericMultiplicationConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + case "/": + result = new NumericDivisionConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + case "+": + result = new NumericAdditionConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + case "-": + result = new NumericSubtractionConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + // NUMERIC-TO-BOOLEAN + case "=": + if (ast.type == 0) { + result = new LogicEqualConnective( + convertAST(((OperatorNode)ast).getChildren().get(0)), + convertAST(((OperatorNode)ast).getChildren().get(1))); + } else { + result = new NumericEqualConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + } + break; + case "!=": + result = new NumericNotEqualConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + case ">=": + result = new GreaterEqualsConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + case ">": + result = new GreaterThanConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + case "<=": + result = new LessEqualsConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + case "<": + result = new LessThanConnective( + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(0)), + (NumericResult) convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + // BOOLEAN-TO-BOOLEAN + case "||": + result = new OrConnective( + convertAST(((OperatorNode)ast).getChildren().get(0)), + convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + case "&&": + result = new AndConnective( + convertAST(((OperatorNode)ast).getChildren().get(0)), + convertAST(((OperatorNode)ast).getChildren().get(1))); + break; + case "!": + result = new NegationConnective( + convertAST(((OperatorNode)ast).getChildren().get(0))); + break; + case "true": + result = new TrueConnective(); + break; + case "false": + result = new FalseConnective(); + default: + // variable or number + if (ast.token.charAt(0) == '$' || ast.token.charAt(0) == '#') { + result = new SemanticFilterTag(ast.token.substring(1)); + } else { + result = new NumericConstantConnective(Double.valueOf(ast.token)); + } + } + return result; + } catch (Exception e) { + throw new InvalidSyntaxException("Syntax error."); + } + } + + private static List OPERATORS = new ArrayList<>(Arrays.asList( + "*", "/", "+", "-", "=", "!=", ">=", ">", "<=", "<", "||", "&&", "!")); + private static Map PRECEDENCES = Map.ofEntries( + entry("*", 10), + entry("/", 10), + entry("+", 9), + entry("-", 9), + entry("=", 7), + entry("!=", 7), + entry(">=", 8), + entry(">", 8), + entry("<=", 8), + entry("<", 8), + entry("||", 3), + entry("&&", 4), + entry("!", 6)); + /** + * Parses a semantic filter rule expression and creates the abstract syntax tree i.e., {@link SemanticFilterRule}. + * @param ruleString expression + * @return AST + * @throws InvalidSyntaxException + */ + public SemanticFilterRule parse(String ruleString) throws InvalidSyntaxException { + + // Tokenize string + StringTokenizer tokenizer = new StringTokenizer(ruleString); + Stack operatorStack = new Stack<>(); + Stack outputStack = new Stack<>(); + + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + + if (OPERATORS.contains(token)) { + + while (!operatorStack.isEmpty() && !operatorStack.peek().token.equals("(") + && (PRECEDENCES.get(operatorStack.peek().token) > PRECEDENCES.get(token) + || PRECEDENCES.get(operatorStack.peek().token) == PRECEDENCES.get(token) + && !token.equals("!"))) { + popOperator(operatorStack, outputStack); + } + operatorStack.push(new OperatorNode(token,-1)); + + } else if (token.equals("(")) { + operatorStack.push(new OperatorNode(token, -1)); + } else if (token.equals(")")) { + if (operatorStack.isEmpty()) { + throw new InvalidSyntaxException("Mismatched parentheses."); + } + while (!operatorStack.peek().token.equals("(")) { + if (operatorStack.isEmpty()) { + throw new InvalidSyntaxException("Mismatched parentheses."); + } + popOperator(operatorStack, outputStack); + } + // discard final ( + operatorStack.pop(); + } else { + // Operand + if (token.startsWith("#") || token.equals("true") || token.equals("false")) { + outputStack.push(new OperandNode(token, 0)); + } else { + // number or variable starting with $ + outputStack.push(new OperandNode(token, 1)); + } + } + } + // pop remaining operators + while (!operatorStack.isEmpty()) { + popOperator(operatorStack, outputStack); + } + + return convertAST(outputStack.pop()); + } + + private void popOperator(Stack operatorStack, Stack outputStack) throws InvalidSyntaxException { + // remove operator from operator stack and create new node on output stack + OperatorNode operator = operatorStack.pop(); + if (operator.token.equals("(") || operator.token.equals(")")) { + throw new InvalidSyntaxException("Mismatched parentheses."); + } + if (operator.token.equals("!")) { + Node operand = outputStack.pop(); + operator.addChild(operand); + operator.type = 0; + outputStack.push(operator); + } else { + // all other operators are binary + Node operand1 = outputStack.pop(); + Node operand2 = outputStack.pop(); + // reverse order to get correct final order + operator.addChild(operand2); + operator.addChild(operand1); + if (operand1.type != operand2.type) { + throw new InvalidSyntaxException("Mixed use of boolean and numeric types in operator " + operator.token + "."); + } + operator.type = operand1.type; + outputStack.push(operator); + } + } + +} diff --git a/test/de.cau.cs.kieler.klighd.test/src/de/cau/cs/kieler/klighd/test/SemanticFilteringTest.java b/test/de.cau.cs.kieler.klighd.test/src/de/cau/cs/kieler/klighd/test/SemanticFilteringTest.java new file mode 100644 index 000000000..ed61b3461 --- /dev/null +++ b/test/de.cau.cs.kieler.klighd.test/src/de/cau/cs/kieler/klighd/test/SemanticFilteringTest.java @@ -0,0 +1,51 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import de.cau.cs.kieler.klighd.filtering.SemanticFilterRule; +import de.cau.cs.kieler.klighd.filtering.parser.SemanticFilterRuleParser; +import de.cau.cs.kieler.klighd.filtering.parser.SemanticFilterRuleParser.InvalidSyntaxException; + +/** + * Tests of classes in {@link de.cau.cs.kieler.klighd.filtering} + * + * @author mka + * + */ +public class SemanticFilteringTest { + + @Test + public void testSimpleExpressions() { + try { + SemanticFilterRule rule1 = new SemanticFilterRuleParser().parse("#tag1 && #tag2 || #tag3"); + assertEquals("OR(AND((tag=tag1, num=null), (tag=tag2, num=null)), (tag=tag3, num=null))", rule1.toString()); + SemanticFilterRule rule2 = new SemanticFilterRuleParser().parse("( #tag1 )"); + assertEquals("(tag=tag1, num=null)", rule2.toString()); + SemanticFilterRule rule3 = new SemanticFilterRuleParser().parse("$tag1 + $tag2 > 4"); + assertEquals("GREATERTHAN(NUMERICADDITION((tag=tag1, num=null), (tag=tag2, num=null)), CONST(4.0))", rule3.toString()); + } catch (InvalidSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + +} From e21c273d6a9b72580f2f937cbcca96117059e163 Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Mon, 29 Aug 2022 13:34:47 +0200 Subject: [PATCH 11/13] Update buildAndTest.yml --- .github/workflows/buildAndTest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index 00608bc63..0a76e7086 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -17,7 +17,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v2 with: - java-version: 8 + java-version: 11 distribution: adopt - name: Cache Maven packages uses: actions/cache@v2 From 56c84f4c6ea719ec7e7368b313397997576c932d Mon Sep 17 00:00:00 2001 From: Max Kasperowski Date: Mon, 29 Aug 2022 13:36:52 +0200 Subject: [PATCH 12/13] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e24a5e08b..476b0e054 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ 1.7.0 - 1.8 + 11 2.22.0 0.8.1 From 6c2b6e7380c90599572c2a5283e93852fd352693 Mon Sep 17 00:00:00 2001 From: fight4day Date: Mon, 29 Aug 2022 16:13:38 +0200 Subject: [PATCH 13/13] Wrote a util for parsing --- .../parser/SemanticFilterRuleParserUtil.java | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/parser/SemanticFilterRuleParserUtil.java diff --git a/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/parser/SemanticFilterRuleParserUtil.java b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/parser/SemanticFilterRuleParserUtil.java new file mode 100644 index 000000000..66ae95f99 --- /dev/null +++ b/plugins/de.cau.cs.kieler.klighd/src/de/cau/cs/kieler/klighd/filtering/parser/SemanticFilterRuleParserUtil.java @@ -0,0 +1,98 @@ +/* + * KIELER - Kiel Integrated Environment for Layout Eclipse RichClient + * + * http://rtsys.informatik.uni-kiel.de/kieler + * + * Copyright 2022 by + * + Kiel University + * + Department of Computer Science + * + Real-Time and Embedded Systems Group + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package de.cau.cs.kieler.klighd.filtering.parser; + +import de.cau.cs.kieler.klighd.filtering.SemanticFilterRule; +import de.cau.cs.kieler.klighd.filtering.SemanticFilterRuleUtil; +import de.cau.cs.kieler.klighd.filtering.parser.SemanticFilterRuleParser.InvalidSyntaxException; + +/** + * Util for easily parsing rules. + * + * @author tik + */ +public abstract class SemanticFilterRuleParserUtil { + + /** Instance of parser. Just one is enough. */ + private static final SemanticFilterRuleParser PARSER = new SemanticFilterRuleParser(); + + /** + * Parses a semantic filter rule expression and returns the {@link SemanticFilterRule}. + * + * @param ruleString + * The semantic filter rule expression + * @return The semantic filter rule + * @see SemanticFilterRuleParser#parse(String) + * @throws InvalidSyntaxException + */ + public static SemanticFilterRule parse(String ruleString) throws InvalidSyntaxException { + return PARSER.parse(ruleString); + } + + /** + * Parses a semantic filter rule expression and returns the {@link SemanticFilterRule} with + * given ruleName. + * + * @param ruleString + * The semantic filter rule expression + * @param ruleName + * The rule name + * @return The semantic filter rule + * @see SemanticFilterRuleParser#parse(String) + * @throws InvalidSyntaxException + */ + public static SemanticFilterRule parse(String ruleString, String ruleName) + throws InvalidSyntaxException { + return SemanticFilterRuleUtil.addRuleName(ruleName, PARSER.parse(ruleString)); + } + + /** + * Tries parsing a semantic filter rule expression. Returns the {@link SemanticFilterRule} or + * {@code null} if the syntax is invalid. + * + * @param ruleString + * The semantic filter rule expression + * @return The semantic filter rule or {@code null} if the syntax is invalid + * @see SemanticFilterRuleParser#parse(String) + */ + public static SemanticFilterRule tryParse(String ruleString) { + try { + return parse(ruleString); + } catch (InvalidSyntaxException e) { + return null; + } + } + + /** + * Tries parsing a semantic filter rule expression. Returns the {@link SemanticFilterRule} or + * {@code null} if the syntax is invalid. + * + * @param ruleString + * The semantic filter rule expression + * @param ruleName + * The rule name + * @return The semantic filter rule or {@code null} if the syntax is invalid + * @see SemanticFilterRuleParser#parse(String) + */ + public static SemanticFilterRule tryParse(String ruleString, String ruleName) { + try { + return parse(ruleString, ruleName); + } catch (InvalidSyntaxException e) { + return null; + } + } +}