| 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.gogrid.domain; |
| 20 | |
| 21 | import com.google.common.primitives.Longs; |
| 22 | import com.google.gson.annotations.SerializedName; |
| 23 | |
| 24 | /** |
| 25 | * @author Oleksiy Yarmula |
| 26 | */ |
| 27 | public class Ip implements Comparable<Ip> { |
| 28 | |
| 29 | private long id; |
| 30 | |
| 31 | private String ip; |
| 32 | private String subnet; |
| 33 | @SerializedName("public") |
| 34 | private boolean isPublic; |
| 35 | private IpState state; |
| 36 | private Option datacenter; |
| 37 | |
| 38 | /** |
| 39 | * A no-args constructor is required for deserialization |
| 40 | */ |
| 41 | public Ip() { |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Constructs a generic IP address without any additional options. |
| 46 | * |
| 47 | * @param ip |
| 48 | * ip address |
| 49 | */ |
| 50 | public Ip(String ip) { |
| 51 | this.ip = ip; |
| 52 | } |
| 53 | |
| 54 | public Ip(long id, String ip, String subnet, boolean isPublic, IpState state, Option datacenter) { |
| 55 | this.id = id; |
| 56 | this.ip = ip; |
| 57 | this.subnet = subnet; |
| 58 | this.isPublic = isPublic; |
| 59 | this.state = state; |
| 60 | this.datacenter = datacenter; |
| 61 | } |
| 62 | |
| 63 | public long getId() { |
| 64 | return id; |
| 65 | } |
| 66 | |
| 67 | public Option getDatacenter() { |
| 68 | return datacenter; |
| 69 | } |
| 70 | |
| 71 | public String getIp() { |
| 72 | return ip; |
| 73 | } |
| 74 | |
| 75 | public String getSubnet() { |
| 76 | return subnet; |
| 77 | } |
| 78 | |
| 79 | public boolean isPublic() { |
| 80 | return isPublic; |
| 81 | } |
| 82 | |
| 83 | public IpState getState() { |
| 84 | return state; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public boolean equals(Object obj) { |
| 89 | if (this == obj) |
| 90 | return true; |
| 91 | if (obj == null) |
| 92 | return false; |
| 93 | if (getClass() != obj.getClass()) |
| 94 | return false; |
| 95 | Ip other = (Ip) obj; |
| 96 | if (datacenter == null) { |
| 97 | if (other.datacenter != null) |
| 98 | return false; |
| 99 | } else if (!datacenter.equals(other.datacenter)) |
| 100 | return false; |
| 101 | if (id != other.id) |
| 102 | return false; |
| 103 | if (ip == null) { |
| 104 | if (other.ip != null) |
| 105 | return false; |
| 106 | } else if (!ip.equals(other.ip)) |
| 107 | return false; |
| 108 | if (isPublic != other.isPublic) |
| 109 | return false; |
| 110 | if (state == null) { |
| 111 | if (other.state != null) |
| 112 | return false; |
| 113 | } else if (!state.equals(other.state)) |
| 114 | return false; |
| 115 | if (subnet == null) { |
| 116 | if (other.subnet != null) |
| 117 | return false; |
| 118 | } else if (!subnet.equals(other.subnet)) |
| 119 | return false; |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public int hashCode() { |
| 125 | final int prime = 31; |
| 126 | int result = 1; |
| 127 | result = prime * result + ((datacenter == null) ? 0 : datacenter.hashCode()); |
| 128 | result = prime * result + (int) (id ^ (id >>> 32)); |
| 129 | result = prime * result + ((ip == null) ? 0 : ip.hashCode()); |
| 130 | result = prime * result + (isPublic ? 1231 : 1237); |
| 131 | result = prime * result + ((state == null) ? 0 : state.hashCode()); |
| 132 | result = prime * result + ((subnet == null) ? 0 : subnet.hashCode()); |
| 133 | return result; |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public String toString() { |
| 138 | return "Ip [datacenter=" + datacenter + ", id=" + id + ", ip=" + ip + ", isPublic=" |
| 139 | + isPublic + ", state=" + state + ", subnet=" + subnet + "]"; |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public int compareTo(Ip o) { |
| 144 | return Longs.compare(id, o.getId()); |
| 145 | } |
| 146 | } |