cancel
Showing results for 
Search instead for 
Did you mean: 

Any way to sort elements in a ResultSet

Former Member
0 Kudos

Is there any way to sort the elements in a ResultSet? I have code that accesses the UME users and displays their name and email in an EVS search help. I'd like to sort the list by name if possible. In case it is helpful here is the code I am using in the WDDoInit method of the view:

IUserFactory ufact = UMFactory.getUserFactory();

IUserSearchFilter isf;

try {

isf = ufact.getUserSearchFilter();

isf.setUniqueName("*", ISearchAttribute.LIKE_OPERATOR,false);

isf.setCity("Tewksbury", ISearchAttribute.EQUALS_OPERATOR,false);

ISearchResult sr = ufact.searchUsers(isf);

String strtest = "";

String strnamen = "";

String stremail = "";

String attributeName =

IPrivateGenReceiptsMainView.IReceiptElement.ADDRESSED_TO;

IWDAttributeInfo attributeInfo =

wdThis.wdGetContext().nodeReceipt().getNodeInfo().getAttribute(attributeName);

ISimpleTypeModifiable AddressedType = attributeInfo.getModifiableSimpleType();

AddressedType.setFieldLabel("AddressedTo");

IModifiableSimpleValueSet valueSet =

AddressedType.getSVServices().getModifiableSimpleValueSet();

while (sr.hasNext()) {

strtest = sr.next().toString();

IUser user = UMFactory.getUserFactory().getUser(strtest);

strnamen = user.getDisplayName();

stremail = user.getEmail();

valueSet.put(user.getDisplayName(),stremail);

}

} catch (UMException e) {

e.printStackTrace();

}

Accepted Solutions (1)

Accepted Solutions (1)

former_member182294
Active Contributor
0 Kudos

Hi Dana,

The simplest way is by using the <b>sort </b> function in IModifiableSimpleValueSet.

After the while loop: <b>valueSet.sort(false,true,true);</b>

The first paramter is <b>sortKey</b> - if true, it sorts according to the order of the keys contained in this SimpleValueSet, otherwise it sorts according to the order of the texts for the current internal default locale.

The second paramter is <b>up</b> - if true, it sorts into ascending order, otherwise into descending order.

The third paramter is <b>ignoreCase</b> - if true, ignore the capitalization of letters.

Regards

Abhilash

Answers (2)

Answers (2)

lajitha_menon
Contributor
0 Kudos

Hi Dana,

Try this out ..

After you have put your elements into the valueSet, do the following(You can put this code at the end).

Vector v = new Vector(valueSet.keySet());

Collections.sort(v);

See if it works,

Cheers,

LM

Former Member
0 Kudos