-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathName.java
58 lines (47 loc) · 1.2 KB
/
Name.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
import java.util.HashSet;
public class Name implements Expression{
private String value;
public Name(String val){
value = val;
}
public Expression copy() {
return new Name(value);
}
public boolean equals(Object other) {
if(other instanceof Name){
Name o = (Name) other;
return value.equals(o.value);
}
return false;
}
@Override
public Expression alphaConvert(String from, String to, boolean capture) {
if (capture && from.equals(value)){
return new Name(to);
}
return copy();
}
@Override
public HashSet<String> allVariables() {
HashSet<String> var = new HashSet<>();
var.add(value);
return var;
}
@Override
public HashSet<String> boundVariables() {
return new HashSet<>();
}
@Override
public Expression eval() {
return this;
}
@Override
public Expression replace(String from, Expression to) {
if (this.value.equals(from))
return to;
return this;
}
public String toString(){
return value;
}
}