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

📄 mddbpacket.java

📁 java B++树 一个很好的算法来实现这些问题 推荐!
💻 JAVA
字号:
package mddb.packets;

import java.util.*;
import java.awt.Point;

//是所有其它类型的包的基类abstract
public  class MddbPacket {
    //网络包分类码=======================
    public final static int FRAME_GROUP_PKG = -1;       //分组包
    public final static int FRAME_ROUTINE_PKG = -2;     //路由包
    public final static int FRAME_CQUERY_PKG = -3;      //查询包
    //网络数据包(分组包)类型码============
    public final static int NET_HELLO = 0;
    public final static int NET_RHELLO = 1;
    public final static int NET_RM = 2;
    public final static int NET_RRM = 3;
    public final static int NET_DELAY = 4;
    public final static int NET_MI = 5;
    public final static int NET_NG = 6;
    //网络路由包类型码=====================
    public final static int NET_RQ = 7;
    public final static int NET_RRQ= 8;

    //表头内容-------------------------------------------------------------------
    protected Point srcAddr;          //源地址--节点位置,注意源地址和包起始地址可能不同
    protected long srcId;             //源节点的ID
    protected Point destAddr;         //目的地址--节点位置
    protected int pathLength;         //路径长度--两点间的距离
    protected ArrayList routineList;  //路由表
    protected int type;               //包的类型--在上面有定义
    protected long timeStamp;         //时间戳,记录包的创建时间

    protected String data; //用于记录表数据内容==注意对于空包应该加上"@"作为空数据标志
    //setters-------------------------------------------------------------------
    public void setType( int type ) {
        this.type = type;
    }

    public void setDestAddr( Point destAddr ) {
        this.destAddr = destAddr;
    }

    public void setData( String data ) {
        this.data = data;
    }

    public void setPathLength( int pathLength ) {
        this.pathLength = pathLength;
    }

    public void setTimeStamp( long timeStamp ) {
        this.timeStamp = timeStamp;
    }

    public void setRoutineList( ArrayList routineList ) {
        this.routineList = routineList;
    }

    public void setSrcAddr( Point srcAddr ) {
        this.srcAddr = srcAddr;
    }

    public void setSrcId( long srcId ) {
        this.srcId = srcId;
    }

    //--getters-----------------------------------------------------------------
    public Point getDestAddr() {
        return destAddr;
    }

    public String getData() {
        return data;
    }

    public int getPathLength() {
        return pathLength;
    }

    public long getTimeStamp() {
        return timeStamp;
    }

    public ArrayList getRoutineList() {
        return routineList;
    }

    public Point getSrcAddr() {
        return srcAddr;
    }

    public int getType() {
        return type;
    }

    public long getSrcId() {
        return srcId;
    }

    //getters end---------------------------------------------------------------
    //==========================================================================
    public MddbPacket( Point srcAddr,
                       long srcId,
                       Point destAddr,
                       int pathLength,
                       ArrayList routineList,
                       int type )
    {
        this.srcAddr = srcAddr;
        this.srcId   = srcId;
        this.destAddr = destAddr;
        this.pathLength = pathLength;
        this.type = type;
        this.routineList  = new ArrayList( routineList );
        this.timeStamp = System.currentTimeMillis();
        this.data = new String();
    }
    //一个空的构造函数用来给PacketReceiver使用,避免一次性传入过多的值
    public MddbPacket(){}
    //可设定时间戳的构造函数
    public MddbPacket( Point srcAddr,
                       long srcId,
                       Point destAddr,
                       int pathLength,
                       ArrayList routineList,
                       int type,
                       long timeStamp )
    {
        this.srcAddr = srcAddr;
        this.srcId   = srcId;
        this.destAddr = destAddr;
        this.pathLength = pathLength;
        this.type = type;
        this.routineList  = new ArrayList( routineList );
        this.timeStamp = timeStamp;
        this.data = new String();
    }

    public MddbPacket(MddbPacket oldPacket)
    {
        this.srcAddr = oldPacket.getSrcAddr();
        this.srcId   = oldPacket.getSrcId();
        this.destAddr = oldPacket.getDestAddr();
        this.pathLength = oldPacket.getPathLength();
        this.type = oldPacket.getType();
        this.routineList  = new ArrayList( oldPacket.getRoutineList() );
        this.timeStamp = oldPacket.getTimeStamp();
        this.data = oldPacket.getData();
    }
    //==========================================================================
}

⌨️ 快捷键说明

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