| 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.savvis.vpdc.domain; |
| 20 | |
| 21 | import org.jclouds.ovf.Section; |
| 22 | |
| 23 | /** |
| 24 | * |
| 25 | * @author Adrian Cole |
| 26 | */ |
| 27 | public class NetworkConnectionSection extends Section<NetworkConnectionSection> { |
| 28 | |
| 29 | @SuppressWarnings("unchecked") |
| 30 | public static Builder builder() { |
| 31 | return new Builder(); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * {@inheritDoc} |
| 36 | */ |
| 37 | @Override |
| 38 | public Builder toBuilder() { |
| 39 | return builder().fromNetworkConectionSection(this); |
| 40 | } |
| 41 | |
| 42 | public static class Builder extends Section.Builder<NetworkConnectionSection> { |
| 43 | private String network; |
| 44 | private String ipAddress; |
| 45 | |
| 46 | public Builder network(String network) { |
| 47 | this.network = network; |
| 48 | return this; |
| 49 | } |
| 50 | |
| 51 | public Builder ipAddress(String ipAddress) { |
| 52 | this.ipAddress = ipAddress; |
| 53 | return this; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * {@inheritDoc} |
| 58 | */ |
| 59 | @Override |
| 60 | public NetworkConnectionSection build() { |
| 61 | return new NetworkConnectionSection(info, network, ipAddress); |
| 62 | } |
| 63 | |
| 64 | public Builder fromNetworkConectionSection(NetworkConnectionSection in) { |
| 65 | return fromSection(in).network(in.getNetwork()).ipAddress(in.getIpAddress()); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * {@inheritDoc} |
| 70 | */ |
| 71 | @Override |
| 72 | public Builder fromSection(Section<NetworkConnectionSection> in) { |
| 73 | return Builder.class.cast(super.fromSection(in)); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * {@inheritDoc} |
| 78 | */ |
| 79 | @Override |
| 80 | public Builder info(String info) { |
| 81 | return Builder.class.cast(super.info(info)); |
| 82 | } |
| 83 | |
| 84 | } |
| 85 | |
| 86 | private final String network; |
| 87 | private final String ipAddress; |
| 88 | |
| 89 | public NetworkConnectionSection(String info, String network, String ipAddress) { |
| 90 | super(info); |
| 91 | this.network = network; |
| 92 | this.ipAddress = ipAddress; |
| 93 | } |
| 94 | |
| 95 | public String getNetwork() { |
| 96 | return network; |
| 97 | } |
| 98 | |
| 99 | public String getIpAddress() { |
| 100 | return ipAddress; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public int hashCode() { |
| 105 | final int prime = 31; |
| 106 | int result = super.hashCode(); |
| 107 | result = prime * result + ((network == null) ? 0 : network.hashCode()); |
| 108 | return result; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public boolean equals(Object obj) { |
| 113 | if (this == obj) |
| 114 | return true; |
| 115 | if (!super.equals(obj)) |
| 116 | return false; |
| 117 | if (getClass() != obj.getClass()) |
| 118 | return false; |
| 119 | NetworkConnectionSection other = (NetworkConnectionSection) obj; |
| 120 | if (network == null) { |
| 121 | if (other.network != null) |
| 122 | return false; |
| 123 | } else if (!network.equals(other.network)) |
| 124 | return false; |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public String toString() { |
| 130 | return String.format("[info=%s, network=%s, ipAddress=%s]", info, network, ipAddress); |
| 131 | } |
| 132 | |
| 133 | } |