final class DataSources {
private int size;
private DataSource[] data = new DataSource[4];
final int size(){
return size;
}
final DataSource get(int idx){
if (idx >= size)
throw new IndexOutOfBoundsException("Index: "+idx+", Size: "+size);
return data[idx];
}
final void add(DataSource table){
if(size >= data.length ){
DataSource[] dataNew = new DataSource[size << 1];
System.arraycopy(data, 0, dataNew, 0, size);
data = dataNew;
}
data[size++] = table;
}
}
private int size;
private DataSource[] data = new DataSource[4];
final int size(){
return size;
}
final DataSource get(int idx){
if (idx >= size)
throw new IndexOutOfBoundsException("Index: "+idx+", Size: "+size);
return data[idx];
}
final void add(DataSource table){
if(size >= data.length ){
DataSource[] dataNew = new DataSource[size << 1];
System.arraycopy(data, 0, dataNew, 0, size);
data = dataNew;
}
data[size++] = table;
}
}

本文介绍了一个用于管理多个数据源的类DataSources。该类能够动态调整内部数组大小以容纳更多的数据源,并提供方法来获取和添加数据源。当添加的数据源数量超过当前数组容量时,数组会自动扩容。
686

被折叠的 条评论
为什么被折叠?



