dcf0c007c12384b008a5d1835205cb13936c2a99
[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 @Deprecated
27 public class RangeQueryBuilder extends QueryBuilder {
28
29     private Object gtValue = null;
30     private Object gteValue = null;
31     private Float boost = 2.0f;
32     private Object ltValue = null;
33     private Object lteValue = null;
34     private String key;
35
36     public RangeQueryBuilder(String key) {
37         super();
38         this.key = key;
39
40     }
41
42     private void setQuery() {
43         JSONObject r = new JSONObject();
44         JSONObject k = new JSONObject();
45         if (this.gteValue != null) {
46             k.put("gte", this.gteValue);
47         } else if (this.gtValue != null) {
48             k.put("gt", this.gtValue);
49         }
50         if (this.lteValue != null) {
51             k.put("lte", this.lteValue);
52         } else if (this.ltValue != null) {
53             k.put("lt", this.ltValue);
54         }
55         if (this.boost != null) {
56             k.put("boost", this.boost);
57         }
58         r.put(this.key, k);
59
60         this.setQuery("range", r);
61     }
62
63
64     public RangeQueryBuilder lte(Object compare) {
65         this.lteValue = compare;
66         this.ltValue = null;
67         this.setQuery();
68         return this;
69     }
70
71     public RangeQueryBuilder lt(Object compare) {
72         this.lteValue = null;
73         this.ltValue = compare;
74         this.setQuery();
75         return this;
76     }
77
78     public RangeQueryBuilder gte(Object compare) {
79         this.gteValue = compare;
80         this.gtValue = null;
81         this.setQuery();
82         return this;
83     }
84
85     public RangeQueryBuilder gt(Object compare) {
86         this.gteValue = null;
87         this.gtValue = compare;
88         this.setQuery();
89         return this;
90     }
91
92 }