Friday, March 25, 2011

Sorting a string list

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();
          
    }