blob: 12da948eca546b53e03e9582bb581a2d6ce014d4 (
plain)
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
96
97
98
99
100
101
102
103
104
105
|
/**
*
*/
package com.galois.fiveui;
import java.io.File;
import java.io.IOException;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
/**
* A singular url to test with a RuleSet.
*
* @author bjones
*/
public class HeadlessAtom {
private String _url;
private RuleSet _ruleSet;
public HeadlessAtom(String url, RuleSet ruleSet) {
_url = url;
_ruleSet = ruleSet;
}
public String getURL() {
return _url;
}
public RuleSet getRuleSet() {
return _ruleSet;
}
public String toString() {
Gson gson = new Gson();
return gson.toJson(this);
}
/**
* Construct a HeadlessAtom from a JsonObject
*
* @param obj JsonObject to convert from
* @param dir parent directory of the filenames referenced in the ruleSet field
* @return a HeadlessAtom POJO
* @throws IOException
* @throws JsonParseException
*/
public static HeadlessAtom fromJsonObject(JsonObject obj, String dir) throws IOException {
String url = null;
String ruleSet = null;
try {
url = obj.get("url").getAsString();
} catch (NullPointerException e) {
}
try {
ruleSet = obj.get("ruleSet").getAsString();
} catch (NullPointerException e) {
}
if (url == null || ruleSet == null) {
throw new JsonParseException("could get either 'url' or 'ruleSet' properties");
}
String rsPath = dir + File.separator + ruleSet;
RuleSet parsed = RuleSet.parseFile(rsPath);
return new HeadlessAtom(url, parsed);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((_url == null) ? 0 : _url.hashCode());
result = prime * result + ((_ruleSet == null) ? 0 : _ruleSet.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
HeadlessAtom other = (HeadlessAtom) obj;
if (_url == null) {
if (other._url != null)
return false;
} else if (!_url.equals(other._url))
return false;
if (_ruleSet == null) {
if (other._ruleSet != null)
return false;
} else if (!_ruleSet.equals(other._ruleSet))
return false;
return true;
}
}
|