io.cloudslang.content.amazon.entities.validators.Validator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cs-amazon Show documentation
Show all versions of cs-amazon Show documentation
Java actions for amazon integration
/*
* (c) Copyright 2017 EntIT Software LLC, a Micro Focus 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
*
* 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.
*/
/*
* (c) Copyright 2018 Micro Focus, 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
*
* 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 io.cloudslang.content.amazon.entities.validators;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import static io.cloudslang.content.utils.BooleanUtilities.isValid;
import static io.cloudslang.content.utils.NumberUtilities.isValidInt;
import static io.cloudslang.content.utils.OtherUtilities.isValidIpPort;
import static java.lang.String.format;
import static org.apache.commons.lang3.StringUtils.join;
public class Validator {
private final List errorList;
public Validator() {
errorList = new ArrayList<>();
}
public boolean hasErrors() {
return !errorList.isEmpty();
}
public String getErrors() {
return getErrors(System.lineSeparator());
}
public String getErrors(@NotNull final String delimiter) {
return join(errorList, delimiter);
}
public Validator validatePort(@NotNull final String value, @NotNull final String inputName) {
if (!isValidIpPort(value)) {
errorList.add(format("[%s]: Invalid port value [%s]!", inputName, value));
}
return this;
}
public Validator validateInt(@NotNull final String intValue, @NotNull final String inputName) {
if (!isValidInt(intValue)) {
errorList.add(format("[%s]: Invalid integer value.", inputName));
}
return this;
}
public Validator validateBoolean(@NotNull final String booleanValue, @NotNull final String inputName) {
if (!isValid(booleanValue)) {
errorList.add(format("[%s]: Invalid boolean value!", inputName));
}
return this;
}
}