Open denshem10 opened 2 years ago
That's quite interesting. So you poll()
each Server out during the Arrive
event and add()
that Server back once Done
?
I think most of us did it using ImList<Server>
. For me, I had some methods in Shop
to help with the assignment of Servers in Arrive
event
I think using a PriorityQueue works but a ImList would be more flexible
ImList seems to work better?
I think both method works, however, like the rest have mentioned, ImList would be more convenient. There also not really a need to create a comparator specially for the servers just for them to be placed in a PQ.
yeap ImList will work better because there's no need to have any specified order of the servers
Hi! Personally, I use ImList for the server, I think using PQ might be possible, but I believe it might create additional complication, use the simpler method instead if it works well!
Used ImList cause PQ need to create new Comparator so more troublesome
Summary
In my solution, I used a PriorityQueue to store Servers and used different Comparators to sort the Servers based on priorities. My Server has 3 main attributes, int serverID, int serveStatus and int waitStatus. I sorted the Servers based on whether they can be served, then whether they can be waited. If one server had the same serveStatus and waitStatus as another server, the serveID was used to break the tie.
Description
Comparator<Server> comparator = new ServerComparatorService().thenComparing(new ServerComparatorWait() .thenComparing(new ServerComparatorName());
Did anyone else do this? Please share!