美文网首页
jfinal-undertow-1.6源码解析(一) Comp

jfinal-undertow-1.6源码解析(一) Comp

作者: 大白乐了 | 来源:发表于2019-06-05 14:54 被阅读0次
/**
 * CompositeResourceManager
 */
public class CompositeResourceManager implements ResourceManager {
    
    protected ResourceManager[] resourceManagers = new ResourceManager[0];

    public void add(ResourceManager resourceManager) {
        List<ResourceManager> list = new ArrayList<ResourceManager>();
        for (ResourceManager rm : resourceManagers) {
            list.add(rm);
        }
        list.add(resourceManager);
        
        this.resourceManagers = list.toArray(new ResourceManager[list.size()]);
    }
}

1.先初始化1个数组

ResourceManger[] resourceManagers = new ResourceManager[0];

2.新建集合

List<ResourceManager> list = new ArrayList<>();

3.遍历数组,添加到集合

for(ResourceManager rm : resourceManagers){
  list.add(rm);
}

4.将新增加的值,添加进集合

list.add(resourceManager);

5.根据集合,重新创建数组

this.resourceManagers = list.toArray(new ResourceManager[list.size()]);

6.总结:利用的集合的灵活性;数组的有序,查询性能高;数组初始化耗费最小资源。

相关文章

网友评论

      本文标题:jfinal-undertow-1.6源码解析(一) Comp

      本文链接:https://www.haomeiwen.com/subject/pgtsxctx.html