3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2022 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.datatypes.enums;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Optional;
31 public enum ConstraintType {
33 IN_RANGE("in_range", "inRange"),
34 GREATER_THAN("greater_than", "greaterThan"),
35 GREATER_OR_EQUAL("greater_or_equal", "greaterOrEqual"),
36 LESS_OR_EQUAL("less_or_equal", "lessOrEqual"),
38 MIN_LENGTH("min_length", "minLength"),
39 MAX_LENGTH("max_length", "maxLength"),
40 VALID_VALUES("valid_values", "validValues"),
41 LESS_THAN("less_than", "lessThan"),
44 private static final Set<ConstraintType> comparableConstraints = Set.of(ConstraintType.GREATER_THAN, ConstraintType.LESS_THAN);
45 private final String type;
46 private final List<String> typeAlias;
49 ConstraintType(final String type, final String... typeAliases) {
51 if (typeAliases == null) {
52 this.typeAlias = Collections.emptyList();
54 this.typeAlias = Arrays.asList(typeAliases);
58 public static Optional<ConstraintType> findByType(final String type) {
60 return Optional.empty();
62 return Arrays.stream(ConstraintType.values())
63 .filter(constraintType -> constraintType.getType().equals(type) || constraintType.getTypeAlias().contains(type))
67 public boolean isComparable() {
68 return comparableConstraints.contains(this);