~cpn-gui/tapaal/typeChecker

« back to all changes in this revision

Viewing changes to src/dk/aau/cs/model/tapn/Colored/Expressions/NumberOfExpression.java

  • Committer: Mark Glavind
  • Date: 2018-12-17 19:55:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1001.
  • Revision ID: mglavi14@student.aau.dk-20181217195519-5jidq02dtjknclth
WIP on colored arc editor panel

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import dk.aau.cs.model.tapn.Colored.Color;
4
4
import dk.aau.cs.model.tapn.Colored.ColorMultiset;
5
5
import dk.aau.cs.model.tapn.Colored.ColorType;
 
6
import dk.aau.cs.model.tapn.Colored.ExpressionSupport.ExprStringPosition;
6
7
import dk.aau.cs.model.tapn.Colored.Variable;
7
8
 
8
9
import java.util.Iterator;
26
27
        this.all = all;
27
28
    }
28
29
 
 
30
    @Override
 
31
    public ArcExpression replace(Expression object1, Expression object2) {
 
32
        if (object1 == this && object2 instanceof ArcExpression) {
 
33
            ArcExpression obj2 = (ArcExpression) object2;
 
34
            obj2.setParent(parent);
 
35
            return obj2;
 
36
        }
 
37
        else {
 
38
            if (all != null) {
 
39
                all = all.replace(object1, object2);
 
40
                return this;
 
41
            }
 
42
            else {
 
43
                for (int i = 0; i < color.size(); i++) {
 
44
                    color.set(i, color.get(i).replace(object1, object2));
 
45
                }
 
46
                return this;
 
47
            }
 
48
        }
 
49
    }
 
50
 
29
51
    public ColorMultiset eval(ExpressionContext context) {
30
52
        if (all == null) {
31
53
            assert(!color.isEmpty());
61
83
    }
62
84
 
63
85
    @Override
64
 
    public Expression replace(Expression object1, Expression object2) {
65
 
        return null;
66
 
    }
67
 
 
68
 
    @Override
69
 
    public Expression copy() {
70
 
        return null;
 
86
    public ArcExpression copy() {
 
87
        if (all != null) {
 
88
            return new NumberOfExpression(number, all);
 
89
        } else
 
90
        return new NumberOfExpression(number, color);
71
91
    }
72
92
 
73
93
    @Override
74
94
    public boolean containsPlaceHolder() {
75
 
        return false;
 
95
        if (all != null) {
 
96
            return false;
 
97
        } else {
 
98
            for (ColorExpression expr : color) {
 
99
                if (expr.containsPlaceHolder()) {
 
100
                    return false;
 
101
                }
 
102
            }
 
103
            return false;
 
104
        }
76
105
    }
77
106
 
78
107
    @Override
79
 
    public Expression findFirstPlaceHolder() {
80
 
        return null;
 
108
    public ArcExpression findFirstPlaceHolder() {
 
109
        if (all != null) {
 
110
            return null;
 
111
        } else {
 
112
            for (ColorExpression expr : color) {
 
113
                if (expr.containsPlaceHolder()) {
 
114
                    return null;
 
115
                //  return expr.findFirstPlaceHolder();
 
116
                }
 
117
            }
 
118
            return null;
 
119
        }
81
120
    }
82
121
 
83
122
    public void getVariables(Set<Variable> variables) {
101
140
        return res;
102
141
    }
103
142
 
 
143
    public ExprStringPosition[] getChildren() {
 
144
        if (all != null) {
 
145
            ExprStringPosition[] children = new ExprStringPosition[2];
 
146
            int endPrev = 0;
 
147
            boolean wasPrevSimple = false;
 
148
 
 
149
            int start = 0;
 
150
            int end = 0;
 
151
 
 
152
            end = start + all.toString().length() + 3;
 
153
            endPrev = end;
 
154
            ExprStringPosition pos = new ExprStringPosition(start, end, all);
 
155
            children[0] = pos;
 
156
            return children;
 
157
        }
 
158
        else {
 
159
            ExprStringPosition[] children = new ExprStringPosition[color.size()];
 
160
 
 
161
            int i = 0;
 
162
            int endPrev = 0;
 
163
            boolean wasPrevSimple = false;
 
164
            for (ColorExpression p : color) {
 
165
 
 
166
                int start = 0;
 
167
                int end = 0;
 
168
 
 
169
                if (i == 0) {
 
170
                    wasPrevSimple = p.isSimpleProperty();
 
171
                    start = wasPrevSimple ? 0 : 1;
 
172
                    end = start + p.toString().length();
 
173
 
 
174
                    endPrev = end;
 
175
 
 
176
                } else {
 
177
                    start = endPrev + 3 + (p.isSimpleProperty() ? 0 : 1)
 
178
                            + (wasPrevSimple ? 0 : 1);
 
179
                    end = start + p.toString().length();
 
180
 
 
181
                    endPrev = end;
 
182
                    wasPrevSimple = p.isSimpleProperty();
 
183
                }
 
184
 
 
185
                ExprStringPosition pos = new ExprStringPosition(start, end, p);
 
186
 
 
187
                children[i] = pos;
 
188
                i++;
 
189
            }
 
190
 
 
191
            return children;
 
192
        }
 
193
 
 
194
    }
 
195
 
104
196
}