in velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/CollectionTool.java [522:569]
public PropertiesComparator(List props)
{
// copy the list so we can safely drop :asc and :desc suffixes
this.properties = new ArrayList(props.size());
this.properties.addAll(props);
// determine ascending/descending
sortTypes = new int[properties.size()];
for (int i = 0; i < properties.size(); i++)
{
if (properties.get(i) == null)
{
throw new IllegalArgumentException("Property " + i
+ "is null, sort properties may not be null.");
}
// determine if the property contains a sort type
// e.g "Name:asc" means sort by property Name ascending
String prop = properties.get(i).toString();
int colonIndex = prop.indexOf(':');
if (colonIndex != -1)
{
String sortType = prop.substring(colonIndex + 1);
properties.set(i, prop.substring(0, colonIndex));
if (TYPE_ASCENDING_SHORT.equalsIgnoreCase(sortType))
{
sortTypes[i] = TYPE_ASCENDING;
}
else if (TYPE_DESCENDING_SHORT.equalsIgnoreCase(sortType))
{
sortTypes[i] = TYPE_DESCENDING;
}
else
{
//FIXME: log this
// invalid property sort type. use default instead.
sortTypes[i] = TYPE_ASCENDING;
}
}
else
{
// default sort type is ascending.
sortTypes[i] = TYPE_ASCENDING;
}
}
}