Sorts a NotesDocumentCollection by DateTime item in reversed order - latest at top


// Sorts a NotesDocumentCollection by date time item in reversed order, (if you want the last created docs at top)

// @param col, unsorted NotesDocumentCollection
// @param iDateTimeName, the date time name of the item to sort the collection by.
// @return sorted NotesDocumentCollection based on date time in descending order
// @author Thomas Adrian
// @version 1.0
function sortColByItemNameReversed(col:NotesDocumentCollection, iDateTimeName:String) {
  var rl:java.util.Vector = new java.util.Vector();
  var doc:NotesDocument = col.getFirstDocument();
  var tm:java.util.TreeMap = new java.util.TreeMap();
  while (doc != null) {
      tm.put(doc.getFirstItem(iDateTimeName).getDateTimeValue().toString(), doc);                   
      doc = col.getNextDocument(doc);
  }
  var tmReversed:java.util.TreeMap = new java.util.TreeMap(java.util.Collections.reverseOrder());
  tmReversed.putAll(tm);

  var tCol:java.util.Collection = tmReversed.values();
  var tIt:java.util.Iterator  = tCol.iterator();
  while (tIt.hasNext()) {
      rl.add(tIt.next());
  }
 
  return rl;  
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...