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 java.util.Objects;
017import java.util.StringJoiner;
018
019import javax.validation.constraints.NotNull;
020
021import com.fasterxml.jackson.annotation.JsonCreator;
022import com.fasterxml.jackson.annotation.JsonProperty;
023
024import io.swagger.v3.oas.annotations.media.Schema;
025
026/**
027 * This predicate negates its subpredicate.
028 * Note: This may not work with all combinations of subpredicates.
029 */
030@Schema(
031  description = "This predicate negates its subpredicate."
032)
033public class NotPredicate implements Predicate {
034
035  @Schema(
036    description = "The sub-predicate to negate."
037  )
038  @NotNull
039  private final Predicate predicate;
040
041  @JsonCreator
042  public NotPredicate(@JsonProperty("predicate") Predicate predicate) {
043    Objects.requireNonNull(predicate);
044
045    this.predicate = predicate;
046  }
047
048  public Predicate getPredicate() {
049    return predicate;
050  }
051
052  @Override
053  public boolean equals(Object o) {
054    if (this == o) {
055      return true;
056    }
057    if (o == null || getClass() != o.getClass()) {
058      return false;
059    }
060    NotPredicate that = (NotPredicate) o;
061    return Objects.equals(predicate, that.predicate);
062  }
063
064  @Override
065  public int hashCode() {
066    return Objects.hash(predicate);
067  }
068
069  @Override
070  public String toString() {
071    return new StringJoiner(", ", NotPredicate.class.getSimpleName() + "[", "]")
072      .add("predicate=" + predicate)
073      .toString();
074  }
075}