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

📄 miningtreenode.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.
 */

 /**
  * 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 Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
  * @author Michael Thess
  * @version 1.1
  */

package com.prudsys.pdm.Core;

import java.util.Arrays;
import java.util.Enumeration;
import java.util.Vector;

/**
 * Node of a tree structure.
 * This means that any node may contain multiple children and one parent. <p>
 *
 * From PDM CWM extension.
 *
 * @see MiningHierarchyNode
 */
public class MiningTreeNode extends com.prudsys.pdm.Cwm.Core.Class
{
    // -----------------------------------------------------------------------
    //  Variables declarations
    // -----------------------------------------------------------------------
    /** Parent node. */
    public MiningTreeNode parent;

    /** Is node root node? */
    public boolean root;

    /** Is node leaf node? */
    public boolean leaf;

    /** Level of node. */
    public int level;

    /** Children of node. */
    public MiningTreeNode[] children;

    /** Are children allowed? */
    public boolean allowsChildren;

    // -----------------------------------------------------------------------
    //  Methods of node manipulation
    // -----------------------------------------------------------------------
    /**
     * Get number of childs.
     *
     * @return number of childs
     */
    public int getChildCount()
    {
      return ( children != null ) ? children.length : 0;
    }

    /**
     * Get child node at specified index.
     *
     * @param childIndex index of child
     * @return child at specified index
     */
    public MiningTreeNode getChildAt( int childIndex )
    {
        return ( children != null ) ? children[childIndex] : null;
    }

    /**
     * Are children allowed?
     *
     * @return true, if allowed, elso false
     */
    public boolean getAllowsChildren()
    {
        return allowsChildren;
    }

    /**
     * Return list of all children
     *
     * @return all children
     */
    public Enumeration children()
    {
        if( children != null )
        {
            Vector v = new Vector( Arrays.asList( children ) );
            return v.elements();
        }
        else
        {
            return null;
        }
    }

    /**
     * Get index of child node.
     *
     * @param node child node
     * @return index of child node, -1 if not found
     */
    public int getIndex( MiningTreeNode node )
    {
        int index = -1;
        if( children == null )
        {
            index = -1;
        }
        else
        {
            for( int i = 0; i < children.length; i++ )
            {
                if( children[i].equals( node ) )
                {
                    index = i;
                }
            }
        }
        return index;
    }

    /**
     * Adds new child to node.
     *
     * @param child new child to add
     */
    public void addChild(MiningTreeNode child)
    {
      if(children == null) children = new MiningTreeNode[0];
      MiningTreeNode[] childs = new MiningTreeNode[children.length+1];
      System.arraycopy(children,0,childs,0,children.length);
      childs[children.length] = child;
      children = childs;
      leaf = false;
    }

    /**
     * Remove child from node.
     *
     * @param child child to be removed
     */
    public void removeChild(MiningTreeNode child)
    {
      if(children == null) return;
      int index = getIndex(child);
      if(index != -1)
      {
        removeChild(index);
      }
    }

    /**
     * Remove child of given index.
     *
     * @param childIndex index of child to be removed
     */
    public void removeChild(int childIndex)
    {
        MiningTreeNode[] childs = new MiningTreeNode[children.length-1];
        System.arraycopy(children,0,childs,0,childIndex);
        System.arraycopy(children,childIndex+1,childs,childIndex,children.length-childIndex-1);
        children = childs;
        if(children.length == 0) leaf = true;
    }

    /**
     * Remove all children.
     */
    public void removeAllChildren()
    {
      children = null;
      leaf = true;
    }

    /**
     * Calculates total number of all children by recursive call.
     *
     * @return number of all children
     */
    public int getTotalNumberOfChildren() {

      int nchild = getChildCount();
      for (int i = 0; i < getChildCount(); i++) {
        nchild = nchild + getChildAt(i).getTotalNumberOfChildren();
      };

      return nchild;
    }

    /**
     * Return parent node.
     *
     * @return parent node
     */
    public MiningTreeNode getParent()
    {
        return parent;
    }

    /**
     * Set parent node.
     *
     * @param parent parent node to set
     */
    public void setParent( MiningTreeNode parent )
    {
        this.parent = parent;
    }

    /**
     * Calculates total number of all parents by recursive call.
     * Of course, this should return the same result as
     * the method getLevel.
     *
     * @return number of all parents
     */
    public int getTotalNumberOfParents() {

      int nparent = 0;
      if (getParent() != null)
        nparent = nparent + 1 + getParent().getTotalNumberOfParents();

      return nparent;
    }

    /**
     * Is node a leaf?
     *
     * @return true, if leaf, elso false
     */
    public boolean isLeaf()
    {
        return leaf;
    }

    /**
     * Set node leaf status.
     *
     * @param leaf true if node is leaf, else false
     */
    public void setLeaf( boolean leaf )
    {
        this.leaf = leaf;
    }

    /**
     * Is node a root?
     *
     * @return true, if root, elso false
     */
    public boolean isRoot()
    {
        return root;
    }

    /**
     * Set node root status.
     *
     * @param root true if node is root, else false
     */
    public void setRoot( boolean root )
    {
        this.root = root;
    }

    /**
     * Return hierarchy level (root level = 0).
     *
     * @return level of node
     */
    public int getLevel()
    {
        return level;
    }

    /**
     * Set level (root level = 0).
     *
     * @param lev node's level
     */
    public void setLevel( int lev )
    {
        this.level = lev;
    }
}

⌨️ 快捷键说明

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