2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.drools.pooling.state;
24 import java.util.TreeMap;
27 * Filter Utilities. These methods create <i>TreeMap</i> objects, because they
28 * should only contain a small number of items.
30 public class FilterUtils {
31 // message element names
32 public static final String MSG_CHANNEL = "channel";
33 public static final String MSG_TIMESTAMP = "timestampMs";
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";
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";
49 private FilterUtils() {
54 * Makes a filter that verifies that a field equals a value.
56 * @param field name of the field to check
57 * @param value desired value
58 * @return a map representing an "equals" filter
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);
70 * Makes an "and" filter, where all of the items must be true.
72 * @param items items to be checked
73 * @return an "and" filter
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);
84 * Makes an "or" filter, where at least one of the items must be true.
86 * @param items items to be checked
87 * @return an "or" filter
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);