6977380ad76255ab175ed5fad55138b192bd39fc
[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         public RangeQueryBuilder lt(Object compare) {
70                 this.lteValue=null;
71                 this.ltValue=compare;
72                 this.setQuery();
73                 return this;
74         }
75         
76         public RangeQueryBuilder gte(Object compare) {
77                 this.gteValue=compare;
78                 this.gtValue=null;
79                 this.setQuery();
80                 return this;
81         }
82         public RangeQueryBuilder gt(Object compare) {
83                 this.gteValue=null;
84                 this.gtValue=compare;
85                 this.setQuery();
86                 return this;
87         }
88
89 }