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; 019import java.util.StringJoiner; 020import java.util.UUID; 021 022import com.fasterxml.jackson.annotation.JsonCreator; 023import com.fasterxml.jackson.annotation.JsonProperty; 024 025import io.swagger.v3.oas.annotations.media.Schema; 026import jakarta.annotation.Nullable; 027 028/** 029 * This predicate checks if its {@code key} is equal to its {@code value}. 030 */ 031@Schema( 032 description = "This predicate checks if its `key` is equal to its `value`." 033) 034public class EqualsPredicate<S extends SearchParameter> extends SimplePredicate<S> { 035 036 @Schema( 037 description = "Specify which taxonomy to use." 038 ) 039 @Nullable 040 private final UUID checklistKey; 041 042 public EqualsPredicate(S key, String value, Boolean matchCase) { 043 this(key, value, matchCase, null); 044 } 045 046 @JsonCreator 047 public EqualsPredicate( 048 @JsonProperty("key") S key, 049 @JsonProperty("value") String value, 050 @Nullable @JsonProperty(value = "matchCase") Boolean matchCase, 051 @Nullable @JsonProperty(value = "checklistKey") UUID checklistKey 052 ) { 053 super(false, key, value, matchCase); 054 this.checklistKey = checklistKey; 055 } 056 057 public UUID getChecklistKey() { 058 return checklistKey; 059 } 060 061 @Override 062 public boolean equals(Object o) { 063 if (this == o) { 064 return true; 065 } 066 if (o == null || getClass() != o.getClass()) { 067 return false; 068 } 069 SimplePredicate<S> that = (SimplePredicate<S>) o; 070 return this.getKey() == that.getKey() 071 && Objects.equals(this.getValue(), that.getValue()) 072 && this.isMatchCase() == that.isMatchCase() 073 && Objects.equals(this.checklistKey, ((EqualsPredicate<?>) o).checklistKey); 074 } 075 076 @Override 077 public int hashCode() { 078 return Objects.hash(getKey(), this.getValue(), this.isMatchCase(), checklistKey); 079 } 080 081 @Override 082 public String toString() { 083 return new StringJoiner(", ", this.getClass().getSimpleName() + "[", "]") 084 .add("key=" + getKey()) 085 .add("value='" + getValue() + "'") 086 .add("matchCase='" + this.isMatchCase() + "'") 087 .add("checklistKey='" + checklistKey + "'") 088 .toString(); 089 } 090}