| 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 java.util.Set; |
| 22 | |
| 23 | import com.google.common.primitives.Longs; |
| 24 | import com.google.gson.annotations.SerializedName; |
| 25 | |
| 26 | /** |
| 27 | * @author Oleksiy Yarmula |
| 28 | */ |
| 29 | public class LoadBalancer implements Comparable<LoadBalancer> { |
| 30 | |
| 31 | private long id; |
| 32 | private String name; |
| 33 | private String description; |
| 34 | @SerializedName("virtualip") |
| 35 | private IpPortPair virtualIp; |
| 36 | @SerializedName("realiplist") |
| 37 | private Set<IpPortPair> realIpList; |
| 38 | private LoadBalancerType type; |
| 39 | private LoadBalancerPersistenceType persistence; |
| 40 | private LoadBalancerOs os; |
| 41 | private LoadBalancerState state; |
| 42 | private Option datacenter; |
| 43 | |
| 44 | /** |
| 45 | * A no-args constructor is required for deserialization |
| 46 | */ |
| 47 | public LoadBalancer() { |
| 48 | } |
| 49 | |
| 50 | public LoadBalancer(long id, String name, String description, IpPortPair virtualIp, |
| 51 | Set<IpPortPair> realIpList, LoadBalancerType type, |
| 52 | LoadBalancerPersistenceType persistence, LoadBalancerOs os, LoadBalancerState state, |
| 53 | Option datacenter) { |
| 54 | this.id = id; |
| 55 | this.name = name; |
| 56 | this.description = description; |
| 57 | this.virtualIp = virtualIp; |
| 58 | this.realIpList = realIpList; |
| 59 | this.type = type; |
| 60 | this.persistence = persistence; |
| 61 | this.os = os; |
| 62 | this.state = state; |
| 63 | this.datacenter = datacenter; |
| 64 | } |
| 65 | |
| 66 | public long getId() { |
| 67 | return id; |
| 68 | } |
| 69 | |
| 70 | public Option getDatacenter() { |
| 71 | return datacenter; |
| 72 | } |
| 73 | |
| 74 | public String getName() { |
| 75 | return name; |
| 76 | } |
| 77 | |
| 78 | public String getDescription() { |
| 79 | return description; |
| 80 | } |
| 81 | |
| 82 | public IpPortPair getVirtualIp() { |
| 83 | return virtualIp; |
| 84 | } |
| 85 | |
| 86 | public Set<IpPortPair> getRealIpList() { |
| 87 | return realIpList; |
| 88 | } |
| 89 | |
| 90 | public LoadBalancerType getType() { |
| 91 | return type; |
| 92 | } |
| 93 | |
| 94 | public LoadBalancerPersistenceType getPersistence() { |
| 95 | return persistence; |
| 96 | } |
| 97 | |
| 98 | public LoadBalancerOs getOs() { |
| 99 | return os; |
| 100 | } |
| 101 | |
| 102 | public LoadBalancerState getState() { |
| 103 | return state; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public boolean equals(Object obj) { |
| 108 | if (this == obj) |
| 109 | return true; |
| 110 | if (obj == null) |
| 111 | return false; |
| 112 | if (getClass() != obj.getClass()) |
| 113 | return false; |
| 114 | LoadBalancer other = (LoadBalancer) obj; |
| 115 | if (datacenter == null) { |
| 116 | if (other.datacenter != null) |
| 117 | return false; |
| 118 | } else if (!datacenter.equals(other.datacenter)) |
| 119 | return false; |
| 120 | if (description == null) { |
| 121 | if (other.description != null) |
| 122 | return false; |
| 123 | } else if (!description.equals(other.description)) |
| 124 | return false; |
| 125 | if (id != other.id) |
| 126 | return false; |
| 127 | if (name == null) { |
| 128 | if (other.name != null) |
| 129 | return false; |
| 130 | } else if (!name.equals(other.name)) |
| 131 | return false; |
| 132 | if (os == null) { |
| 133 | if (other.os != null) |
| 134 | return false; |
| 135 | } else if (!os.equals(other.os)) |
| 136 | return false; |
| 137 | if (persistence == null) { |
| 138 | if (other.persistence != null) |
| 139 | return false; |
| 140 | } else if (!persistence.equals(other.persistence)) |
| 141 | return false; |
| 142 | if (realIpList == null) { |
| 143 | if (other.realIpList != null) |
| 144 | return false; |
| 145 | } else if (!realIpList.equals(other.realIpList)) |
| 146 | return false; |
| 147 | if (state == null) { |
| 148 | if (other.state != null) |
| 149 | return false; |
| 150 | } else if (!state.equals(other.state)) |
| 151 | return false; |
| 152 | if (type == null) { |
| 153 | if (other.type != null) |
| 154 | return false; |
| 155 | } else if (!type.equals(other.type)) |
| 156 | return false; |
| 157 | if (virtualIp == null) { |
| 158 | if (other.virtualIp != null) |
| 159 | return false; |
| 160 | } else if (!virtualIp.equals(other.virtualIp)) |
| 161 | return false; |
| 162 | return true; |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public int hashCode() { |
| 167 | final int prime = 31; |
| 168 | int result = 1; |
| 169 | result = prime * result + ((datacenter == null) ? 0 : datacenter.hashCode()); |
| 170 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 171 | result = prime * result + (int) (id ^ (id >>> 32)); |
| 172 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 173 | result = prime * result + ((os == null) ? 0 : os.hashCode()); |
| 174 | result = prime * result + ((persistence == null) ? 0 : persistence.hashCode()); |
| 175 | result = prime * result + ((realIpList == null) ? 0 : realIpList.hashCode()); |
| 176 | result = prime * result + ((state == null) ? 0 : state.hashCode()); |
| 177 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
| 178 | result = prime * result + ((virtualIp == null) ? 0 : virtualIp.hashCode()); |
| 179 | return result; |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public int compareTo(LoadBalancer o) { |
| 184 | return Longs.compare(id, o.getId()); |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | public String toString() { |
| 189 | return "LoadBalancer [datacenter=" + datacenter + ", description=" + description + ", id=" |
| 190 | + id + ", name=" + name + ", os=" + os + ", persistence=" + persistence |
| 191 | + ", realIpList=" + realIpList + ", state=" + state + ", type=" + type |
| 192 | + ", virtualIp=" + virtualIp + "]"; |
| 193 | } |
| 194 | } |