2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.be.components.impl.utils;
19 import com.google.common.collect.Sets;
20 import org.apache.commons.collections.CollectionUtils;
21 import org.apache.commons.lang.StringUtils;
23 import java.util.List;
24 import java.util.Optional;
26 public class DirectivesUtils {
28 public static final String SUBSTITUTABLE = "substitutable";
29 public static final String SELECTABLE = "selectable";
30 public enum DIRECTIVE {
32 SUBSTITUTABLE(DirectivesUtils.SUBSTITUTABLE), SELECTABLE(DirectivesUtils.SELECTABLE);
34 private final String value;
36 DIRECTIVE(String value) {
41 public String toString() {
47 public static Optional<DIRECTIVE> getDirective(String inDirective) {
48 if (StringUtils.isEmpty(inDirective)) {
49 return Optional.empty();
52 return Sets.newHashSet(DIRECTIVE.values()).stream()
53 .filter(directive -> directive.toString().equals(inDirective)).findAny();
56 public static boolean isValid(List<String> inDirectives){
57 if (CollectionUtils.isEmpty(inDirectives)){
60 return inDirectives.stream().allMatch(directive -> getDirective(directive).isPresent());