AnsweredAssumed Answered

Sorting numbers

Question asked by robin.zhang344808 on Sep 24, 2018
Latest reply on Sep 25, 2018 by robin.zhang344808
Hi, everyone
I found the following code for sorting number from forum and it works fine with small number. However it did not work for large number in my case. For example,
1) 
Input:      Output is the same as input!  
99999
99998
99996
99997
99995
99994
99993
2) if I want to sort in reverse order (i.e. from largest to smallest), where do I need to make change in code?
Thanks 
import java.util.ArrayList;
 
// Name of Dynamic Document Property that contains the sorting values.
// !! THIS IS SET IN THE SET PROPERTIES SHAPE JUST BEFORE THIS DATA PROCESS SHAPE
sortByValuePropName = "ID";
// Init temp collections
SortedMap sortedMap = new TreeMap();

// Loop through documents and store the sort-by-values and document indices in the sortedMap.
for ( int i = 0; i < dataContext.getDataCount(); i++ ) {
  Properties props = dataContext.getProperties(i);
  String sortByValue = props.getProperty("document.dynamic.userdefined." + sortByValuePropName) + "_" + i;
  sortedMap.put(sortByValue, new Integer(i));
}
// Retrieve the sorted values.
Collection sortedValues = sortedMap.values();
// Loop through sorted results to output documents for the next process shape
Iterator iterator = sortedValues.iterator();
 
while (iterator.hasNext()) {
  int i = ((Integer)iterator.next()).intValue();
  dataContext.storeStream(dataContext.getStream(i), dataContext.getProperties(i));
}

Outcomes