📄 objectlist.java
字号:
/*
* Created on 17-Jul-2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.jfree.util;
/**
* A list of objects that can grow as required.
*
* @author David Gilbert
*/
public class ObjectList {
/** The default initial capacity of the list. */
public static final int DEFAULT_INITIAL_CAPACITY = 8;
/** Storage for the objects. */
private Object[] objects;
/**
* Default constructor.
*/
public ObjectList() {
this(DEFAULT_INITIAL_CAPACITY);
}
/**
* Creates a new list.
*
* @param initialCapacity the initial capacity.
*/
public ObjectList(int initialCapacity) {
this.objects = new Object[initialCapacity];
}
/**
* Returns the object at the specified index, if there is one, or <code>null</code>.
*
* @param index the object index.
*
* @return The object or <code>null</code>.
*/
public Object get(int index) {
Object result = null;
if (index >= 0 && index < this.objects.length) {
result = this.objects[index];
}
return result;
}
/**
* Sets an object reference (overwriting any existing object).
*
* @param index the object index.
* @param object the object (<code>null</code> permitted).
*/
public void set(int index, Object object) {
if (index < 0) {
throw new IllegalArgumentException("ObjectList.set(...): index must be >= 0.");
}
if (index >= this.objects.length) {
Object enlarged = new Object[index];
System.arraycopy(this.objects, 0, enlarged, 0, this.objects.length);
}
this.objects[index] = object;
}
/**
* Clears the list.
*/
public void clear() {
this.objects = new Object[DEFAULT_INITIAL_CAPACITY];
}
/**
* Returns the size of the list.
*
* @return The size of the list.
*/
public int size() {
return this.objects.length;
}
/**
* Returns the index of the specified object, or -1 if the object is not in the list.
*
* @param object the object.
*
* @return The index or -1.
*/
public int indexOf(Object object) {
int result = -1;
int index = 0;
boolean done = false;
while (!done) {
if (index >= this.objects.length) {
done = true;
}
else if (this.objects[index] == object) {
result = index;
done = true;
}
else {
index = index + 1;
}
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -