📄 messagequeue.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. * 消息列队实现 * 其中元素均为byte[] */package documenteditor;import java.util.Vector;/** * * @author wangzhi */public class MessageQueue extends Vector{ private int Len = 0;//列队长度,超过则从头部删掉元素 public MessageQueue(int Len){ this.Len = Len; } //进列队,返回元素个数 public int Enqueue(byte[] buff) { super.add(buff); int count = super.size(); if(count>Len){ super.remove(0); } return super.size(); } //以字符串形式进列队,返回元素个数 public int Enqueue(String Message){ super.add(Message.getBytes()); int count = super.size(); if(count>Len){ super.remove(0); } return super.size(); } //以字符串形势出列队 public String Dequeue(){ if(this.size()>0){ byte[] RStr = (byte[])this.get(0); super.remove(0); return new String(RStr); }else{ return null; } } //出列队 public byte[] DequeueByte(){ if(this.size()>0){ byte[] RStr = (byte[])this.get(0); super.remove(0); return RStr; }else{ return null; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -