| 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 | */ |
| 19 | package org.jclouds.ec2.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | /** |
| 24 | * |
| 25 | * @see <a href= |
| 26 | * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-UserIdGroupPairType.html" |
| 27 | * /> |
| 28 | * @author Adrian Cole |
| 29 | */ |
| 30 | public class UserIdGroupPair implements Comparable<UserIdGroupPair> { |
| 31 | private final String userId; |
| 32 | private final String groupName; |
| 33 | |
| 34 | public UserIdGroupPair(String userId, String groupName) { |
| 35 | this.userId = checkNotNull(userId,"userId"); |
| 36 | this.groupName = checkNotNull(groupName,"groupName"); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | @Override |
| 41 | public String toString() { |
| 42 | return "[userId=" + userId + ", groupName=" + groupName + "]"; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | * {@inheritDoc} |
| 48 | */ |
| 49 | public int compareTo(UserIdGroupPair o) { |
| 50 | return (this == o) ? 0 : getUserId().compareTo(o.getUserId()); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * AWS User ID of an identity. Cannot be used when specifying a CIDR IP address. |
| 56 | */ |
| 57 | public String getUserId() { |
| 58 | return userId; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | /** |
| 63 | * Name of the security group. Cannot be used when specifying a CIDR IP address. |
| 64 | */ |
| 65 | public String getGroupName() { |
| 66 | return groupName; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | final int prime = 31; |
| 73 | int result = 1; |
| 74 | result = prime * result + ((groupName == null) ? 0 : groupName.hashCode()); |
| 75 | result = prime * result + ((userId == null) ? 0 : userId.hashCode()); |
| 76 | return result; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | @Override |
| 81 | public boolean equals(Object obj) { |
| 82 | if (this == obj) |
| 83 | return true; |
| 84 | if (obj == null) |
| 85 | return false; |
| 86 | if (getClass() != obj.getClass()) |
| 87 | return false; |
| 88 | UserIdGroupPair other = (UserIdGroupPair) obj; |
| 89 | if (groupName == null) { |
| 90 | if (other.groupName != null) |
| 91 | return false; |
| 92 | } else if (!groupName.equals(other.groupName)) |
| 93 | return false; |
| 94 | if (userId == null) { |
| 95 | if (other.userId != null) |
| 96 | return false; |
| 97 | } else if (!userId.equals(other.userId)) |
| 98 | return false; |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | } |