queue.java

来自「Java Communicating Agents是一个用于开发网络反应式信息a」· Java 代码 · 共 109 行

JAVA
109
字号
/* * $Source: /home/data/cvsroot/src/jacomma/util/Queue.java,v $ * $Revision: 1.7 $ * $Date: 2000/10/28 20:09:08 $ * * This file is part of the jacomma framework * Copyright (c) 2000 	Dimitrios Vyzovitis *			mailto:dviz@egnatia.ee.auth.gr *			 * *			 *			 *			 * *	This library is free software; you can redistribute it and/or modify *	it under the terms of the GNU Library General Public License as published by *	the Free Software Foundation; either version 2 of the License, or *	(at your option) any later version. * *	This library is distributed in the hope that it will be useful, *	but WITHOUT ANY WARRANTY; without even the implied warranty of *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *	GNU Library General Public License for more details. * *	You should have received a copy of the GNU Library General Public License *	along with this library; if not, write to the Free Software *	Foundation, Inc., 59 Temple Place, Suite 330,  *	Boston, MA  02111-1307  USA */package jacomma.util;import java.util.List;import java.util.ArrayList;import java.util.Iterator;/** * TBA **/public class Queue {		public static final int DEFAULT_INITIAL_SIZE = 10;		protected List que_;	public Queue() {		this( DEFAULT_INITIAL_SIZE );	}		public Queue( int isz ) {		que_ = new ArrayList( isz );	}	public synchronized void put( Object obj ) {		que_.add( obj );		notifyAll();	}		public synchronized void signal() { notifyAll(); }	public synchronized Object get() throws InterruptedException {		Object obj = null;		for ( obj = try_get(); obj == null; obj = try_get() ) wait();				return obj;	}		public synchronized Object try_get() {		if ( que_.isEmpty() )			return null;		else			return que_.remove( 0 );	}		public synchronized Object get( Object test ) throws InterruptedException {		Object m = null;		for ( m = try_get( test ); m == null; m = try_get( test ) ) wait();				return m;	}	public synchronized Object try_get( Object test ) {		for( Iterator it = que_.iterator();			 it.hasNext(); ) {			Object  next = it.next();			if ( test.equals( next ) ) {				que_.remove( next );				return next;			}		}				return null;	}	public synchronized Object try_accept( Visitor v ) {		if ( !v.canVisit( List.class ) || que_.isEmpty() ) return null;		else return v.visit( que_ );	}		public synchronized Object accept( Visitor v ) throws InterruptedException {		if ( v.canVisit( List.class ) ) {			while( que_.isEmpty() ) wait();			return v.visit( que_ );		} else return null;	}}

⌨️ 快捷键说明

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