⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binaryoperatormeasure.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/**
 * <p>Title: XELOPES</p>
 * <p>Description: Java Data Mining API. Supported standarts: <a href="http://www.dmg.org">Predictive Model Markup Language (PMML 2.0) </a>;  <a href="http://www.omg.org/cwm">DataMining specification for Common Warehouse Metamodel (OMG)</a>.</p>
 * <p>Copyright: Copyright (c) 2002-2004 prudsys AG</p>
 * <p>Company: prudsys, ZSoft</p>
 * @authorv Michael Thess
 * @version 1.2
 */

package com.prudsys.pdm.Olap.Metadata.Measures;

import javax.olap.OLAPException;

import com.prudsys.pdm.Olap.Metadata.Measure;

/**
 * Measure which runs binary operation (+, -, etc.) between two measures.
 */
public class BinaryOperatorMeasure extends Measure {

  // -----------------------------------------------------------------------
  //  Constants declarations
  // -----------------------------------------------------------------------
  /** Plus. */
  public static final int PLUS = 0;

  /** Minius. */
  public static final int MINUS = 1;

  /** Times. */
  public static final int TIMES = 2;

  /** Over. */
  public static final int OVER = 3;

  /** Minimum. */
  public static final int MIN = 4;

  /** Maximum. */
  public static final int MAX = 5;

  /** Power. */
  public static final int POW = 6;


  // -----------------------------------------------------------------------
  //  Variables declarations
  // -----------------------------------------------------------------------
  /** First measure. */
  protected Measure measure1;

  /** Second measure. */
  protected Measure measure2;

  // -----------------------------------------------------------------------
  //  Constructor
  // -----------------------------------------------------------------------
  /**
   * Empty constructor.
   */
  public BinaryOperatorMeasure() {
  }

  /**
   * BinaryOperaorMeasure from given subtype and both measures.
   *
   * @param subtype measure subtype
   * @param measure1 first measure
   * @param measure2 second measure
   */
  public BinaryOperatorMeasure(int subtype, Measure measure1, Measure measure2) {

    this.subtype  = subtype;
    this.measure1 = measure1;
    this.measure2 = measure2;
  }

  // -----------------------------------------------------------------------
  //  Getter and setter methods
  // -----------------------------------------------------------------------
  /**
   * Returns a first measure.
   *
   * @return first measure
   */
  public Measure getMeasure1() {

    return measure1;
  }

  /**
   * Sets first measure.
   *
   * @param measure1 new first measure
   */
  public void setMeasure1(Measure measure1) {

    this.measure1 = measure1;
  }

  /**
   * Returns a second measure.
   *
   * @return second measure
   */
  public Measure getMeasure2() {

    return measure2;
  }

  /**
   * Sets second measure.
   *
   * @param measure2 new second measure
   */
  public void setMeasure2(Measure measure2) {

    this.measure2 = measure2;
  }

  // -----------------------------------------------------------------------
  //  Method of measure value calculation
  // -----------------------------------------------------------------------
  /**
   * Calculates binary operator measure value.
   *
   * @return measure value
   * @throws OLAPException unknwn subtype
   */
  public double measureValue() throws OLAPException {

    double value1 = measure1.measureValue();
    double value2 = measure2.measureValue();

    if (subtype == PLUS)
      return value1+value2;
    else if (subtype == MINUS)
      return value1-value2;
    if (subtype == TIMES)
      return value1*value2;
    if (subtype == OVER)
      return value1/value2;
    if (subtype == MIN)
      return Math.min(value1, value2);
    if (subtype == MAX)
      return Math.max(value1, value2);
    if (subtype == POW)
      return Math.pow(value1, value2);

    else
      throw new OLAPException("unknown subtype");

  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -