arrayrecycler.java

来自「专业汽车级嵌入式操作系统OSEK的源代码」· Java 代码 · 共 48 行

JAVA
48
字号
package lejos.util;/** * An array recycler for Object arrays. To use this utility, create * a global instance of this class, and then invoke * <code>allocate(int)</code> to create recyclable arrays. * As usual, invoke <code>recycle(...)</code> to release the array.  * <p> * Note that the caller is expected to provide * thread safety for instances of this class. *  * @see lejos.util.RecyclableArray */public final class ArrayRecycler extends Recycler {	private int requestedLength;	    /**     * Constructs a recycler.     */    public ArrayRecycler() {    }        /**     * Attempts to obtain a free RecyclableArray.     * @return A RecyclableArray reference.     * @throws java.lang.StackOverflowError May be thrown due to the recursive implementation of the method.     */    public final RecyclableArray allocate (int length) {		RecyclableArray array1;		this.requestedLength = length;        array1 = (RecyclableArray) allocate();		if (array1.getCapacity() >= length) {			array1.init (length);			return array1;		}		try {		   return allocate (length);		} finally {		   // Must not recycle before calling allocate (length).		   recycle (array1);		}	}	    	protected final Recyclable createInstance() {		return new RecyclableArray (this.requestedLength);	}}

⌨️ 快捷键说明

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