Connecting Tech Pros Worldwide Forums | Help | Site Map

Order by on the basis of n columns.

dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#1: Aug 29 '09
Suppose i have a List<Map<String,Object>>.
Map represents each row, with column key and column_value value.
Now i want to sort the list on basis of n columns.
Suppose columns are like this .. col1,col2....coln.
Now i want to sort like this.... order by col3 desc, col2 asc.
What do you think, should i sort the values at multiple phases? like, first sort the col3 as descending order then sort the col2 as ascending order...Or,i should do like this ..like calculate a comparing value using the hash codes of the values?
What should be mathematics logic? Could you help me?

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Aug 29 '09

re: Order by on the basis of n columns.


Quote:

Originally Posted by dmjpro View Post

What should be mathematics logic? Could you help me?

There is no mathematics nor logic involved; whatever you're going to do with those maps it's going to be a mess. They have invented databases for that juggling; use them.

kind regards,

Jos
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#3: Aug 31 '09

re: Order by on the basis of n columns.


Actually our case is something else. So i need to do using Java.
Suppose n1,n2 in one row. 2nd row contains n1,n3.
Now n1,n2 can't generate a number which is greater than number generated by n1,n3 in same way (provided n2>n3)?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#4: Aug 31 '09

re: Order by on the basis of n columns.


Quote:

Originally Posted by dmjpro View Post

Actually our case is something else. So i need to do using Java.
Suppose n1,n2 in one row. 2nd row contains n1,n3.
Now n1,n2 can't generate a number which is greater than number generated by n1,n3 in same way (provided n2>n3)?

Generates a number? What for? You need to write quite a messy Comparator and not hack your way through it by trying to assign magic constant values to every row. Why can't you use a database for this mess?

kind regards,

Jos
Reply