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

📄 compoundmeasure.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 is aggregated over an attribute.
 */
public class CompoundMeasure extends Measure {

  // -----------------------------------------------------------------------
  //  Constants declarations
  // -----------------------------------------------------------------------
  /** Sum. */
  public static final int SUM = 0;

  /** Product. */
  public static final int PRODUCT = 1;

  // -----------------------------------------------------------------------
  //  Variables declarations
  // -----------------------------------------------------------------------
  /** Measures array. */
  protected Measure[] measures;

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

  /**
   * CompoundMeasure from given subtype and number of measures.
   * Measures must be set using the setMeasure method.
   *
   * @param subtype measure subtype
   * @param measuresNumber number of argument measures
   */
  public CompoundMeasure(int subtype, int measuresNumber) {

    this.subtype = subtype;
    this.measures = new Measure[measuresNumber];
  }

  // -----------------------------------------------------------------------
  //  Getter and setter methods
  // -----------------------------------------------------------------------
  /**
   * Returns number of measures.
   *
   * @return number of measures
   */
  public int getMeasuresNumber() {

    return ( measures != null ) ? measures.length : 0;
  }

  /**
   * Returns a measure at a given position.
   *
   * @param n position of the measure
   * @return measure at given position
   */
  public Measure getMeasure(int n) {

    return measures[n];
  }

  /**
   * Sets measure on a given position.
   *
   * @param measure measure to set
   * @param n position of measure
   */
  public void setMeasure(Measure measure, int n) {

    measures[n] = measure;
  }

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

    double value = 0.0;
    int n = getMeasuresNumber();
    switch(subtype)
    {
      case SUM:
        for(int i=0;i<n;i++)
          value = value + measures[i].measureValue();
        break;
      case PRODUCT:
        for(int i=0;i<n;i++)
          value = value*measures[i].measureValue();
        break;
      default:
        throw new OLAPException("unknown subtype");
    }

    return value;
  }

}

⌨️ 快捷键说明

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