[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / main / java / org / openecomp / sdc / translator / datatypes / heattotosca / PropertyRegexMatcher.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.translator.datatypes.heattotosca;
22
23 import org.apache.commons.collections.CollectionUtils;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.regex.Pattern;
28
29 public class PropertyRegexMatcher {
30   private String propertyName;
31   private List<Pattern> regexPatterns;
32   private String stringToSearchForPropertyValue;
33
34   /**
35    * Constractor for creating PropertyRegexMatcher.
36    * @param propertyName property name
37    * @param regexPatterns regex pattern
38    * @param stringToSearchForPropertyValue string for search in the property value manipulation
39    */
40   public PropertyRegexMatcher(String propertyName,
41                               List<String> regexPatterns,
42                               String stringToSearchForPropertyValue) {
43     this.propertyName = propertyName;
44     setRegex(regexPatterns);
45     this.stringToSearchForPropertyValue = stringToSearchForPropertyValue;
46   }
47
48   public String getPropertyName() {
49     return propertyName;
50   }
51
52   public void setPropertyName(String propertyName) {
53     this.propertyName = propertyName;
54   }
55
56   /**
57    * Sets regex.
58    *
59    * @param regexPatterns the regex patterns
60    */
61   public void setRegex(List<String> regexPatterns) {
62     if (CollectionUtils.isEmpty(this.regexPatterns)) {
63       this.regexPatterns = new ArrayList<>();
64     }
65
66     for (String regexPattern : regexPatterns) {
67       this.regexPatterns.add(Pattern.compile(regexPattern));
68     }
69   }
70
71   public List<Pattern> getRegexPatterns() {
72     return regexPatterns;
73   }
74
75   public String getStringToSearchForPropertyValue() {
76     return stringToSearchForPropertyValue;
77   }
78
79   public void setStringToSearchForPropertyValue(String stringToSearchForPropertyValue) {
80     this.stringToSearchForPropertyValue = stringToSearchForPropertyValue;
81   }
82
83 }