io.cloudslang.lang.entities.bindings.Input Maven / Gradle / Ivy
/*******************************************************************************
* (c) Copyright 2016 Hewlett-Packard Development Company, L.P.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License v2.0 which accompany this distribution.
*
* The Apache License is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
*******************************************************************************/
package io.cloudslang.lang.entities.bindings;
import io.cloudslang.lang.entities.PromptType;
import io.cloudslang.lang.entities.SensitivityLevel;
import io.cloudslang.lang.entities.bindings.prompt.Prompt;
import io.cloudslang.lang.entities.bindings.values.Value;
import io.cloudslang.lang.entities.bindings.values.ValueFactory;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
/**
* @author orius123
* @version $Id$
* @since 05/11/14.
*/
public class Input extends InOutParam {
private static final long serialVersionUID = -2411446962609754342L;
private boolean required;
private boolean privateInput;
private Prompt prompt;
private Input(InputBuilder inputBuilder) {
super(inputBuilder.name,
inputBuilder.value,
inputBuilder.functionDependencies,
inputBuilder.systemPropertyDependencies
);
this.required = inputBuilder.required;
this.privateInput = inputBuilder.privateInput;
this.prompt = inputBuilder.prompt;
}
/**
* only here to satisfy serialization libraries
*/
@SuppressWarnings("unused")
private Input() {
}
public boolean isRequired() {
return required;
}
public boolean isPrivateInput() {
return privateInput;
}
public boolean hasPrompt() {
return prompt != null;
}
public Prompt getPrompt() {
return prompt;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.appendSuper(super.toString())
.append("required", required)
.append("privateInput", privateInput)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Input input = (Input) o;
return new EqualsBuilder()
.appendSuper(super.equals(o))
.append(required, input.required)
.append(privateInput, input.privateInput)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.appendSuper(super.hashCode())
.append(required)
.append(privateInput)
.toHashCode();
}
public static class InputBuilder {
private String name;
private Value value;
private boolean required;
private boolean privateInput;
private Set functionDependencies;
private Set systemPropertyDependencies;
private Prompt prompt;
public InputBuilder(String name, Serializable serializable) {
this(name, serializable, false);
}
public InputBuilder(String name, Serializable serializable, boolean sensitive) {
this.name = name;
this.value = ValueFactory.create(serializable, sensitive);
this.required = true;
this.privateInput = false;
this.functionDependencies = new HashSet<>();
this.systemPropertyDependencies = new HashSet<>();
}
public InputBuilder(String name, Serializable serializable, boolean sensitive,
SensitivityLevel sensitivityLevel) {
this.name = name;
this.value = ValueFactory.create(serializable, sensitive, sensitivityLevel);
this.required = true;
this.privateInput = false;
this.functionDependencies = new HashSet<>();
this.systemPropertyDependencies = new HashSet<>();
}
public InputBuilder(Input input, Value value) {
this.name = input.getName();
this.value = value;
this.required = input.isRequired();
this.privateInput = input.isPrivateInput();
this.functionDependencies = input.getFunctionDependencies();
this.systemPropertyDependencies = input.getSystemPropertyDependencies();
this.prompt = input.prompt;
}
public InputBuilder withRequired(boolean required) {
this.required = required;
return this;
}
public InputBuilder withPrivateInput(boolean privateInput) {
this.privateInput = privateInput;
return this;
}
public InputBuilder withFunctionDependencies(Set functionDependencies) {
this.functionDependencies = functionDependencies;
return this;
}
public InputBuilder withSystemPropertyDependencies(Set systemPropertyDependencies) {
this.systemPropertyDependencies = systemPropertyDependencies;
return this;
}
public InputBuilder withPrompt(Prompt prompt) {
this.prompt = prompt;
return this;
}
public Input build() {
return new Input(this);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy