001/*
002 * Copyright 2014 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.model.occurrence.predicate;
017
018import javax.validation.constraints.NotNull;
019
020import com.google.common.base.Objects;
021import com.google.common.base.Preconditions;
022import org.codehaus.jackson.annotate.JsonCreator;
023import org.codehaus.jackson.annotate.JsonProperty;
024
025/**
026 * This predicate negates its subpredicate.
027 * Note: This may not work with all combinations of subpredicates.
028 */
029public class NotPredicate implements Predicate {
030
031  @NotNull
032  private final Predicate predicate;
033
034  @JsonCreator
035  public NotPredicate(@JsonProperty("predicate") Predicate predicate) {
036    Preconditions.checkNotNull(predicate);
037
038    this.predicate = predicate;
039  }
040
041  public Predicate getPredicate() {
042    return predicate;
043  }
044
045  @Override
046  public boolean equals(Object obj) {
047    if (this == obj) {
048      return true;
049    }
050
051    if (!(obj instanceof NotPredicate)) {
052      return false;
053    }
054
055    NotPredicate that = (NotPredicate) obj;
056    return Objects.equal(this.predicate, that.predicate);
057  }
058
059  @Override
060  public int hashCode() {
061    return Objects.hashCode(predicate);
062  }
063
064  @Override
065  public String toString() {
066    return Objects.toStringHelper(this).add("predicate", predicate).toString();
067  }
068}