This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Jun 24, 2013, 5:45 PM
31 Posts
topic has been resolvedResolved

descendingMap with TreeMap

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags: Java,Sorting
  • Replies: 2

I am using David Leedy's TreeMap for filtering and sorting the results of a view in repeat control. This works great but I need the values to be in descending order. Everywhere I read it is suggested to use descendingMap. I am not Java savvy enough to figure out where that goes. I have tried in the var myList... but I get errors on both sides, and also before and after the myList.put but everything is still sorted in ascending order. Can a Java savvy person please help?

var AE:String = session.getEffectiveUserName();
var collect:NotesDocumentCollection = view1.getAllDocumentsByKey(AE, true)
var dateCount:integer = 0;
var myList:java.util.TreeMap = new java.util.TreeMap(java.lang.String.CASE_INSENSITIVE_ORDER); 
var tmpCount:integer = 0; 
var tmpName:string = "";
 
var doc:NotesDocument = collect.getFirstDocument();
var tmpDoc:NotesDocument
while (doc != null) {
tmpDoc = collect.getNextDocument();
dateCount = dateCount + 1;
 
// Get the Order Date text field - repeat key
tmpName = doc.getItemValueString("OrderDateTxt")
tmpCount = myList.get(tmpName.toString())
 
myList.put(tmpName, tmpCount + 1)
 
doc.recycle(); 
doc = tmpDoc; 
}
 
viewScope.put("dateCount", dateCount);
viewScope.put("dateBreakdown", myList);
Jun 24, 2013, 5:50 PM
31 Posts
RESOLVED - simple oversight...

I just figured this out on a whim: 

viewScope.put("dateBreakdown", myList.descendingMap());
Jun 25, 2013, 1:33 PM
586 Posts
TreeMaps and sotring

Lady Sterling,

 

Glad you could use that technique!

This is were Java REALLY comes into play.  I've been doing a lot with sorting things lately.  It's really nice to have a Java Object  for a Company and also another for "Contact" at that company.  Then say I want to grab a Company object. I can at any time load into they company object all my contacts.  So they become indicidual contact objects in a TreeMap or even better just a simple ListArray.  So the company object contains an array of Contact objects.

then whenever I need I can send that Array to a repeat control and work with the specific contact objects as if they were documents really.

But here's the best part:

In Java there's this stuff called comparator and comparable.  that's for sorting.  so I can add these to my contact object.  This is the "Sorting Logic".  so then from the company object I can pull out my contacts sorted by lastname... or firstname...  or state...  or whatever really.  It's able to sort by a property.  It's really powerful I think.  

This technique will be coming to NotesIn9 soon.  It is Java...  but it's so worth it to do.

 

Dave

 

 

 


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal