-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBSetComprehension.java
95 lines (82 loc) · 2.5 KB
/
BSetComprehension.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.util.Vector;
/* Package: B AMN */
/******************************
* Copyright (c) 2003,2019 Kevin Lano
* 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
* *****************************/
public class BSetComprehension extends BExpression
{ private String variable;
private Vector variables = new Vector();
private BExpression range;
private BExpression predicate;
public BSetComprehension(String var, String ran,
BExpression pred)
{ variable = var;
range = new BBasicExpression(ran);
predicate = pred;
}
public BSetComprehension(String var, BExpression ran,
BExpression pred)
{ variable = var;
range = ran;
predicate = pred;
}
public BSetComprehension(Vector vars, BExpression pred)
{ variables = vars;
predicate = pred;
variable = null;
}
public BSetComprehension(Vector vars, BExpression ran, BExpression pred)
{ variables = vars;
variable = null;
predicate = pred;
range = ran;
}
public Vector rd()
{ Vector res = predicate.rd();
if (range != null)
{ res = VectorUtil.union(res,range.rd()); }
Vector vars = new Vector();
vars.addAll(variables);
vars.add(variable);
res.removeAll(vars);
return res;
}
public boolean setValued()
{ return true; }
public BExpression simplify()
{ BExpression sp = predicate.simplify();
if ((sp + "").equals("false"))
{ return new BSetExpression(); }
if (variable != null)
{ return new BSetComprehension(variable,range,sp); }
else
{ return new BSetComprehension(variables,sp); }
} // pred being false yields empty set, etc.
public BExpression substituteEq(String oldE, BExpression newE)
{ if (oldE.equals(toString()))
{ return newE; }
return this;
}
public String toString()
{ if (variable != null)
{ return "{ " + variable + " | " + variable + " : " + range + " & " +
predicate + " }";
}
else
{ String res = "{ ";
for (int i = 0; i < variables.size(); i++)
{ String var = (String) variables.get(i);
res = res + var;
if (i < variables.size() - 1)
{ res = res + ","; }
}
res = res + " | " + predicate + " }";
return res;
}
}
}