| 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 static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.util.Set; |
| 24 | |
| 25 | import com.google.common.collect.ImmutableSet; |
| 26 | import com.google.common.collect.Sets; |
| 27 | |
| 28 | /** |
| 29 | * The ProductSection element specifies product-information for an appliance, such as product name, |
| 30 | * version, and vendor. |
| 31 | * |
| 32 | * @author Adrian Cole |
| 33 | */ |
| 34 | public class ProductSection extends Section<ProductSection> { |
| 35 | |
| 36 | @SuppressWarnings("unchecked") |
| 37 | public static Builder builder() { |
| 38 | return new Builder(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * {@inheritDoc} |
| 43 | */ |
| 44 | @Override |
| 45 | public Builder toBuilder() { |
| 46 | return builder().fromDeploymentOptionSection(this); |
| 47 | } |
| 48 | |
| 49 | public static class Builder extends Section.Builder<ProductSection> { |
| 50 | protected Set<Property> properties = Sets.newLinkedHashSet(); |
| 51 | |
| 52 | /** |
| 53 | * @see ProductSection#getPropertys |
| 54 | */ |
| 55 | public Builder property(Property property) { |
| 56 | this.properties.add(checkNotNull(property, "property")); |
| 57 | return this; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @see ProductSection#getPropertys |
| 62 | */ |
| 63 | public Builder properties(Iterable<Property> properties) { |
| 64 | this.properties = ImmutableSet.<Property> copyOf(checkNotNull(properties, "properties")); |
| 65 | return this; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * {@inheritDoc} |
| 70 | */ |
| 71 | @Override |
| 72 | public ProductSection build() { |
| 73 | return new ProductSection(info, properties); |
| 74 | } |
| 75 | |
| 76 | public Builder fromDeploymentOptionSection(ProductSection in) { |
| 77 | return info(in.getInfo()).properties(in.getProperties()); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * {@inheritDoc} |
| 82 | */ |
| 83 | @Override |
| 84 | public Builder fromSection(Section<ProductSection> in) { |
| 85 | return Builder.class.cast(super.fromSection(in)); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * {@inheritDoc} |
| 90 | */ |
| 91 | @Override |
| 92 | public Builder info(String info) { |
| 93 | return Builder.class.cast(super.info(info)); |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | |
| 98 | protected final Set<Property> properties; |
| 99 | |
| 100 | public ProductSection(String info, Iterable<Property> properties) { |
| 101 | super(info); |
| 102 | this.properties = ImmutableSet.<Property> copyOf(checkNotNull(properties, "properties")); |
| 103 | |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public int hashCode() { |
| 108 | final int prime = 31; |
| 109 | int result = super.hashCode(); |
| 110 | result = prime * result + ((properties == null) ? 0 : properties.hashCode()); |
| 111 | return result; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public boolean equals(Object obj) { |
| 116 | if (this == obj) |
| 117 | return true; |
| 118 | if (!super.equals(obj)) |
| 119 | return false; |
| 120 | if (getClass() != obj.getClass()) |
| 121 | return false; |
| 122 | ProductSection other = (ProductSection) obj; |
| 123 | if (properties == null) { |
| 124 | if (other.properties != null) |
| 125 | return false; |
| 126 | } else if (!properties.equals(other.properties)) |
| 127 | return false; |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public String toString() { |
| 133 | return String.format("[info=%s, properties=%s]", info, properties); |
| 134 | } |
| 135 | |
| 136 | public Set<Property> getProperties() { |
| 137 | return properties; |
| 138 | } |
| 139 | |
| 140 | } |