EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.ec2.domain]

COVERAGE SUMMARY FOR SOURCE FILE [IpPermissionImpl.java]

nameclass, %method, %block, %line, %
IpPermissionImpl.java50%  (1/2)38%  (9/24)46%  (175/384)45%  (36.7/82)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class IpPermissionImpl$Builder0%   (0/1)0%   (0/11)0%   (0/86)0%   (0/23)
IpPermissionImpl$Builder (): void 0%   (0/1)0%   (0/12)0%   (0/4)
build (): IpPermission 0%   (0/1)0%   (0/16)0%   (0/1)
fromPort (int): IpPermissionImpl$Builder 0%   (0/1)0%   (0/5)0%   (0/2)
groupId (String): IpPermissionImpl$Builder 0%   (0/1)0%   (0/7)0%   (0/2)
groupIds (Iterable): IpPermissionImpl$Builder 0%   (0/1)0%   (0/7)0%   (0/2)
ipProtocol (IpProtocol): IpPermissionImpl$Builder 0%   (0/1)0%   (0/5)0%   (0/2)
ipRange (String): IpPermissionImpl$Builder 0%   (0/1)0%   (0/7)0%   (0/2)
ipRanges (Iterable): IpPermissionImpl$Builder 0%   (0/1)0%   (0/7)0%   (0/2)
toPort (int): IpPermissionImpl$Builder 0%   (0/1)0%   (0/5)0%   (0/2)
userIdGroupPair (String, String): IpPermissionImpl$Builder 0%   (0/1)0%   (0/8)0%   (0/2)
userIdGroupPairs (Multimap): IpPermissionImpl$Builder 0%   (0/1)0%   (0/7)0%   (0/2)
     
class IpPermissionImpl100% (1/1)69%  (9/13)59%  (175/298)62%  (36.7/59)
builder (): IpPermissionImpl$Builder 0%   (0/1)0%   (0/4)0%   (0/1)
compareTo (IpPermission): int 0%   (0/1)0%   (0/11)0%   (0/1)
getGroups (): Set 0%   (0/1)0%   (0/30)0%   (0/4)
toString (): String 0%   (0/1)0%   (0/37)0%   (0/1)
equals (Object): boolean 100% (1/1)63%  (57/90)48%  (14/29)
hashCode (): int 100% (1/1)89%  (64/72)96%  (8.7/9)
IpPermissionImpl (IpProtocol, int, int, Multimap, Iterable, Iterable): void 100% (1/1)100% (36/36)100% (8/8)
getFromPort (): int 100% (1/1)100% (3/3)100% (1/1)
getGroupIds (): Set 100% (1/1)100% (3/3)100% (1/1)
getIpProtocol (): IpProtocol 100% (1/1)100% (3/3)100% (1/1)
getIpRanges (): Set 100% (1/1)100% (3/3)100% (1/1)
getToPort (): int 100% (1/1)100% (3/3)100% (1/1)
getUserIdGroupPairs (): Multimap 100% (1/1)100% (3/3)100% (1/1)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.ec2.domain;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Map.Entry;
24import java.util.Set;
25 
26import com.google.common.collect.ImmutableMultimap;
27import com.google.common.collect.ImmutableSet;
28import com.google.common.collect.Iterables;
29import com.google.common.collect.LinkedHashMultimap;
30import com.google.common.collect.Multimap;
31import com.google.common.collect.Sets;
32 
33/**
34 * 
35 * @see <a href=
36 *      "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-IpPermissionType.html"
37 *      />
38 * @author Adrian Cole
39 */
40public class IpPermissionImpl implements IpPermission {
41   public static Builder builder() {
42      return new Builder();
43   }
44 
45   public static class Builder {
46      private int fromPort;
47      private int toPort;
48      private IpProtocol ipProtocol;
49      private Multimap<String, String> userIdGroupPairs = LinkedHashMultimap.create();
50      private Set<String> groupIds = Sets.newLinkedHashSet();
51      private Set<String> ipRanges = Sets.newLinkedHashSet();
52 
53      public Builder fromPort(int fromPort) {
54         this.fromPort = fromPort;
55         return this;
56      }
57 
58      public Builder toPort(int toPort) {
59         this.fromPort = toPort;
60         return this;
61      }
62 
63      public Builder ipProtocol(IpProtocol ipProtocol) {
64         this.ipProtocol = ipProtocol;
65         return this;
66      }
67 
68      public Builder userIdGroupPair(String userId, String groupNameOrId) {
69         this.userIdGroupPairs.put(userId, groupNameOrId);
70         return this;
71      }
72 
73      public Builder userIdGroupPairs(Multimap<String, String> userIdGroupPairs) {
74         this.userIdGroupPairs.putAll(userIdGroupPairs);
75         return this;
76      }
77 
78      public Builder ipRange(String ipRange) {
79         this.ipRanges.add(ipRange);
80         return this;
81      }
82 
83      public Builder ipRanges(Iterable<String> ipRanges) {
84         Iterables.addAll(this.ipRanges, ipRanges);
85         return this;
86      }
87 
88      public Builder groupId(String groupId) {
89         this.groupIds.add(groupId);
90         return this;
91      }
92 
93      public Builder groupIds(Iterable<String> groupIds) {
94         Iterables.addAll(this.groupIds, groupIds);
95         return this;
96      }
97 
98      public IpPermission build() {
99         return new IpPermissionImpl(ipProtocol, fromPort, toPort, userIdGroupPairs, groupIds, ipRanges);
100      }
101   }
102 
103   private final int fromPort;
104   private final int toPort;
105   private final Multimap<String, String> userIdGroupPairs;
106   private final Set<String> groupIds;
107   private final IpProtocol ipProtocol;
108   private final Set<String> ipRanges;
109 
110   public IpPermissionImpl(IpProtocol ipProtocol, int fromPort, int toPort,
111         Multimap<String, String> userIdGroupPairs, Iterable<String> groupIds, Iterable<String> ipRanges) {
112      this.fromPort = fromPort;
113      this.toPort = toPort;
114      this.userIdGroupPairs = ImmutableMultimap.copyOf(checkNotNull(userIdGroupPairs, "userIdGroupPairs"));
115      this.ipProtocol = checkNotNull(ipProtocol, "ipProtocol");
116      this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds"));
117      this.ipRanges = ImmutableSet.copyOf(checkNotNull(ipRanges, "ipRanges"));
118   }
119 
120   /**
121    * {@inheritDoc}
122    */
123   public int compareTo(IpPermission o) {
124      return (this == o) ? 0 : getIpProtocol().compareTo(o.getIpProtocol());
125   }
126 
127   /**
128    * {@inheritDoc}
129    */
130   @Override
131   public int getFromPort() {
132      return fromPort;
133   }
134 
135   /**
136    * {@inheritDoc}
137    */
138   @Override
139   public int getToPort() {
140      return toPort;
141   }
142 
143   /**
144    * {@inheritDoc}
145    */
146   @Override
147   @Deprecated
148   public Set<UserIdGroupPair> getGroups() {
149      ImmutableSet.Builder<UserIdGroupPair> groups = ImmutableSet.<UserIdGroupPair> builder();
150      for (Entry<String, String> pair : userIdGroupPairs.entries())
151         groups.add(new UserIdGroupPair(pair.getKey(), pair.getValue()));
152      return groups.build();
153   }
154 
155   /**
156    * {@inheritDoc}
157    */
158   @Override
159   public Multimap<String, String> getUserIdGroupPairs() {
160      return userIdGroupPairs;
161   }
162 
163   /**
164    * {@inheritDoc}
165    */
166   @Override
167   public Set<String> getGroupIds() {
168      return groupIds;
169   }
170 
171   /**
172    * {@inheritDoc}
173    */
174   @Override
175   public IpProtocol getIpProtocol() {
176      return ipProtocol;
177   }
178 
179   /**
180    * {@inheritDoc}
181    */
182   @Override
183   public Set<String> getIpRanges() {
184      return ipRanges;
185   }
186 
187   @Override
188   public int hashCode() {
189      final int prime = 31;
190      int result = 1;
191      result = prime * result + fromPort;
192      result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode());
193      result = prime * result + ((ipProtocol == null) ? 0 : ipProtocol.hashCode());
194      result = prime * result + ((ipRanges == null) ? 0 : ipRanges.hashCode());
195      result = prime * result + toPort;
196      result = prime * result + ((userIdGroupPairs == null) ? 0 : userIdGroupPairs.hashCode());
197      return result;
198   }
199 
200   @Override
201   public boolean equals(Object obj) {
202      if (this == obj)
203         return true;
204      if (obj == null)
205         return false;
206      if (getClass() != obj.getClass())
207         return false;
208      IpPermissionImpl other = (IpPermissionImpl) obj;
209      if (fromPort != other.fromPort)
210         return false;
211      if (groupIds == null) {
212         if (other.groupIds != null)
213            return false;
214      } else if (!groupIds.equals(other.groupIds))
215         return false;
216      if (ipProtocol != other.ipProtocol)
217         return false;
218      if (ipRanges == null) {
219         if (other.ipRanges != null)
220            return false;
221      } else if (!ipRanges.equals(other.ipRanges))
222         return false;
223      if (toPort != other.toPort)
224         return false;
225      if (userIdGroupPairs == null) {
226         if (other.userIdGroupPairs != null)
227            return false;
228      } else if (!userIdGroupPairs.equals(other.userIdGroupPairs))
229         return false;
230      return true;
231   }
232 
233   @Override
234   public String toString() {
235      return "[fromPort=" + fromPort + ", toPort=" + toPort + ", userIdGroupPairs=" + userIdGroupPairs + ", groupIds="
236            + groupIds + ", ipProtocol=" + ipProtocol + ", ipRanges=" + ipRanges + "]";
237   }
238 
239}

[all classes][org.jclouds.ec2.domain]
EMMA 2.0.5312 (C) Vladimir Roubtsov