blob: 84d60f1f49fc8d99c6148b6f4ed1254f9b99bc4f [file] [log] [blame]
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.elb.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
/**
*
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_PolicyTypeDescription.html"
* >doc</a>
*
* @author Adrian Cole
*/
public class PolicyType {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromPolicyType(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected String description;
protected ImmutableSet.Builder<AttributeMetadata<?>> attributeMetadata = ImmutableSet.<AttributeMetadata<?>> builder();
/**
* @see PolicyType#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see PolicyType#getDescription()
*/
public T description(String description) {
this.description = description;
return self();
}
/**
* @see PolicyType#getAttributeMetadata()
*/
public T attributeMetadata(Iterable<AttributeMetadata<?>> attributeMetadata) {
this.attributeMetadata.addAll(checkNotNull(attributeMetadata, "attributeMetadata"));
return self();
}
/**
* @see PolicyType#getAttributeMetadata()
*/
public T attributeMetadata(AttributeMetadata<?> attributeMetadata) {
this.attributeMetadata.add(checkNotNull(attributeMetadata, "attributeMetadata"));
return self();
}
public PolicyType build() {
return new PolicyType(name, description, attributeMetadata.build());
}
public T fromPolicyType(PolicyType in) {
return this.name(in.getName()).description(in.getDescription()).attributeMetadata(in.getAttributeMetadata());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
protected final String name;
protected final String description;
protected final Set<AttributeMetadata<?>> attributeMetadata;
protected PolicyType(String name, String description, Iterable<AttributeMetadata<?>> attributeMetadata) {
this.name = checkNotNull(name, "name");
this.description = checkNotNull(description, "description");
this.attributeMetadata = ImmutableSet.copyOf(checkNotNull(attributeMetadata, "attributeMetadata"));
}
/**
* The name of the policy type.
*/
public String getName() {
return name;
}
/**
* A human-readable description of the policy type.
*/
public String getDescription() {
return description;
}
/**
* The description of the policy attributes associated with the LoadBalancer policies defined by
* the Elastic Load Balancing service.
*/
public Set<AttributeMetadata<?>> getAttributeMetadata() {
return attributeMetadata;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PolicyType other = (PolicyType) obj;
return Objects.equal(this.name, other.name);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return Objects.toStringHelper(this).omitNullValues().add("name", name).add("description", description)
.add("attributeMetadata", attributeMetadata).toString();
}
}