-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClosure.java
More file actions
51 lines (39 loc) · 997 Bytes
/
Copy pathClosure.java
File metadata and controls
51 lines (39 loc) · 997 Bytes
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
package data;
import syntaxtree.*;
public class Closure implements Value {
private Function fun;
private Env env;
public Closure(Function f, Env e){
fun = f;
env = e;
}
public Env getEnv(){
return env;
}
public Function getFunction(){
return fun;
}
public int compareTo(Value v){
int classCompare = getClass().getName().compareTo(v.getClass().getName());
if (classCompare != 0){
return classCompare;
}
Closure c = (Closure) v;
return fun.compareTo(c.getFunction());
}
public int hashCode(){
final int PRIME = 31;
int result = 1;
result = PRIME * result + ( (fun == null) ? 0 : fun.hashCode());
result = PRIME * result + ( (env == null) ? 0 : env.hashCode());
return result;
}
public boolean equals(Object o){
if (this == o ) return true;
if (o == null ) return false;
if (getClass() != o.getClass()) return false;
Closure c = (Closure) o;
if(!fun.equals(c.getFunction())) return false;
return env.equals(c.getEnv());
}
}