on 12-19-2007 2:56 PM
Hi,
I wrote the piece of code to sort a webdynpro Table.
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());
rx.getHits().compareTo(ry.getHits());
return (iY-iX);
} }
);
But it sorts like
11
10
8
6
3
1
2
It sorts correctly, except for 2 values. Instead of 2 ,1... It gives 1,2. Where is the problem? how can i solve this isuue? Can anyone please help me in fixing this error?
Regards,
Divya
Hi,
try to change the comparator as follows
public int compare ( Object obj1, Object obj2 )
{
int i1 = ( ( Integer ) obj1 ) .intValue ( ) ;
int i2 = ( ( Integer ) obj2 ) .intValue ( ) ;
return Math.abs ( i1 ) - Math.abs ( i2 ) ;
}
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
There is no difference in the output. I think it is not comparing the entire list. before that it is printing the list. How can i rectify the error?
My table node is "KMAccess". It has columns like
DocumentName , Path, Hits. All columns are of type String.
I want to sort the table based on the column Hits. Can anyone please provide solution on this?
Regards
Divya
Hi ,
i have one question wht is ur key and values
suppose ur having emp details like
Emp Id , Emp Salary
u take Hashtable
it will sort according to highest Emp id value
later u can reverse using listiterator
bye
venkat p
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.