e8b3d3047281051a0713c8b95d4e2df5d45dfc79
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.common.database.queries;
23
24 import org.json.JSONObject;
25
26 public class RangeQueryBuilder extends QueryBuilder {
27
28     private Object gtValue = null;
29     private Object gteValue = null;
30     private Float boost = 2.0f;
31     private Object ltValue = null;
32     private Object lteValue = null;
33     private String key;
34
35     public RangeQueryBuilder(String key) {
36         super();
37         this.key = key;
38
39     }
40
41     private void setQuery() {
42         JSONObject r = new JSONObject();
43         JSONObject k = new JSONObject();
44         if (this.gteValue != null) {
45             k.put("gte", this.gteValue);
46         } else if (this.gtValue != null) {
47             k.put("gt", this.gtValue);
48         }
49         if (this.lteValue != null) {
50             k.put("lte", this.lteValue);
51         } else if (this.ltValue != null) {
52             k.put("lt", this.ltValue);
53         }
54         if (this.boost != null) {
55             k.put("boost", this.boost);
56         }
57         r.put(this.key, k);
58
59         this.setQuery("range", r);
60     }
61
62
63     public RangeQueryBuilder lte(Object compare) {
64         this.lteValue = compare;
65         this.ltValue = null;
66         this.setQuery();
67         return this;
68     }
69
70     public RangeQueryBuilder lt(Object compare) {
71         this.lteValue = null;
72         this.ltValue = compare;
73         this.setQuery();
74         return this;
75     }
76
77     public RangeQueryBuilder gte(Object compare) {
78         this.gteValue = compare;
79         this.gtValue = null;
80         this.setQuery();
81         return this;
82     }
83
84     public RangeQueryBuilder gt(Object compare) {
85         this.gteValue = null;
86         this.gtValue = compare;
87         this.setQuery();
88         return this;
89     }
90
91 }