1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.cloudloadbalancers.domain;
20
21 import static com.google.common.base.Preconditions.checkArgument;
22 import static com.google.common.base.Preconditions.checkNotNull;
23
24
25
26
27
28
29
30
31
32
33
34 public class VirtualIP implements Comparable<VirtualIP> {
35 public static Builder builder() {
36 return new Builder();
37 }
38
39 public static class Builder {
40 private int id = -1;
41 private String address;
42 private Type type;
43 private IPVersion ipVersion = IPVersion.IPV4;
44
45 public Builder id(int id) {
46 this.id = id;
47 return this;
48 }
49
50 public Builder address(String address) {
51 this.address = address;
52 return this;
53 }
54
55 public Builder type(Type type) {
56 this.type = type;
57 return this;
58 }
59
60 public Builder ipVersion(IPVersion ipVersion) {
61 this.ipVersion = ipVersion;
62 return this;
63 }
64
65 public VirtualIP build() {
66 return new VirtualIP(id, address, type, ipVersion);
67 }
68 }
69
70
71
72
73 public static enum Type {
74
75
76
77 PUBLIC,
78
79
80
81 SERVICENET, UNRECOGNIZED;
82
83 public static Type fromValue(String type) {
84 try {
85 return valueOf(checkNotNull(type, "type"));
86 } catch (IllegalArgumentException e) {
87 return UNRECOGNIZED;
88 }
89 }
90
91 }
92
93
94
95
96 public static enum IPVersion {
97
98 IPV4, IPV6, UNRECOGNIZED;
99
100 public static IPVersion fromValue(String ipVersion) {
101 try {
102 return valueOf(checkNotNull(ipVersion, "ipVersion"));
103 } catch (IllegalArgumentException e) {
104 return UNRECOGNIZED;
105 }
106 }
107
108 }
109
110
111 VirtualIP() {
112
113 }
114
115 private int id;
116 private String address;
117 private Type type;
118 private IPVersion ipVersion;
119
120 public VirtualIP(int id, String address, Type type, IPVersion ipVersion) {
121 checkArgument(id != -1, "id must be specified");
122 this.id = id;
123 this.address = checkNotNull(address, "address");
124 this.type = checkNotNull(type, "type");
125 this.ipVersion = checkNotNull(ipVersion, "ipVersion");
126 }
127
128 public int getId() {
129 return id;
130 }
131
132 public String getAddress() {
133 return address;
134 }
135
136 public Type getType() {
137 return type;
138 }
139
140 public IPVersion getIpVersion() {
141 return ipVersion;
142 }
143
144 @Override
145 public int compareTo(VirtualIP arg0) {
146 return address.compareTo(arg0.address);
147 }
148
149 @Override
150 public int hashCode() {
151 final int prime = 31;
152 int result = 1;
153 result = prime * result + id;
154 return result;
155 }
156
157 @Override
158 public boolean equals(Object obj) {
159 if (this == obj)
160 return true;
161 if (obj == null)
162 return false;
163 if (getClass() != obj.getClass())
164 return false;
165 VirtualIP other = (VirtualIP) obj;
166 if (id != other.id)
167 return false;
168 return true;
169 }
170
171 @Override
172 public String toString() {
173 return String.format("[address=%s, id=%s, ipVersion=%s, type=%s]", address, id, ipVersion, type);
174 }
175
176 }