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

📄 memberlist.java

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

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

public class MemberList {
    //MemberList纪录成员的成员Id和成员的位置
    private ArrayList mbrId, mbrPos;
    private int size;

    //constractor-----------------------------------------------
    public MemberList( long myId, Point myPos ) {
        mbrId = new ArrayList();
        mbrPos = new ArrayList();
        mbrId.add( new Long( myId ) );
        mbrPos.add( new Point( myPos ) );
        size = 1;
    }

    public final int getSize()
    {
        return size;
    }

    //对于MemberList重新进行初始化
    public void reInitialize( long mstrId, Point mstrPos ) {
        synchronized(this){
            mbrId = new ArrayList();
            mbrPos = new ArrayList();
            mbrId.add( new Long( mstrId ) );
            mbrPos.add( new Point( mstrPos ) );
            size = 1;
        }
    }
    //-----------------------------------------------------------
    //添加数值,若已经包含则进行更新
    public void add( long id, Point pos ) {
        synchronized(this){
            if( !mbrId.contains( new Long( id ) ) ) {
                mbrId.add( new Long( id ) );
                mbrPos.add( new Point( pos ) );
                size++;
            }
            else {
                int index = mbrId.indexOf( new Long( id ) );
                mbrId.set( index, new Long( id ) );
                mbrPos.set( index, new Point( pos ) );
            }
        }
    }

    //删除指定位置的值---------------------------------
    public void remove( int position ) {
        synchronized(this){
            if( isValidPosition( position ) ) {
                mbrId.remove( position );
                mbrPos.remove( position );
                size--;
            }
        }
    }

    public void remove( long id ) {
        synchronized(this){
            int index = mbrId.indexOf( new Long( id ) );
            if( index != -1 ) {
                mbrId.remove( index );
                mbrPos.remove( index );
                size--;
            }
        }
    }
    //-----------------------------------------------

    private boolean isValidPosition( int pos ) {
        synchronized(this){
            if( pos >= size || pos < 0 ) {
                return false;
            }
            return true;
        }
    }

    //------------------------------------------------
    public void clear() {
        synchronized(this){
            this.mbrId.clear();
            this.mbrPos.clear();
            size = 0;
        }
    }
    //-------------------------------------------------
    public boolean contains(Long mbrId)
    {
        if( this.mbrId.contains(mbrId) )
            return true;
        return false;
    }
    //--------------------------------------------------
    public long getMbrId(int position){
        if( isValidPosition(position) )
        {
            return ((Long)this.mbrId.get(position)).longValue();
        }
        return -1;
    }

}

⌨️ 快捷键说明

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