My goodness. You would think this would be easy. Searched WmPublic and PSUtilities and found nothing. Googled and didn't find much either. So I created a java service sortStringList of my own.
Inputs:
inList - StringList
ascending - boolean
Outputs:
sortedList - StringList
public static final void sortStringList(IData pipeline) throws ServiceException {
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String[] inList = IDataUtil.getStringArray( pipelineCursor, "inList" );
String ascending = IDataUtil.getString( pipelineCursor, "ascending" );
pipelineCursor.destroy();
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
String[] sortedList = inList.clone();
if (ascending.equalsIgnoreCase("true")) {
Arrays.sort(sortedList);
} else {
List<String> list = Arrays.asList(sortedList);
Collections.sort(list, Collections.reverseOrder() );
}
IDataUtil.put( pipelineCursor_1, "sortedList", sortedList );
pipelineCursor_1.destroy();
}
IS8 and PsUtilities have sort services for document lists. You can convert your string list (just by mapping)into a document list and sort it.
ReplyDeletehow to convert a document list into a string list
DeleteHi Kelvin,
ReplyDeleteThis would be more straight forward right:-
http://wiki.customware.net/repository/display/WMFAQ/How+do+I+sort+a+Document+List
Regards,
Pua
Hi Kevin,
ReplyDeleteJust another elegant approach for this.
Instead of:
Collections.sort(list);
Collections.reverse(list);
try
Collections.sort(list, new Comparator() {
@Override
public int compare(String arg0, String arg1) {
return arg1.compareTo(arg0);
}
});
... or even better:
ReplyDeleteCollections.sort( list, Collections.reverseOrder() );
Great Job - thanks!
ReplyDelete