📄 queue.java
字号:
/***********************************************************************
* Module: Queue.java
* Author: jzx
* Purpose: Defines the Class Queue
***********************************************************************/
package com.zcsoft.comm;
import java.util.*;
/** <p>Title: 串口通信</p>
* <p>Description: 队列 </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Zhicheng Software&Service Co. Ltd.</p>
*
* @author 蒋智湘
* @version 1.0 */
public class Queue
{
/** 队列中的项 */
private Vector entries;
/** 终止其它线程从队列中取出项 */
private boolean stop;
public Queue()
{
entries = new Vector();
}
/** @param entry */
public synchronized void put(Object entry)
{
entries.addElement(entry);
notify();
}
public synchronized void stop()
{
stop = true;
notify();
}
public synchronized Object pull()
{
while(isEmpty() && !stop)
{
try
{
wait();
}
catch (InterruptedException ex){}
if(stop == true)
{
return null;
}
}
return get();
}
public synchronized Object get()
{
Object object = peek();
if(object != null)
{
entries.removeElementAt(0);
}
return object;
}
public Object peek()
{
return isEmpty()?null:entries.elementAt(0);
}
public boolean isEmpty()
{
return entries.isEmpty();
}
public int size()
{
return entries.size();
}
/**
* 判断队列中是否存在同指定对象相等的成员
* @param entry
* @return 如果存在,则返回true,否则返回false
*/
public boolean exists(Object entry)
{
return this.entries.indexOf(entry) != -1;
}
/** 枚举队列中的所有成员 */
public Enumeration elements()
{
return entries.elements();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -