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