Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting the countries in Alphabetical Order

 
sai jyothi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers

I am trying to sort the countries names in alphabetical order.With the code below sorting is happening but there is an issue with performance.whenever the user selects a country there is a while loop which gets executed again n again.Can we minimise this part of code ?




Thanks
Jyothi
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sai jyothi wrote:... there is a while loop which gets executed again n again.

Where?
 
Nitin Surana
Ranch Hand
Posts: 129
Java Netbeans IDE Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally would have used the TreeMap instead, no overhead of sorting.
 
sai jyothi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is another method where the control goes to where while loop gets execute



So the control goes to this while loop.
 
sinchan banerje
Greenhorn
Posts: 7
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

From the code that you have written it is clear you need to add values to a Map if the keyLength is equal to AccountOpeningConstants.TWO_CHAR_LEN and return a sorted Map of the key value pairs.

I dont think there is a problem with your sortByComparator() method bcause it is outside the while loop . However, the code of while seems an overhead.

the code could be:
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a trying to clear a doubt...

Are you perhaps saying that you have a drop down or similar in your user interface and when a user traverses
the list of countries, for each country, these methods get called?
 
sai jyothi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes please.It is a combo box where countries are sorted according to alphabetical order.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok lets say you have 5 countries and these countries are loaded in to the combo box.

Now when a user tries to select a country, say the one at the bottom these methods get called 5 times?

if this is the case then your user interface may be firing these methods in a way you did not expect and you may need to look at that level.

I've come across some similar issues in the past and just thought to check and if it is
not then ignore this line of thinking.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitin Surana wrote:I personally would have used the TreeMap instead, no overhead of sorting.

Do you mean no visible overhead in calling a sort() method? This is correct.
But a TreeMap keeps things in sorted order. That requires overhead.
 
sai jyothi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry guys for not giving response.Was stuck with some other issues in project.Yes it is the user interface that is firing these methods.Please let me know your apporach

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic