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

com.opengamma.strata.math.impl.integration.Integrator1D Maven / Gradle / Ivy

There is a newer version: 2.12.46
Show newest version
/*
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.strata.math.impl.integration;

import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opengamma.strata.collect.ArgChecker;

/**
 * Class for defining the integration of 1-D functions.
 *  
 * @param  Type of the function output and result
 * @param  Type of the function inputs and integration bounds
 */
public abstract class Integrator1D implements Integrator> {

  private static final Logger log = LoggerFactory.getLogger(Integrator1D.class);

  /**
   * {@inheritDoc}
   */
  @Override
  public T integrate(Function f, U[] lower, U[] upper) {
    ArgChecker.notNull(f, "function was null");
    ArgChecker.notNull(lower, "lower bound array was null");
    ArgChecker.notNull(upper, "upper bound array was null");
    ArgChecker.notEmpty(lower, "lower bound array was empty");
    ArgChecker.notEmpty(upper, "upper bound array was empty");
    ArgChecker.notNull(lower[0], "lower bound was null");
    ArgChecker.notNull(upper[0], "upper bound was null");
    if (lower.length > 1) {
      log.info("Lower bound array had more than one element; only using the first");
    }
    if (upper.length > 1) {
      log.info("Upper bound array had more than one element; only using the first");
    }
    return integrate(f, lower[0], upper[0]);
  }

  /**
   * 1-D integration method.
   * @param f The function to integrate, not null
   * @param lower The lower bound, not null
   * @param upper The upper bound, not null
   * @return The result of the integration
   */
  public abstract T integrate(Function f, U lower, U upper);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy