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.model.predicate;
015
016import org.gbif.api.model.common.search.SearchParameter;
017import org.gbif.api.util.RangeValue;
018
019import java.util.Objects;
020import java.util.StringJoiner;
021
022import javax.validation.constraints.NotNull;
023
024import com.fasterxml.jackson.annotation.JsonCreator;
025import com.fasterxml.jackson.annotation.JsonProperty;
026
027import io.swagger.v3.oas.annotations.media.Schema;
028
029/**
030 * This predicate checks if its {@code key} is within the range {@code value}.
031 *
032 * Note: ALA only, not advertised as part of the public GBIF API.
033 */
034@Schema(
035  description = "This predicate checks if its `key` is within the range `value`."
036)
037public class RangePredicate<S extends SearchParameter> implements Predicate {
038
039    @Schema(description = "The search parameter to test.")
040    @NotNull
041    private final S key;
042
043    @Schema(description = "The range value to test for.")
044    @NotNull private final RangeValue value;
045
046    @JsonCreator
047    public RangePredicate(@JsonProperty("key") S key, @JsonProperty("value") RangeValue value) {
048        Objects.requireNonNull(key, "<key> may not be null");
049        Objects.requireNonNull(value, "<value> may not be null");
050        this.key = key;
051        this.value = value;
052    }
053
054    public S getKey() {
055        return key;
056    }
057
058    public RangeValue getValue() {
059        return value;
060    }
061
062  @Override
063  public String toString() {
064    return new StringJoiner(", ", this.getClass().getSimpleName() + "[", "]")
065      .add("key=" + key)
066      .add("value='" + value + "'")
067      .toString();
068  }
069}