📄 actionformbeans.java
字号:
package collections;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections.FastHashMap;
/**
* Title : Base Dict Class
* Description : here Description is the function of class, here maybe multirows
* @author <a href="mailto:sunpeng@china.freeborders">kevin</a>
* @Version 1.0
*/
/**
* Class description goes here.
* @version 1.0 2005-9-22
* @author kevin
*/
public class ActionFormBeans implements Serializable
{
protected FastHashMap formBeans = new FastHashMap();
public boolean getFast()
{
return (formBeans.getFast());
}
public void setFast(boolean fast)
{
formBeans.setFast(fast);
}
public void addFormBean(ActionFormBean formBean)
{
formBeans.put(formBean.getName(), formBean);
}
public ActionFormBean findFormBean(String name)
{
return ((ActionFormBean)formBeans.get(name));
}
public String[] findFormBeans()
{
return ((String[])formBeans.keySet().toArray(new String[formBeans.size()]));
}
public void removeFormBean(ActionFormBean formBean)
{
formBeans.remove(formBean.getName());
}
public static void sortBean()
{
Country c1 = new Country("China");
Country c2 = new Country("America");
Country c3 = new Country("England");
Country c4 = new Country("Italy");
List people = new ArrayList();
People p = new People(33, "Jake", c2);
people.add(p);
p = new People(28, "Sam", c3);
people.add(p);
p = new People(25, "Sunpeng", c1);
people.add(p);
p = new People(29, "Kevin", c4);
people.add(p);
p = new People(30, "Susan", c3);
people.add(p);
BeanComparator comp = new BeanComparator("age");
Collections.sort(people, comp);
int i = 0;
System.out.println("Sort by age====");
for(i = 0; i < people.size(); i++)
{
System.out.println(" ====" + ((People)people.get(i)).getName() + " || age=" + ((People)people.get(i)).getAge());
}
comp = new BeanComparator("name");
Collections.sort(people, comp);
System.out.println("Sort by name====");
for(i = 0; i < people.size(); i++)
{
System.out.println(" ====" + ((People)people.get(i)).getName());
}
comp = new BeanComparator("country");
Collections.sort(people, comp);
System.out.println("Sort by country====");
try
{
for(i = 0; i < people.size(); i++)
{
System.out.println(" ====" + ((People)people.get(i)).getName() + " || country.name=" + PropertyUtils.getNestedProperty((People)people.get(i), "country.name"));
}
}
catch(IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(InvocationTargetException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(NoSuchMethodException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void fastMap()
{
ActionFormBean formBean;
ActionFormBeans formBeans = new ActionFormBeans();
formBeans.setFast(false);
for(int i = 0; i < 22; i++)
{
formBean = new ActionFormBean();
formBean.setName(i + "=>[Test]");
formBeans.addFormBean(formBean);
}
String[] names = formBeans.findFormBeans();
for(int j = 0; j < names.length; j++)
{
System.out.println(j + "===" + names[j]);
}
}
public static void main(String[] args)
{
sortBean();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -