Re-encrypt drools-pdp properties
[policy/drools-pdp.git] / feature-pooling-dmaap / src / main / java / org / onap / policy / drools / pooling / state / FilterUtils.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2018-2020 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.onap.policy.drools.pooling.state;
22
23 import java.util.Map;
24 import java.util.TreeMap;
25
26 /**
27  * Filter Utilities. These methods create <i>TreeMap</i> objects, because they
28  * should only contain a small number of items.
29  */
30 public class FilterUtils {
31     // message element names
32     public static final String MSG_CHANNEL = "channel";
33     public static final String MSG_TIMESTAMP = "timestampMs";
34
35     // json element names
36     protected static final String JSON_CLASS = "class";
37     protected static final String JSON_FILTERS = "filters";
38     protected static final String JSON_FIELD = "field";
39     protected static final String JSON_VALUE = "value";
40
41     // values to be stuck into the "class" element
42     protected static final String CLASS_OR = "Or";
43     protected static final String CLASS_AND = "And";
44     protected static final String CLASS_EQUALS = "Equals";
45
46     /**
47      * Constructor.
48      */
49     private FilterUtils() {
50         super();
51     }
52
53     /**
54      * Makes a filter that verifies that a field equals a value.
55      *
56      * @param field name of the field to check
57      * @param value desired value
58      * @return a map representing an "equals" filter
59      */
60     public static Map<String, Object> makeEquals(String field, String value) {
61         Map<String, Object> map = new TreeMap<>();
62         map.put(JSON_CLASS, CLASS_EQUALS);
63         map.put(JSON_FIELD, field);
64         map.put(JSON_VALUE, value);
65
66         return map;
67     }
68
69     /**
70      * Makes an "and" filter, where all of the items must be true.
71      *
72      * @param items items to be checked
73      * @return an "and" filter
74      */
75     public static Map<String, Object> makeAnd(@SuppressWarnings("unchecked") Map<String, Object>... items) {
76         Map<String, Object> map = new TreeMap<>();
77         map.put(JSON_CLASS, CLASS_AND);
78         map.put(JSON_FILTERS, items);
79
80         return map;
81     }
82
83     /**
84      * Makes an "or" filter, where at least one of the items must be true.
85      *
86      * @param items items to be checked
87      * @return an "or" filter
88      */
89     public static Map<String, Object> makeOr(@SuppressWarnings("unchecked") Map<String, Object>... items) {
90         Map<String, Object> map = new TreeMap<>();
91         map.put(JSON_CLASS, CLASS_OR);
92         map.put(JSON_FILTERS, items);
93
94         return map;
95     }
96 }