Add <,> operators support to cps-path
[cps.git] / cps-path-parser / src / main / java / org / onap / cps / cpspath / parser / CpsPathComparativeOperator.java
diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathComparativeOperator.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathComparativeOperator.java
new file mode 100644 (file)
index 0000000..c7ffd0d
--- /dev/null
@@ -0,0 +1,64 @@
+/*\r
+ *  ============LICENSE_START=======================================================\r
+ *  Copyright (C) 2023 Tech Mahindra Ltd\r
+ *  ================================================================================\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ *\r
+ *  SPDX-License-Identifier: Apache-2.0\r
+ *  ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.cps.cpspath.parser;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+public enum CpsPathComparativeOperator {\r
+    EQ("="),\r
+    GT(">"),\r
+    LT("<"),\r
+    GE(">="),\r
+    LE("<=");\r
+\r
+    private final String label;\r
+\r
+    CpsPathComparativeOperator(final String label) {\r
+        this.label = label;\r
+    }\r
+\r
+    public final String getLabel() {\r
+        return this.label;\r
+    }\r
+\r
+    private static final Map<String, CpsPathComparativeOperator> cpsPathComparativeOperatorPerLabel = new HashMap<>();\r
+\r
+    static {\r
+        for (final CpsPathComparativeOperator cpsPathComparativeOperator : CpsPathComparativeOperator.values()) {\r
+            cpsPathComparativeOperatorPerLabel.put(cpsPathComparativeOperator.label, cpsPathComparativeOperator);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Finds the value of the given enumeration.\r
+     *\r
+     * @param label value of the enum\r
+     * @return a comparativeOperatorType\r
+     */\r
+    public static CpsPathComparativeOperator fromString(final String label) {\r
+        if (!cpsPathComparativeOperatorPerLabel.containsKey(label)) {\r
+            throw new PathParsingException("Incomplete leaf condition (no operator)");\r
+        }\r
+        return cpsPathComparativeOperatorPerLabel.get(label);\r
+    }\r
+}\r
+\r