org.openstack4j.openstack.senlin.domain.SenlinPolicyCreate Maven / Gradle / Ivy
package org.openstack4j.openstack.senlin.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
import org.openstack4j.model.senlin.PolicyCreate;
import org.openstack4j.model.senlin.builder.PolicyCreateBuilder;
import java.util.HashMap;
import java.util.Map;
/**
* This class contains all elements required for the creation of a SenlinPolicy. It
* uses Jackson annotation for (de)serialization into JSON
*
* @author lion
*
*/
public class SenlinPolicyCreate implements PolicyCreate {
private static final long serialVersionUID = 2130740129242729916L;
@JsonProperty("policy")
private Map policy;
/**
* Returnes a {@link SenlinPolicyCreateConcreteBuilder} for configuration and
* creation of a {@link SenlinPolicyCreate} object.
*
* @return a {@link SenlinPolicyCreateConcreteBuilder}
*/
public static SenlinPolicyCreateConcreteBuilder build() {
return new SenlinPolicyCreateConcreteBuilder();
}
@Override
public PolicyCreateBuilder toBuilder() {
return new SenlinPolicyCreateConcreteBuilder(this);
}
/**
* A Builder to create a SenlinPolicy. Use {@link #build()} to receive the
* {@link PolicyCreate} object.
*
* @author lion
*
*/
public static class SenlinPolicyCreateConcreteBuilder implements
PolicyCreateBuilder {
private SenlinPolicyCreate model;
/**
* Constructor to create a {@link SenlinPolicyCreateConcreteBuilder} object
* with a new, empty {@link SenlinPolicyCreate} object.
*/
public SenlinPolicyCreateConcreteBuilder() {
this(new SenlinPolicyCreate());
}
/**
* Constructor for manipulation of an existing {@link SenlinPolicyCreate}
* object.
*
* @param model
* the {@link SenlinPolicyCreate} object which is to be
* modified.
*/
public SenlinPolicyCreateConcreteBuilder(SenlinPolicyCreate model) {
this.model = model;
this.model.policy = Maps.newHashMap();
HashMap spec = Maps.newHashMap();
HashMap properties = Maps.newHashMap();
HashMap adjustment = Maps.newHashMap();
properties.put("adjustment", adjustment);
spec.put("properties", properties);
this.model.policy.put("spec", spec);
}
@Override
public PolicyCreate build() {
return model;
}
@Override
public PolicyCreateBuilder from(PolicyCreate in) {
model = (SenlinPolicyCreate) in;
return this;
}
@Override
public PolicyCreateBuilder name(String name) {
model.policy.put("name", name);
return this;
}
@Override
public PolicyCreateBuilder spec(Map spec) {
model.policy.put("spec", spec);
return this;
}
@Override
public PolicyCreateBuilder properties(Map properties) {
HashMap spec = (HashMap)(model.policy.get("spec"));
spec.put("properties", properties);
return this;
}
@Override
public PolicyCreateBuilder adjustment(Map adjustment) {
HashMap properties = (HashMap)(((HashMap)(model.policy.get("spec"))).get("properties"));
properties.put("adjustment", adjustment);
return this;
}
@Override
public PolicyCreateBuilder minStep(int minStep) {
HashMap adjustment = (HashMap)(((HashMap)((HashMap)model.policy
.get("spec")).get("properties")).get("adjustment"));
adjustment.put("min_step", minStep);
return this;
}
@Override
public PolicyCreateBuilder number(int number) {
HashMap adjustment = (HashMap)(((HashMap)((HashMap)model.policy
.get("spec")).get("properties")).get("adjustment"));
adjustment.put("number", number);
return this;
}
@Override
public PolicyCreateBuilder adjustmentType(String adjustmentType) {
HashMap adjustment = (HashMap)(((HashMap)((HashMap)model.policy
.get("spec")).get("properties")).get("adjustment"));
adjustment.put("type", adjustmentType);
return this;
}
@Override
public PolicyCreateBuilder event(String event) {
HashMap properties = (HashMap)((HashMap)model.policy
.get("spec")).get("properties");
properties.put("event", event);
return this;
}
@Override
public PolicyCreateBuilder specType(String specType) {
HashMap spec = (HashMap)model.policy
.get("spec");
spec.put("type", specType);
return this;
}
@Override
public PolicyCreateBuilder version(String version) {
HashMap spec = (HashMap)model.policy
.get("spec");
spec.put("version", version);
return this;
}
}
}