• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding Values To Array & Moving Other Values Down  RSS feed

 
Andrew Cero
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi;

I am trying to use my attached code to check the priority of the item, then depending on its priority add it to the array. The high priority items go on the top of the list followed by the medium, low and then normal. The code has to take the new item with its corresponding priority and append it to the bottom of its corresponding priority section while still moving the other items down. Another step in the code is going to have to be to remove the item from the queue.

Any suggestions would help....im pretty lost.


 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew,

It looks to me like you're making this harder than it needs to be. A few suggestions:

1. Have your class use the Comparator<T> interface. It was made for this very kind of problem.
2. Use an Enumeration for your priorities.
3. Have your compare() method sort on the priority Enumeration and the system time (for example)

You can then use a TreeSet, which will order your item objects on the fly, without a lot of messy array operations.

John.

Edit: Comparable<T> -> Comparator<T>
Edit: compareTo() -> compare()
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!