File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Sorting objects by type, is that okay? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Sorting objects by type, is that okay?" Watch "Sorting objects by type, is that okay?" New topic
Author

Sorting objects by type, is that okay?

Mathew Mintalm
Ranch Hand

Joined: Feb 21, 2010
Posts: 103

Hello, I have android java game, where I have to deal with many different types of objects and their coordinates (player needs to place object in destination X/Y) But to make it less annoying for player I wanted to let him place object in any possible position (if there is more than one object of same type) I made this logic test code to sort objects by type, and than "send" all possible coordinates to each object:




My question is, I am not sure if its done right, and maybe there is anything I can do it better? Thank you.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7492
    
  18

Mathew Mintalm wrote:My question is, I am not sure if its done right, and maybe there is anything I can do it better? Thank you.

Well, the main thing that leaps out at me is that you don't have a Coordinate class. If you did, you could make it Comparable, which would allow you to sort them - and so by extension any object that includes them - with Collections.sort().

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Sorting objects by type, is that okay?
 
Similar Threads
When does Class Cast Exception occur?
Constructor question.
Constructor doubt
Memory Leak?
Applet(with images) running problem at Client