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;
017
018import java.util.Objects;
019
020import com.fasterxml.jackson.annotation.JsonCreator;
021import com.fasterxml.jackson.annotation.JsonProperty;
022
023import io.swagger.v3.oas.annotations.media.Schema;
024
025/**
026 * This predicate checks if its {@code key} is greater than or equal its {@code value}.
027 */
028@Schema(
029  description = "This predicate checks if its `key` is greater than or equal to to its `value`."
030)
031public class GreaterThanOrEqualsPredicate<S extends SearchParameter> extends SimplePredicate<S> {
032
033  @JsonCreator
034  public GreaterThanOrEqualsPredicate(
035      @JsonProperty("key") S key, @JsonProperty("value") String value) {
036    super(true, key, value, null);
037  }
038
039  @Override
040  public boolean equals(Object obj) {
041    if (this == obj) {
042      return true;
043    }
044
045    if (!(obj instanceof GreaterThanOrEqualsPredicate)) {
046      return false;
047    }
048
049    SimplePredicate<S> that = (SimplePredicate<S>) obj;
050    return Objects.equals(this.getKey(), that.getKey())
051      && Objects.equals(this.getValue(), that.getValue());
052  }
053
054  @Override
055  public int hashCode() {
056    return Objects.hash(this.getKey(), this.getValue());
057  }
058}