FalsePredicate.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.collections4.functors;

  18. import java.io.Serializable;

  19. import org.apache.commons.collections4.Predicate;

  20. /**
  21.  * Predicate implementation that always returns false.
  22.  *
  23.  * @param <T> the type of the input to the predicate.
  24.  * @since 3.0
  25.  */
  26. public final class FalsePredicate<T> extends AbstractPredicate<T> implements Serializable {

  27.     /** Serial version UID */
  28.     private static final long serialVersionUID = 7533784454832764388L;

  29.     /** Singleton predicate instance */
  30.     @SuppressWarnings("rawtypes") // the static instance works for all types
  31.     public static final Predicate INSTANCE = new FalsePredicate<>();

  32.     /**
  33.      * Gets a typed instance.
  34.      *
  35.      * @param <T> the type that the predicate queries
  36.      * @return the singleton instance
  37.      * @since 4.0
  38.      */
  39.     public static <T> Predicate<T> falsePredicate() {
  40.         return INSTANCE;
  41.     }

  42.     /**
  43.      * Restricted constructor.
  44.      */
  45.     private FalsePredicate() {
  46.     }

  47.     /**
  48.      * Returns the singleton instance.
  49.      *
  50.      * @return the singleton instance.
  51.      */
  52.     private Object readResolve() {
  53.         return INSTANCE;
  54.     }

  55.     /**
  56.      * Evaluates the predicate returning false always.
  57.      *
  58.      * @param object  the input object
  59.      * @return false always
  60.      */
  61.     @Override
  62.     public boolean test(final T object) {
  63.         return false;
  64.     }

  65. }