Update of /cvsroot/ejtools/libraries/common/src/main/net/sourceforge/ejtools/beans
In directory usw-pr-cvs1:/tmp/cvs-serv20349
Added Files:
Sort.java
Log Message:
Initial Import
--- NEW FILE: Sort.java ---
package net.sourceforge.ejtools.beans;
import java.io.*;
import java.net.*;
import java.util.*;
/**
* Description of the Class
*
* @author laurent
* @created 24 décembre 2001
*/
public abstract class Sort
{
/**
* Gets the childrenByClass attribute of the Sort class
*
* @param enum Description of Parameter
* @param c Description of Parameter
* @return The childrenByClass value
*/
public static Iterator getChildrenByClass(Iterator enum, Class c)
{
Object obj;
Vector v = new Vector();
while (enum.hasNext())
{
if (c.isAssignableFrom((obj = enum.next()).getClass()))
{
v.addElement(obj);
}
}
return v.iterator();
}
/**
* Description of the Method
*
* @param enum Description of Parameter
* @return Description of the Returned Value
*/
public static Iterator sortByClass(Iterator enum)
{
Vector v = new Vector();
while (enum.hasNext())
{
v.addElement(enum.next());
}
Collections.sort(v,
new Comparator()
{
public int compare(Object o1, Object o2)
{
return o1.getClass().getName().compareTo(o2.getClass().getName());
}
public boolean equals(Object obj)
{
return true;
// Ever called?
}
});
return v.iterator();
}
/**
* Description of the Method
*
* @param enum Description of Parameter
* @return Description of the Returned Value
*/
public static Iterator sortByClassAndName(Iterator enum)
{
Vector v = new Vector();
while (enum.hasNext())
{
v.addElement(enum.next());
}
Collections.sort(v,
new Comparator()
{
public int compare(Object o1, Object o2)
{
int ret = o1.getClass().getName().compareTo(o2.getClass().getName());
if (ret == 0)
{
ret = o1.toString().compareTo(o2.toString());
}
return ret;
}
public boolean equals(Object obj)
{
return true;
// Ever called?
}
});
return v.iterator();
}
/**
* Description of the Method
*
* @param enum Description of Parameter
* @return Description of the Returned Value
*/
public static Iterator sortByName(Iterator enum)
{
Vector v = new Vector();
while (enum.hasNext())
{
v.addElement(enum.next());
}
Collections.sort(v,
new Comparator()
{
public int compare(Object o1, Object o2)
{
return o1.toString().compareTo(o2.toString());
}
public boolean equals(Object obj)
{
return true;
// Ever called?
}
});
return v.iterator();
}
}
|