001/*
002 * Copyright 2014 Global Biodiversity Information Facility (GBIF)
003 * Licensed under the Apache License, Version 2.0 (the "License");
004 * you may not use this file except in compliance with the License.
005 * You may obtain a copy of the License at
006 * http://www.apache.org/licenses/LICENSE-2.0
007 * Unless required by applicable law or agreed to in writing, software
008 * distributed under the License is distributed on an "AS IS" BASIS,
009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010 * See the License for the specific language governing permissions and
011 * limitations under the License.
012 */
013package org.gbif.api.model.occurrence.predicate;
014
015import org.gbif.api.model.occurrence.search.OccurrenceSearchParameter;
016
017import javax.validation.constraints.NotNull;
018
019import com.google.common.base.Objects;
020import com.google.common.base.Preconditions;
021import org.codehaus.jackson.annotate.JsonCreator;
022import org.codehaus.jackson.annotate.JsonProperty;
023
024public class IsNotNullPredicate implements Predicate {
025
026  @NotNull
027  private final OccurrenceSearchParameter parameter;
028
029  @JsonCreator
030  public IsNotNullPredicate(@JsonProperty("parameter") OccurrenceSearchParameter parameter) {
031    Preconditions.checkNotNull(parameter, "<parameter> may not be null");
032    this.parameter = parameter;
033    checkPredicateAllowed();
034  }
035
036  public OccurrenceSearchParameter getParameter() {
037    return parameter;
038  }
039
040  /**
041   * @throws IllegalArgumentException if the key SearchParameter is Geometry
042   */
043  private void checkPredicateAllowed() {
044    if (OccurrenceSearchParameter.GEOMETRY == parameter) {
045      throw new IllegalArgumentException("IsNotNull predicate is not supported for Geometry parameter");
046    }
047  }
048
049  @Override
050  public int hashCode() {
051    return Objects.hashCode(parameter);
052  }
053
054  @Override
055  public String toString() {
056    return Objects.toStringHelper(this).add("parameter", parameter).toString();
057  }
058
059}