📄 objectpropertyspool.java
字号:
package com.eshaper.appbuilder.objectbase.property;
import java.io.*;
import java.util.*;
public class ObjectPropertysPool
{
static private ObjectPropertysPool instance; // 唯一实例
/**
* 返回唯一实例.如果是第一次调用此方法,则创建实例
*
* @return DBConnectionManager 唯一实例
*/
static synchronized public ObjectPropertysPool getInstance()
{
if (instance == null) instance = new ObjectPropertysPool();
return instance;
}
/**
* 建构函数私有以防止其它对象创建本类实例
*/
private ObjectPropertysPool()
{
}
public int getCount()
{
return pool.size();
}
public ObjectPropertys get(String name) throws Exception
{
ObjectPropertys propertys = null;
for(int index=0;index<pool.size();index++)
{
try
{
propertys = (ObjectPropertys)pool.get(index);
if(propertys.getObjectName().equalsIgnoreCase(name))
return propertys;
}
catch (Exception e)
{
pool.remove(index);
continue;
}
}
propertys = add(name);
return propertys;
}
public ObjectPropertys get(int index)
{
if(index<0 || index>=pool.size()) return null;
try
{
return (ObjectPropertys)pool.get(index);
}
catch (Exception e)
{
pool.remove(index);
}
return null;
}
private ObjectPropertys add(String name) throws Exception
{
String filepath = "D:\\work\\test\\file\\"+name+".tdf";
ObjectPropertys propertys = new ObjectPropertys();
propertys.setObjectName(name);
propertys.loadFromFile(filepath);
pool.add(propertys);
return propertys;
}
private ArrayList pool = new ArrayList();
public static void main(String args[]) throws Exception
{
System.out.println("Test-------");
ObjectPropertysPool pool = new ObjectPropertysPool();
System.out.println("First count = " + pool.getCount());
ObjectPropertys fields = pool.get("Users");
System.out.println("Last count = " + pool.getCount());
System.out.println("fields's field count = " + fields.getCount());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -