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

📄 datanode.java

📁 《Java网络程序设计.rar》包括三个网络程序的源代码。
💻 JAVA
字号:
package org.impact.stars.control.web.checker;

/* the data node of the abstract access tree*/

import java.util.*;
import java.sql.*;
import javax.swing.tree.DefaultMutableTreeNode;

import org.impact.stars.util.*;
import org.impact.stars.control.exceptions.*;


public class Datanode extends DefaultMutableTreeNode {
        
	private String  dataID;
        private String  parentID;
	private String	name;
        private String  read ="0";
	private String	write ="0";
        private String  uperBranch ="0";  //to show whether some lower nodes are using this node 1: use
        private String  downBranch ="0";  //to show whether some lower nodes are blocking all of other nodes: global
        public int    lastWriteMin = 0;
	
	/**
	 * Datanode constructor comment.
	 */
	public Datanode() {
		super();
        }
	public Datanode(String adataID, String aparentID, String aname) {
                super();
		this.name = aname;
                this.parentID = aparentID;
                this.dataID = adataID;
	}
        
	public String getDataID(){
		return dataID;
	}
        
        public String getName(){
                return name;
        }
        
        public void setRead(String aread)
        {
            this.read= aread;
        }
        
        public String getRead(){
               return read;
        }
        
        public void setWrite(String awrite){
               this.write = awrite;
               lastWriteMin = (new GregorianCalendar()).get(Calendar.MINUTE);
        }

        public String getWrite()
        {
                return write;
        }
        
        public void setUperBranch(String aupb){
               this.uperBranch = aupb;
        }

        
        public String getUperBranch()
        {
                return uperBranch;
        }

        public void setDownBranch(String aupb){
               this.downBranch = aupb;
        }

        
        public String getDownBranch()
        {
                return downBranch;
        }
        
        public String getParentID()
        {
            return parentID;
        }
        
        public int getLastWriteMin()
        {
            if(lastWriteMin!=0)
            {
            return lastWriteMin;
            }
            else
            {
                return (new GregorianCalendar()).get(Calendar.MINUTE);
            }
        }
/*
	public static void linkFamily(Datanode pa, Datanode akid) {
            
			pa.children.addElement(akid);
			akid.parent = pa;
	}
 */
    /* recursive function to return a datanode with the specified ID
     */
        public Datanode findDatanode(String adataid)
        {  
            Debug.println("Datanode: findDatanode :"+ adataid + "for" + this.getDataID());
            Datanode findnode = null;
            if(adataid.equals(this.getDataID()))
            {
                Debug.println("Datanode: found Datanode :"+ adataid);
                return this;
            }
            else        
            {    
                Enumeration enum = this.children();
                while(enum.hasMoreElements())
                    {                        
                        Datanode newnode = (Datanode)enum.nextElement();
                        findnode = newnode.findDatanode(adataid);
                        if (findnode!=null)
                        {
                            return findnode;
                        }
                        
                        /*
                        Debug.println("Datanode: compare "+ newnode.getDataID());
                        if(adataid.equals(newnode.getDataID()))
                        {
                            Debug.println("Found Datanode "+ adataid);                            
                            return newnode;
                        }
                        else
                        {
                            findnode = newnode.findDatanode(adataid);
                        }*/
               }
               return findnode; 
            }
        }
        
        //breadFirstSearch
        public Datanode findDatanodeBF(String adataid)
        {
           Enumeration eu = this.breadthFirstEnumeration();
           while(eu.hasMoreElements())
           {
               Datanode node =(Datanode)eu.nextElement();
            if ((node.getDataID()).equals(adataid))
            {
                return node;
            }
           }
           return null;
        }
           
          
        /*
         *This method set all of the uper branch of this node
         */
        public void setallUperBranch(String w){
            this.setUperBranch(w);
            Datanode parent = (Datanode)this.parent;
            if (parent!=null)
            {
              parent.setallUperBranch(w);
            }
        }
        
        /*
         *This method set all of the down node of this node
         */
        
        public void setallDownWrite(String w){
            Enumeration enum = this.children();

            while(enum.hasMoreElements())
                {                        
                    Datanode newnode = (Datanode)enum.nextElement();
                    newnode.setWrite(w);
                    newnode.setallDownWrite(w);
            }
        }

        /*
         *This method clean all branch above this node during update
         * if all of the children of a clean node are clean, the branch is clean
         */

        public void cleanBranch(){
            Enumeration enum = this.children();
            while(enum.hasMoreElements())
                {                        
                    Datanode childnode = (Datanode)enum.nextElement();
                    if (childnode.getUperBranch().equals("1"))
                    {
                        return;
                    }
            }
            if (this.getWrite().equals("0")) 
            {
                this.setUperBranch("0");
                if (this.parent!=null)
                {
                    ((Datanode)(this.parent)).cleanBranch();
                }
            }
        }        
}

⌨️ 快捷键说明

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