📄 neighbourlist.java
字号:
package mddb.client.components;
import java.util.*;
import java.awt.Point;
public class NeighbourList {
private ArrayList nebrId,nebrPosition,nebrMasterId;
private int size;
public NeighbourList() {
this.nebrId = new ArrayList();
this.nebrMasterId = new ArrayList();
this.nebrPosition = new ArrayList();
size = 0;
}
public final int getSize(){
return size;
}
//对于不存在的直接加入,对于已存在的进行替换
public void add(long nebrId,long nebrMasterId,Point nebrPos){
synchronized(this){
if( this.nebrId.contains( new Long( nebrId ) ) ) {
int index = this.nebrId.indexOf( new Long( nebrId ) );
this.nebrId.set( index, new Long( nebrId ) );
this.nebrMasterId.set( index, new Long( nebrMasterId ) );
this.nebrPosition.set( index, new Point( nebrPos ) );
}
else {
this.nebrId.add( new Long( nebrId ) );
this.nebrMasterId.add( new Long( nebrMasterId ) );
this.nebrPosition.add( new Point( nebrPos ) );
size++;
}
}
}
//-------------------------------------------------------------------
public void update(long nebrId,long nebrMasterId,Point nebrPos){
synchronized(this){
if( this.nebrId.contains( new Long( nebrId ) ) ) {
int index = this.nebrId.indexOf( new Long( nebrId ) );
this.nebrId.set( index, new Long( nebrId ) );
this.nebrMasterId.set( index, new Long( nebrMasterId ) );
this.nebrPosition.set( index, new Point( nebrPos ) );
}
}
}
public void update(Long nebrId,Long nebrMasterId,Point nebrPos){
synchronized(this){
if( this.nebrId.contains( nebrId) ) {
int index = this.nebrId.indexOf( nebrId );
this.nebrId.set( index, nebrId );
this.nebrMasterId.set( index, nebrMasterId );
this.nebrPosition.set( index, new Point( nebrPos ) );
}
}
}
//--------------------------------------------------------------------
public void clear(){
synchronized(this){
this.nebrId.clear();
this.nebrMasterId.clear();
this.nebrPosition.clear();
size = 0;
}
}
private boolean isValidPosition( int pos ) {
synchronized(this){
if( pos >= size || pos < 0 ) {
return false;
}
return true;
}
}
//删除指定位置的值---------------------------------
public void remove( int position ) {
synchronized(this){
if( isValidPosition( position ) ) {
this.nebrId.remove( position );
this.nebrMasterId.remove( position );
this.nebrPosition.remove( position );
size--;
}
}
}
public void remove( long id ) {
synchronized(this){
int index = nebrId.indexOf( new Long( id ) );
if( index != -1 ) {
this.nebrId.remove( index );
this.nebrMasterId.remove( index );
this.nebrPosition.remove( index );
size--;
}
}
}
//-----------------------------------------------
//返回对应位置的值:nebrId,nebrMasterId,nebrX,nebrY
public Object[] get(int position){
synchronized(this){
if( isValidPosition( position ) ) {
Object[] value = new Object[3];
value[0] = ( Object )this.nebrId.get( position );
value[1] = this.nebrMasterId.get( position );
value[2] = ( Point )this.nebrPosition.get( position );
return value;
}
return null;
}
}
//得到指定位置的NebrId值
public long getNebrId(int position){
synchronized(this){
if( isValidPosition( position ) ) {
return( ( Long )nebrId.get( position ) ).longValue();
}
return -1;
}
}
//获得指定位置的NeighbourMasterId
public long getNebrMasterId(int position){
synchronized(this){
if( isValidPosition( position ) ) {
return( ( Long )nebrMasterId.get( position ) ).longValue();
}
return -1;
}
}
//获得邻居的位置
public Point getNebrPosition(int position){
synchronized(this){
if( isValidPosition( position ) ) {
return( Point )nebrPosition.get( position );
}
return null;
}
}
//-------------------------------------------------------
public boolean contains(Long nebrId){
if( this.nebrId.contains(nebrId) )
return true;
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -