| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * 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, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 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 | /** |
| 41 | * {@inheritDoc} |
| 42 | */ |
| 43 | public int compareTo(UserIdGroupPair o) { |
| 44 | return (this == o) ? 0 : getUserId().compareTo(o.getUserId()); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /** |
| 49 | * AWS User ID of an identity. Cannot be used when specifying a CIDR IP address. |
| 50 | */ |
| 51 | public String getUserId() { |
| 52 | return userId; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /** |
| 57 | * Name of the security group. Cannot be used when specifying a CIDR IP address. |
| 58 | */ |
| 59 | public String getGroupName() { |
| 60 | return groupName; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | @Override |
| 65 | public int hashCode() { |
| 66 | final int prime = 31; |
| 67 | int result = 1; |
| 68 | result = prime * result + ((groupName == null) ? 0 : groupName.hashCode()); |
| 69 | result = prime * result + ((userId == null) ? 0 : userId.hashCode()); |
| 70 | return result; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | @Override |
| 75 | public boolean equals(Object obj) { |
| 76 | if (this == obj) |
| 77 | return true; |
| 78 | if (obj == null) |
| 79 | return false; |
| 80 | if (getClass() != obj.getClass()) |
| 81 | return false; |
| 82 | UserIdGroupPair other = (UserIdGroupPair) obj; |
| 83 | if (groupName == null) { |
| 84 | if (other.groupName != null) |
| 85 | return false; |
| 86 | } else if (!groupName.equals(other.groupName)) |
| 87 | return false; |
| 88 | if (userId == null) { |
| 89 | if (other.userId != null) |
| 90 | return false; |
| 91 | } else if (!userId.equals(other.userId)) |
| 92 | return false; |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | } |