-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary.java
More file actions
48 lines (40 loc) · 1.36 KB
/
Copy pathDictionary.java
File metadata and controls
48 lines (40 loc) · 1.36 KB
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
// Kimberley Ni and Eylul Oktay
import java.util.HashMap;
import java.util.Map.Entry;
public class Dictionary {
public static HashMap<String, Expression> map;
public static String lastResultString;
public Dictionary() {
map = new HashMap<>();
lastResultString = "";
}
public static void addVals(String storedVarStr, Expression storedExp) {
if (!map.containsKey(storedVarStr)) {
map.put(storedVarStr, storedExp);
lastResultString = "Added " + storedExp.toString() + " as " + storedVarStr + ".";
} else {
lastResultString = storedVarStr + " is already defined.";
}
}
public static Boolean containsKey(String storedVarStr) {
return map.containsKey(storedVarStr);
}
public static Expression get(String storedVarStr) {
return map.get(storedVarStr);
}
public static Expression getKey(Expression exp) {
for (Entry<String, Expression> entry : map.entrySet()) {
if (exp.equals(entry.getValue())) {
return new Variable(entry.getKey());
}
}
return exp;
}
/*
* Logging from Dictionary, namely "Added value as variable"
* Alternatively, string could be "variable is already defined."
*/
public static String lastVariableAssignResult() {
return lastResultString;
}
}