-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSNode.java
More file actions
61 lines (48 loc) · 1.61 KB
/
Copy pathDNSNode.java
File metadata and controls
61 lines (48 loc) · 1.61 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
49
50
51
52
53
54
55
56
57
58
59
60
61
package ca.ubc.cs.cs317.dnslookup;
import java.io.Serializable;
/** DNS nodes can be used to specify an individual DNS query or the key to a specific result.
* Each node represents a fully-qualified domain name (represented by hostName) and a record
* type. Two nodes with the same host name and type are considered equal.
*/
public class DNSNode implements Comparable<DNSNode>, Serializable {
private String hostName;
private RecordType type;
public DNSNode(String hostName, RecordType type) {
this.hostName = hostName;
this.type = type;
}
public String getHostName() {
return hostName;
}
public RecordType getType() {
return type;
}
public void setHostName(String hostName){
this.hostName = hostName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DNSNode dnsNode = (DNSNode) o;
if (!hostName.equals(dnsNode.hostName)) return false;
return type == dnsNode.type;
}
@Override
public int hashCode() {
int result = hostName.hashCode();
result = 31 * result + type.hashCode();
return result;
}
@Override
public String toString() {
return hostName + " (" + type + ")";
}
@Override
public int compareTo(DNSNode o) {
if (!hostName.equalsIgnoreCase(o.hostName))
return hostName.compareToIgnoreCase(o.hostName);
else
return type.compareTo(o.type);
}
}