-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSIPImpl.java
More file actions
92 lines (83 loc) · 1.96 KB
/
DNSIPImpl.java
File metadata and controls
92 lines (83 loc) · 1.96 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
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
/**
* Basic implementation of DNSIP
*
* @author Chris Blades
* @version 3/16/2010
*/
public class DNSIPImpl extends AbstractDNSObject implements DNSIP {
/**
* The String representation of this IP
*/
private String ip;
/**
* Creates a new IP with the loopback address
*/
public DNSIPImpl() {
this("127.0.0.1");
}
/**
* Creates a new DNSIP with the given ip
*
* @param ip the IP address this DNSIP should wrap
*/
public DNSIPImpl(String ip) {
this.ip = ip;
}
/**
* Changes the IP the DNSIP object wraps.
*
* @param IP the new IP
*/
public void setIP(String ip) {
this.ip = ip;
changed = true;
}
/**
* Returns a string representation of this IP.
*
* @return a string representation of this IP
*/
public String getData() {
return this.ip;
}
/**
* Return this IP as an array of bytes.
*
* @return this IP as an array of bytes
*/
public byte[] serialize() {
generateTransient();
return this.serialized;
}
/**
* Return a mapping of state values of this IP
*
* @return the state values of this DNSIP
*/
public Map stateValues() {
generateTransient();
return this.values;
}
/**
* Generate serialized and values if there has been change to the
* state of this DNSIP.
*/
public void generateTransient() {
if (changed) {
//
// generate serialized
//
serialized = new byte[4];
String[] parts = ip.split("\\.");
for (int i = 0; i < parts.length && i < serialized.length; i++) {
serialized[i] = (byte)Integer.parseInt(parts[i]);
}
//
// generate values
//
values.clear();
values.put("IP", this.ip);
changed = false;
}
}
}