| 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.trmk.vcloud_0_8.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import org.jclouds.javax.annotation.Nullable; |
| 24 | |
| 25 | import com.google.common.base.CaseFormat; |
| 26 | |
| 27 | /** |
| 28 | * @author Adrian Cole |
| 29 | */ |
| 30 | public class IpAddress implements Comparable<IpAddress> { |
| 31 | |
| 32 | public static enum Status { |
| 33 | AVAILABLE, ASSIGNED, UNRECOGNIZED; |
| 34 | public String value() { |
| 35 | return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public String toString() { |
| 40 | return value(); |
| 41 | } |
| 42 | |
| 43 | public static Status fromValue(String status) { |
| 44 | try { |
| 45 | return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status"))); |
| 46 | } catch (IllegalArgumentException e) { |
| 47 | return UNRECOGNIZED; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | } |
| 52 | |
| 53 | private final String address; |
| 54 | private final Status status; |
| 55 | @Nullable |
| 56 | private final String server; |
| 57 | |
| 58 | public IpAddress(String address, Status status, String server) { |
| 59 | this.address = address; |
| 60 | this.status = status; |
| 61 | this.server = server; |
| 62 | } |
| 63 | |
| 64 | public String getAddress() { |
| 65 | return address; |
| 66 | } |
| 67 | |
| 68 | public Status getStatus() { |
| 69 | return status; |
| 70 | } |
| 71 | |
| 72 | public String getServer() { |
| 73 | return server; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public String toString() { |
| 78 | return "IpAddress [address=" + address + ", server=" + server + ", status=" + status + "]"; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public int compareTo(IpAddress o) { |
| 83 | return (this == o) ? 0 : getAddress().compareTo(o.getAddress()); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public int hashCode() { |
| 88 | final int prime = 31; |
| 89 | int result = 1; |
| 90 | result = prime * result + ((address == null) ? 0 : address.hashCode()); |
| 91 | result = prime * result + ((server == null) ? 0 : server.hashCode()); |
| 92 | result = prime * result + ((status == null) ? 0 : status.hashCode()); |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public boolean equals(Object obj) { |
| 98 | if (this == obj) |
| 99 | return true; |
| 100 | if (obj == null) |
| 101 | return false; |
| 102 | if (getClass() != obj.getClass()) |
| 103 | return false; |
| 104 | IpAddress other = (IpAddress) obj; |
| 105 | if (address == null) { |
| 106 | if (other.address != null) |
| 107 | return false; |
| 108 | } else if (!address.equals(other.address)) |
| 109 | return false; |
| 110 | if (server == null) { |
| 111 | if (other.server != null) |
| 112 | return false; |
| 113 | } else if (!server.equals(other.server)) |
| 114 | return false; |
| 115 | if (status == null) { |
| 116 | if (other.status != null) |
| 117 | return false; |
| 118 | } else if (!status.equals(other.status)) |
| 119 | return false; |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | } |