用于串口通讯测试的工具软件。完全使用java语言编写。
源代码在线查看: queue.java
/***********************************************************************
* Module: Queue.java
* Author: jzx
* Purpose: Defines the Class Queue
***********************************************************************/
package com.zcsoft.comm;
import java.util.*;
/** Title: 串口通信
* Description: 队列
* Copyright: Copyright (c) 2002
* Company: Zhicheng Software&Service Co. Ltd.
*
* @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();
}
}