| 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.ovf; |
| 20 | |
| 21 | import org.jclouds.javax.annotation.Nullable; |
| 22 | |
| 23 | import org.jclouds.cim.OSType; |
| 24 | |
| 25 | /** |
| 26 | * An OperatingSystemSection specifies the operating system installed on a virtual machine. |
| 27 | * |
| 28 | * @author Adrian Cole |
| 29 | */ |
| 30 | public class OperatingSystemSection extends Section<OperatingSystemSection> { |
| 31 | |
| 32 | @SuppressWarnings("unchecked") |
| 33 | public static Builder builder() { |
| 34 | return new Builder(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * {@inheritDoc} |
| 39 | */ |
| 40 | @Override |
| 41 | public Builder toBuilder() { |
| 42 | return builder().fromOperatingSystemSection(this); |
| 43 | } |
| 44 | |
| 45 | public static class Builder extends Section.Builder<OperatingSystemSection> { |
| 46 | protected Integer id; |
| 47 | protected String description; |
| 48 | |
| 49 | /** |
| 50 | * @see OperatingSystemSection#getID |
| 51 | */ |
| 52 | public Builder id(Integer id) { |
| 53 | this.id = id; |
| 54 | return this; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @see OperatingSystemSection#getDescription |
| 59 | */ |
| 60 | public Builder description(String description) { |
| 61 | this.description = description; |
| 62 | return this; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * {@inheritDoc} |
| 67 | */ |
| 68 | @Override |
| 69 | public OperatingSystemSection build() { |
| 70 | return new OperatingSystemSection(id, info, description); |
| 71 | } |
| 72 | |
| 73 | public Builder fromOperatingSystemSection(OperatingSystemSection in) { |
| 74 | return id(in.getId()).info(in.getInfo()).description(in.getDescription()); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * {@inheritDoc} |
| 79 | */ |
| 80 | @Override |
| 81 | public Builder fromSection(Section<OperatingSystemSection> in) { |
| 82 | return Builder.class.cast(super.fromSection(in)); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * {@inheritDoc} |
| 87 | */ |
| 88 | @Override |
| 89 | public Builder info(String info) { |
| 90 | return Builder.class.cast(super.info(info)); |
| 91 | } |
| 92 | |
| 93 | } |
| 94 | |
| 95 | protected final Integer id; |
| 96 | protected final String description; |
| 97 | |
| 98 | public OperatingSystemSection(@Nullable Integer id, @Nullable String info, @Nullable String description) { |
| 99 | super(info); |
| 100 | this.id = id; |
| 101 | this.description = description; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * |
| 106 | * @return ovf id |
| 107 | * @see OSType#getCode() |
| 108 | */ |
| 109 | public Integer getId() { |
| 110 | return id; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * |
| 115 | * @return description or null |
| 116 | */ |
| 117 | public String getDescription() { |
| 118 | return description; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public int hashCode() { |
| 123 | final int prime = 31; |
| 124 | int result = 1; |
| 125 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 126 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| 127 | result = prime * result + ((info == null) ? 0 : info.hashCode()); |
| 128 | return result; |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public boolean equals(Object obj) { |
| 133 | if (this == obj) |
| 134 | return true; |
| 135 | if (obj == null) |
| 136 | return false; |
| 137 | if (getClass() != obj.getClass()) |
| 138 | return false; |
| 139 | OperatingSystemSection other = (OperatingSystemSection) obj; |
| 140 | if (description == null) { |
| 141 | if (other.description != null) |
| 142 | return false; |
| 143 | } else if (!description.equals(other.description)) |
| 144 | return false; |
| 145 | if (id == null) { |
| 146 | if (other.id != null) |
| 147 | return false; |
| 148 | } else if (!id.equals(other.id)) |
| 149 | return false; |
| 150 | if (info == null) { |
| 151 | if (other.info != null) |
| 152 | return false; |
| 153 | } else if (!info.equals(other.info)) |
| 154 | return false; |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public String toString() { |
| 160 | return String.format("[info=%s, id=%s, description=%s]", info, id, description); |
| 161 | } |
| 162 | |
| 163 | } |