📄 hierarchicaldimension.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.
*/
/**
* Title: XELOPES Data Mining Library
* Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
* Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
* Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
* @author Michael Thess
* @version 1.2
*/
package com.prudsys.pdm.Olap.Metadata;
import java.util.Collection;
import java.util.Iterator;
import javax.olap.OLAPException;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.CategoryHierarchy;
import com.prudsys.pdm.Olap.OlapEngine;
/**
* Xelopes OLAP Dimension with Level-based hierarchy.
*/
public class HierarchicalDimension extends Dimension
{
// -----------------------------------------------------------------------
// Variables declarations
// -----------------------------------------------------------------------
/** Object for handling the hierarchies. */
protected CategoryHierarchy catHierarchy = new CategoryHierarchy();
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
/**
* Empty constructor.
*/
public HierarchicalDimension() {
}
/**
* Constructor with reference to OLAP engine object.
*
* @param olapEngine OLAP engine object
*/
public HierarchicalDimension(OlapEngine olapEngine) {
this.olapEngine = olapEngine;
}
// -----------------------------------------------------------------------
// Getter and setter methods
// -----------------------------------------------------------------------
/**
* Returns the number of levels.
*
* @return number of levels
*/
public int getNumberOfLevels() {
return getNumberOfDimensionAttributes();
}
/**
* Returns categorical attribute that corresponds to specified level.
*
* @param level specified level
* @return attribute of this level, null if not found
*/
public CategoricalAttribute getLevelAttribute(int level) {
return (CategoricalAttribute) getDimensionAttribute(level);
}
/**
* Returns category hierarchy object.
*
* @return category hierarchy object
*/
public CategoryHierarchy getCatHierarchy() {
return catHierarchy;
}
/**
* Sets category hierarchy object.
*
* @param catHierarchy new category hierarchy object
*/
public void setCatHierarchy(CategoryHierarchy catHierarchy) {
this.catHierarchy = catHierarchy;
}
/**
* Add input attribute. Automatically extends level based hierarchy
* by creating the corresponding hierarchy level association.
*
* @param attribute new input attribute
* @throws OLAPException attribute is not instance of mining attribute class
*/
public void addInputAttribute(org.omg.cwm.objectmodel.core.Attribute attribute) throws OLAPException {
// Add attribute to dimension:
super.addInputAttribute(attribute);
// Create level and add to dimension:
javax.olap.metadata.Level level = olapEngine.getLevel().createLevel();
level.setName( attribute.getName() );
addMemberSelection(level);
attribute.setOwner(level);
// Get hierarchy:
javax.olap.metadata.LevelBasedHierarchy levelBasedHierarchy = null;
Collection hcoll = getHierarchy();
Iterator it = hcoll.iterator();
for (int i = 0; i < hcoll.size(); i++) {
javax.olap.metadata.Hierarchy hierarchy = (javax.olap.metadata.Hierarchy) it.next();
if (hierarchy instanceof javax.olap.metadata.LevelBasedHierarchy)
levelBasedHierarchy = (javax.olap.metadata.LevelBasedHierarchy) hierarchy;
};
if (levelBasedHierarchy == null) {
levelBasedHierarchy = olapEngine.getLevelBasedHierarchy().createLevelBasedHierarchy();
levelBasedHierarchy.setName("Standard");
addHierarchy(levelBasedHierarchy);
}
// Create hierarchy level asociation and add to hierarchy:
javax.olap.metadata.HierarchyLevelAssociation hierarchyLevelAssociation =
olapEngine.getHierarchyLevelAssociation().createHierarchyLevelAssociation();
hierarchyLevelAssociation.setName( getName() );
hierarchyLevelAssociation.setCurrentLevel(level);
levelBasedHierarchy.addHierarchyLevelAssociation(hierarchyLevelAssociation);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -