contextlist.java
来自「用JAVA实现排序等简单算法的演示」· Java 代码 · 共 69 行
JAVA
69 行
package contextsPoolManager;
import java.util.ArrayList;
/**
* 存放上下文列表信息的类
* @author carlven
* @since 2007/10/15
* @version 1.0
*
*/
public class ContextList {
private ArrayList<Context> contexts = null; // 存放真正的上下文信息
public ContextList() {
contexts = new ArrayList<Context>(10);
}
/**
* 加入上下文
*/
public void addContext(Context context) {
contexts.add(context);
}
/**
* 删除上下文
*/
public void removeContext(Context context) {
contexts.remove(context);
}
/**
* 返回列表中上下文个数
*/
public int getContextSize() {
return contexts.size();
}
/**
* 返回下标为 index 的上下文,用于遍历列表中的所有上下文
*/
public Context getContext(int index) {
return contexts.get(index);
}
/**
* 清除所有上下文
*/
public void clear() {
contexts.clear();
}
/**
* 转换成字符串以方便测试或调试时输出
*/
public String toString() {
StringBuffer result = new StringBuffer();
for (int index = 0; index < contexts.size(); index++) {
Context context = contexts.get(index);
result.append(context);
}
return result.toString();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?