Sorting a string list
Jan 02, 2021 13:07 0 Comments Other components GANESH MALLA

 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 list = Arrays.asList(sortedList);
          
            Collections.sort(list, Collections.reverseOrder() );
          
        }
      
        IDataUtil.put( pipelineCursor_1, "sortedList", sortedList );
        pipelineCursor_1.destroy();
          
    }

Prev Next
About the Author
Topic Replies (0)
Leave a Reply
Guest User

You might also like

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect