001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.api.util;
015
016import java.util.Objects;
017
018import javax.annotation.Nullable;
019
020import com.fasterxml.jackson.annotation.JsonCreator;
021import com.fasterxml.jackson.annotation.JsonProperty;
022
023/**
024 * A range used for predicates allowing including or excluding the end values.
025 */
026public class RangeValue {
027
028  @JsonCreator
029  public RangeValue(
030      @Nullable @JsonProperty("gte") String gte,
031      @Nullable @JsonProperty("gt") String gt,
032      @Nullable @JsonProperty("lte") String lte,
033      @Nullable @JsonProperty("lt") String lt) {
034
035    if (Objects.isNull(gte) && Objects.isNull(gt)) {
036      throw new IllegalArgumentException("Specify gte or gt");
037    }
038    if (Objects.isNull(lte) && Objects.isNull(lt)) {
039      throw new IllegalArgumentException("Specify lte or lt");
040    }
041    if (!Objects.isNull(gte) && !Objects.isNull(gt)) {
042      throw new IllegalArgumentException("Specify gte or gt, not both");
043    }
044    if (lte != null && lt != null) {
045      throw new IllegalArgumentException("Specify lte or lt, not both");
046    }
047    this.gte = gte;
048    this.lte = lte;
049    this.gt = gt;
050    this.lt = lt;
051  }
052
053  @JsonProperty("gt")
054  String gt;
055
056  @JsonProperty("lt")
057  String lt;
058
059  @JsonProperty("gte")
060  String gte;
061
062  @JsonProperty("lte")
063  String lte;
064
065  public String getGte() {
066    return gte;
067  }
068
069  public String getLte() {
070    return lte;
071  }
072
073  public String getGt() {
074    return gt;
075  }
076
077  public String getLt() {
078    return lt;
079  }
080}