1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.vcloud.domain.network;
20
21 import static com.google.common.base.Preconditions.checkNotNull;
22
23 import java.util.List;
24
25 import javax.annotation.Nullable;
26
27 import org.jclouds.vcloud.domain.network.nat.NatPolicy;
28 import org.jclouds.vcloud.domain.network.nat.NatRule;
29 import org.jclouds.vcloud.domain.network.nat.NatType;
30
31 import com.google.common.collect.Iterables;
32 import com.google.common.collect.Lists;
33
34
35
36
37 public class NatService {
38 private final boolean enabled;
39 @Nullable
40 private final NatType type;
41 @Nullable
42 private final NatPolicy policy;
43 private final List<NatRule> natRules = Lists.newArrayList();
44
45 public NatService(boolean enabled, @Nullable NatType type, @Nullable NatPolicy policy,
46 Iterable<? extends NatRule> natRules) {
47 this.enabled = enabled;
48 this.type = type;
49 this.policy = policy;
50 Iterables.addAll(this.natRules, checkNotNull(natRules, "natRules"));
51 }
52
53
54
55
56
57
58 public List<? extends NatRule> getNatRules() {
59 return natRules;
60 }
61
62
63
64
65
66
67 public boolean isEnabled() {
68 return enabled;
69 }
70
71
72
73
74
75
76 @Nullable
77 public NatType getType() {
78 return type;
79 }
80
81
82
83
84
85
86 @Nullable
87 public NatPolicy getPolicy() {
88 return policy;
89 }
90
91 @Override
92 public int hashCode() {
93 final int prime = 31;
94 int result = 1;
95 result = prime * result + (enabled ? 1231 : 1237);
96 result = prime * result + ((natRules == null) ? 0 : natRules.hashCode());
97 result = prime * result + ((policy == null) ? 0 : policy.hashCode());
98 result = prime * result + ((type == null) ? 0 : type.hashCode());
99 return result;
100 }
101
102 @Override
103 public boolean equals(Object obj) {
104 if (this == obj)
105 return true;
106 if (obj == null)
107 return false;
108 if (getClass() != obj.getClass())
109 return false;
110 NatService other = (NatService) obj;
111 if (enabled != other.enabled)
112 return false;
113 if (natRules == null) {
114 if (other.natRules != null)
115 return false;
116 } else if (!natRules.equals(other.natRules))
117 return false;
118 if (policy == null) {
119 if (other.policy != null)
120 return false;
121 } else if (!policy.equals(other.policy))
122 return false;
123 if (type == null) {
124 if (other.type != null)
125 return false;
126 } else if (!type.equals(other.type))
127 return false;
128 return true;
129 }
130
131 @Override
132 public String toString() {
133 return "[enabled=" + enabled + ", natRules=" + natRules + ", policy=" + policy + ", type=" + type + "]";
134 }
135
136 }