All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.linkedin.dagli.util.function.BooleanNegatedFunction7 Maven / Gradle / Ivy

Go to download

DAG-oriented machine learning framework for bug-resistant, readable, efficient, maintainable and trivially deployable models in Java and other JVM languages

There is a newer version: 15.0.0-beta9
Show newest version
// AUTOGENERATED CODE.  DO NOT MODIFY DIRECTLY!  Instead, please modify the util/function/BooleanNegatedFunction.ftl file.
// See the README in the module's src/template directory for details.
package com.linkedin.dagli.util.function;

import java.util.Objects;


/**
 * Implements the negation of the result of a boolean function.
 *
 * This class is {@link java.io.Serializable} to allow its subclass (also named Serializable) to be serialized, but
 * should not be regarded as "safely serializable" since the function it wraps is not itself guaranteed to be
 * serializable.
 */
class BooleanNegatedFunction7 implements BooleanFunction7,
    java.io.Serializable {
  private static final int CLASS_HASH = BooleanNegatedFunction7.class.hashCode();

  private final BooleanFunction7 _function;

  // no-arg constructor for Kryo
  private BooleanNegatedFunction7() {
    _function = null;
  }

  /**
   * Creates a new instance that will negate the result provided by the given, wrapped function.
   *
   * @param function the function to be wrapped
   */
  private BooleanNegatedFunction7(BooleanFunction7 function) {
    _function = Objects.requireNonNull(function);
  }

  /**
   * Returns a function that will have a result that is a negation of the function provided.  If the passed function
   * is itself of this type, its underlying (wrapped) function will be returned; otherwise, a new instance of this class
   * will be created to wrap the passed function.
   *
   * @param function the function whose result will be negated
   * @return a function (which may or may not be new) that negates the return value of the provided function
   */
  static  BooleanFunction7 negate(
      BooleanFunction7 function) {
    if (function instanceof BooleanNegatedFunction7) {
      return ((BooleanNegatedFunction7) function)._function; // negation of a negation is the original function
    }
    return new BooleanNegatedFunction7<>(function);
  }

  @Override
  public boolean apply(A value1, B value2, C value3, D value4, E value5, F value6, G value7) {
    return !_function.apply(value1, value2, value3, value4, value5, value6, value7);
  }

  @Override
  public int hashCode() {
    return CLASS_HASH + _function.hashCode();
  }

  @Override
  public boolean equals(Object obj) {
    if (obj instanceof BooleanNegatedFunction7) {
      return this._function.equals(((BooleanNegatedFunction7) obj)._function);
    }
    return false;
  }

  static class Serializable extends BooleanNegatedFunction7 implements
      BooleanFunction7.Serializable {
    private static final long serialVersionUID = 1;

    // no-arg constructor for Kryo
    private Serializable() {
    }

    /**
     * Creates a new instance that will negate the result provided by the given, wrapped function.
     *
     * @param function the function to be wrapped
     */
    private Serializable(BooleanFunction7.Serializable function) {
      super(function);
    }

    /**
     * Returns a function that will have a result that is a negation of the function provided.  If the passed function
     * is itself of this type, its underlying (wrapped) function will be returned; otherwise, a new instance of this class
     * will be created to wrap the passed function.
     *
     * @param function the function whose result will be negated
     * @return a function (which may or may not be new) that negates the return value of the provided function
     */
    static  BooleanFunction7.Serializable negate(
        BooleanFunction7.Serializable function) {
      if (function instanceof BooleanNegatedFunction7.Serializable) {
        // negation of a negation is the original function
        return (BooleanFunction7.Serializable) ((BooleanNegatedFunction7) function)._function;
      }
      return new BooleanNegatedFunction7.Serializable<>(function);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy