on 2007 Dec 21 7:33 AM
HI all, I am trying to sort the table using comparator. Below is the code used for sorting. However the last document is not sorted in the proper order.The Output is also given for reference. Can Anyone help me in this.
wdContext.nodeKMAccess().sortElements(
new Comparator()
{
public int compare(Object x, Object y)
{
int iX,iY;
IPrivateDownloadKMHitsReportView.IKMAccessElement rx = (IPrivateDownloadKMHitsReportView.IKMAccessElement)x;
IPrivateDownloadKMHitsReportView.IKMAccessElement ry = (IPrivateDownloadKMHitsReportView.IKMAccessElement)y;
iX = Integer.parseInt(rx.getHits());
iY = Integer.parseInt(ry.getHits());
while(rx.getHits()!=null && ry.getHits()!=null)
{
rx.getHits().compareTo(ry.getHits());
}
return iY-iX;
but output is coming as
11
10
8
6
4
3
1
2
Regards,
Kamini
Hi,
Try the below Code
wdContext.nodeKMAccess().sortElements(
new Comparator()
{
public int compare(Object x, Object y)
{
int iX,iY;
IPrivateDownloadKMHitsReportView.IKMAccessElement rx = (IPrivateDownloadKMHitsReportView.IKMAccessElement)x;
IPrivateDownloadKMHitsReportView.IKMAccessElement ry = (IPrivateDownloadKMHitsReportView.IKMAccessElement)y;
iX = Integer.parseInt(rx.getHits());
iY = Integer.parseInt(ry.getHits());
if(iX<iY)
return -1;
else if(iX>1Y)
return 1;
else
return 0;
Regards,
Naga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
62 | |
12 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.