Skip to content

Commit 27a5698

Browse files
committed
ST6RI-886 Implemented all functions in SequenceFunctions package.
- Also added tests to ExpressionEvaluationTest.
1 parent f99b275 commit 27a5698

20 files changed

Lines changed: 739 additions & 19 deletions

File tree

org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/LibraryFunctionFactory.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,24 @@ protected void initializeFunctionMap() {
3838
put(new ProdFunction());
3939

4040
// SequenceFunctions
41-
put(new SizeFunction());
41+
put(new ExcludesFunction());
42+
put(new ExcludingAtFunction());
43+
put(new ExcludingFunction());
44+
put(new HeadFunction());
45+
put(new IncludesFunction());
46+
put(new IncludesOnlyFunction());
47+
put(new IncludingAtFunction());
48+
put(new IncludingFunction());
49+
put(new IntersectionFunction());
4250
put(new IsEmptyFunction());
51+
put(new LastFunction());
4352
put(new NotEmptyFunction());
44-
put(new IncludesFunction());
45-
put(new ExcludesFunction());
53+
put(new SequenceEqualsFunction());
54+
put(new SequenceSameFunction());
55+
put(new SizeFunction());
56+
put(new SubsequenceFunction());
57+
put(new TailFunction());
58+
put(new UnionFunction());
4659

4760
// StringFunctions
4861
put(new StringLengthFunction());

org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/functions/sequence/ExcludesFunction.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ public String getOperatorName() {
3535

3636
@Override
3737
public EList<Element> invoke(InvocationExpression invocation, Element target, ModelLevelExpressionEvaluator evaluator) {
38-
EList<Element> list = evaluator.evaluateArgument(invocation, 0, target);
39-
Element value = evaluator.argumentValue(invocation, 1, target);
40-
Boolean result = list == null && value == null? null: list.stream().noneMatch(x->EvaluationUtil.equal(x, value));
41-
return result == null? EvaluationUtil.singletonList(invocation):
42-
EvaluationUtil.booleanResult(result);
38+
EList<Element> list1 = evaluator.evaluateArgument(invocation, 0, target);
39+
EList<Element> list2 = evaluator.evaluateArgument(invocation, 1, target);
40+
return list1 == null || list2 == null? EvaluationUtil.singletonList(invocation):
41+
EvaluationUtil.booleanResult(list2.stream().allMatch(e2->list1.stream().noneMatch(e1->EvaluationUtil.equal(e1, e2))));
4342
}
4443

4544
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of theGNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.sequence;
22+
23+
import org.eclipse.emf.common.util.BasicEList;
24+
import org.eclipse.emf.common.util.EList;
25+
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
26+
import org.omg.sysml.lang.sysml.Element;
27+
import org.omg.sysml.lang.sysml.InvocationExpression;
28+
import org.omg.sysml.util.EvaluationUtil;
29+
30+
public class ExcludingAtFunction extends SequenceFunction {
31+
32+
@Override
33+
public String getOperatorName() {
34+
return "excludingAt";
35+
}
36+
37+
@Override
38+
public EList<Element> invoke(InvocationExpression invocation, Element target, ModelLevelExpressionEvaluator evaluator) {
39+
EList<Element> seq = evaluator.evaluateArgument(invocation, 0, target);
40+
Element startIndex = evaluator.argumentValue(invocation, 1, target);
41+
Element endIndex = evaluator.argumentValue(invocation, 2, target);
42+
if (seq == null || startIndex == null) {
43+
return EvaluationUtil.singletonList(invocation);
44+
} else {
45+
if (endIndex == null) {
46+
endIndex = startIndex;
47+
}
48+
Object startIndexValue = EvaluationUtil.valueOf(startIndex);
49+
Object endIndexValue = EvaluationUtil.valueOf(endIndex);
50+
if (!(startIndexValue == null || startIndexValue instanceof Integer &&
51+
endIndexValue == null || endIndexValue instanceof Integer)) {
52+
return EvaluationUtil.singletonList(invocation);
53+
} else if (startIndexValue == null) {
54+
return seq;
55+
} else {
56+
int i = ((Integer)startIndexValue) - 1;
57+
if (i < 0) {
58+
i = 0;
59+
}
60+
int j = endIndexValue == null? seq.size(): ((Integer)endIndexValue);
61+
if (j < 0) {
62+
j = 0;
63+
}
64+
if (j < i) {
65+
return seq;
66+
} else {
67+
EList<Element> result = new BasicEList<>(seq.subList(0, i));
68+
result.addAll(seq.subList(j, seq.size()));
69+
return result;
70+
}
71+
}
72+
}
73+
}
74+
75+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of theGNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.sequence;
22+
23+
import org.eclipse.emf.common.util.BasicEList;
24+
import org.eclipse.emf.common.util.EList;
25+
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
26+
import org.omg.sysml.lang.sysml.Element;
27+
import org.omg.sysml.lang.sysml.InvocationExpression;
28+
import org.omg.sysml.util.EvaluationUtil;
29+
30+
public class ExcludingFunction extends SequenceFunction {
31+
32+
@Override
33+
public String getOperatorName() {
34+
return "excluding";
35+
}
36+
37+
@Override
38+
public EList<Element> invoke(InvocationExpression invocation, Element target, ModelLevelExpressionEvaluator evaluator) {
39+
EList<Element> list1 = evaluator.evaluateArgument(invocation, 0, target);
40+
EList<Element> list2 = evaluator.evaluateArgument(invocation, 1, target);
41+
if (list1 == null || list2 == null) {
42+
return EvaluationUtil.singletonList(invocation);
43+
} else {
44+
EList<Element> result = new BasicEList<>(list1);
45+
result.removeIf(e1->list2.stream().anyMatch(e2->EvaluationUtil.equal(e1, e2)));
46+
return result;
47+
}
48+
}
49+
50+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of theGNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.sequence;
22+
23+
import org.eclipse.emf.common.util.EList;
24+
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
25+
import org.omg.sysml.lang.sysml.Element;
26+
import org.omg.sysml.lang.sysml.InvocationExpression;
27+
import org.omg.sysml.util.EvaluationUtil;
28+
29+
public class HeadFunction extends SequenceFunction {
30+
31+
@Override
32+
public String getOperatorName() {
33+
return "head";
34+
}
35+
36+
@Override
37+
public EList<Element> invoke(InvocationExpression invocation, Element target, ModelLevelExpressionEvaluator evaluator) {
38+
EList<Element> seq = evaluator.evaluateArgument(invocation, 0, target);
39+
return seq == null? EvaluationUtil.singletonList(invocation):
40+
seq.isEmpty()? EvaluationUtil.nullList():
41+
EvaluationUtil.singletonList(seq.getFirst());
42+
}
43+
44+
}

org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/functions/sequence/IncludesFunction.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ public String getOperatorName() {
3535

3636
@Override
3737
public EList<Element> invoke(InvocationExpression invocation, Element target, ModelLevelExpressionEvaluator evaluator) {
38-
EList<Element> list = evaluator.evaluateArgument(invocation, 0, target);
39-
Element value = evaluator.argumentValue(invocation, 1, target);
40-
Boolean result = list == null && value == null? null: list.stream().anyMatch(x->EvaluationUtil.equal(x, value));
41-
return result == null? EvaluationUtil.singletonList(invocation):
42-
EvaluationUtil.booleanResult(result);
38+
EList<Element> list1 = evaluator.evaluateArgument(invocation, 0, target);
39+
EList<Element> list2 = evaluator.evaluateArgument(invocation, 1, target);
40+
return list1 == null || list2 == null? EvaluationUtil.singletonList(invocation):
41+
list2.isEmpty()? EvaluationUtil.booleanResult(true):
42+
list1.isEmpty()? EvaluationUtil.booleanResult(false):
43+
EvaluationUtil.booleanResult(includes(list1, list2));
44+
}
45+
46+
protected static boolean includes(EList<Element> list1, EList<Element> list2) {
47+
return list2.stream().allMatch(x->list1.stream().anyMatch(y->EvaluationUtil.equal(x, y)));
4348
}
4449

4550
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of theGNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.sequence;
22+
23+
import org.eclipse.emf.common.util.EList;
24+
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
25+
import org.omg.sysml.lang.sysml.Element;
26+
import org.omg.sysml.lang.sysml.InvocationExpression;
27+
import org.omg.sysml.util.EvaluationUtil;
28+
29+
public class IncludesOnlyFunction extends IncludesFunction {
30+
31+
@Override
32+
public String getOperatorName() {
33+
return "includesOnly";
34+
}
35+
36+
@Override
37+
public EList<Element> invoke(InvocationExpression invocation, Element target, ModelLevelExpressionEvaluator evaluator) {
38+
EList<Element> list1 = evaluator.evaluateArgument(invocation, 0, target);
39+
EList<Element> list2 = evaluator.evaluateArgument(invocation, 1, target);
40+
return list1 == null || list2 == null? EvaluationUtil.singletonList(invocation):
41+
list2.isEmpty()? EvaluationUtil.booleanResult(list1.isEmpty()):
42+
list1.isEmpty()? EvaluationUtil.booleanResult(false):
43+
EvaluationUtil.booleanResult(includes(list1, list2) && includes(list2, list1));
44+
}
45+
46+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of theGNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.sequence;
22+
23+
import org.eclipse.emf.common.util.BasicEList;
24+
import org.eclipse.emf.common.util.EList;
25+
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
26+
import org.omg.sysml.lang.sysml.Element;
27+
import org.omg.sysml.lang.sysml.InvocationExpression;
28+
import org.omg.sysml.util.EvaluationUtil;
29+
30+
public class IncludingAtFunction extends SequenceFunction {
31+
32+
@Override
33+
public String getOperatorName() {
34+
return "includingAt";
35+
}
36+
37+
@Override
38+
public EList<Element> invoke(InvocationExpression invocation, Element target, ModelLevelExpressionEvaluator evaluator) {
39+
EList<Element> seq = evaluator.evaluateArgument(invocation, 0, target);
40+
EList<Element> values = evaluator.evaluateArgument(invocation, 1, target);
41+
Element index = evaluator.argumentValue(invocation, 2, target);
42+
if (seq == null || values == null || index == null) {
43+
return EvaluationUtil.singletonList(invocation);
44+
} else {
45+
Object indexValue = EvaluationUtil.valueOf(index);
46+
if (!(indexValue == null || indexValue instanceof Integer)) {
47+
return EvaluationUtil.singletonList(invocation);
48+
} else {
49+
int i = indexValue == null? seq.size(): ((Integer)indexValue) - 1;
50+
if (i < 0) {
51+
i = 0;
52+
}
53+
EList<Element> result = new BasicEList<>(seq.subList(0, i));
54+
result.addAll(values);
55+
result.addAll(seq.subList(i, seq.size()));
56+
return result;
57+
}
58+
}
59+
}
60+
61+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of theGNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.sequence;
22+
23+
public class IncludingFunction extends UnionFunction {
24+
25+
@Override
26+
public String getOperatorName() {
27+
return "including";
28+
}
29+
30+
}

0 commit comments

Comments
 (0)