Results 1 to 3 of 3
- 02-18-2010, 04:58 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
Nested List class for Simulation Queue
Hello, all. This is my first post to the forums, and I hope someone out there can help me! For a client, I am developing a (fairly) sophisticated discrete-event simulation written entirely in Java. For anyone familiar with simulations, before an entity can be serviced, it must enter a queue. In version 0.1 of the simulation there was only one queue, a Queue1 class, with a nested List class inside of it, which just initiated an empty list. The Queue1 class added or removed entities from the queue. The List class looked as follows:
Now, I need another queue. We can call it Queue2, for kicks. If I try to add another class List {} inside Queue2, it says List has already been defined.Java Code:class List { // Global variables for List public Commodity work; public List next; public List() { work = null; next = null; } }
So, I tried creating a generic Queue class with the list nested, and had my Queue classes, Queue1 and Queue2, extend Queue. However, both queues are still feeding off of the same List. How do I create new lists in each individual queue class so that I can maintain different lists simultaneously? If you would like the code for one of the Queue classes, I'd be glad to post that, as well. Thanks!
- 02-18-2010, 09:53 PM #2
Why aren't you just using a LinkedList?
Edit:Java Code:LinkedList<Commodity> queue1 = new LinkedList<Commodity>(); LinkedList<Commodity> queue2 = new LinkedList<Commodity>();
If threads are involved: ConcurrentLinkedQueueLast edited by mrmatt1111; 02-18-2010 at 09:55 PM.
My Hobby Project: LegacyClone
- 02-19-2010, 01:19 AM #3
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
Well that's definitely an implementation I can look into, but the List is currently called if a double length == 0, thus creating a new list. For some reason, the second process is reading off the same length value as the first process, and thus never evaluates to true, and passes right by it. However, length is a private variable in both classes. The enqueue method looks as follows:
There is also a dequeue method which should decrement the length variable.Java Code:public void enqueue(Commodity commodityToAdd) { if(commodityToAdd == null) return; List ptr = head; if(isEmpty()) { head = new List(); ptr = head; } else { while(ptr.next != null) ptr = ptr.next; ptr.next = new List(); ptr = ptr.next; } ptr.next = null; ptr.work = commodityToAdd; length++; }
Similar Threads
-
beehive simulation
By BlueF4re in forum New To JavaReplies: 2Last Post: 12-02-2009, 08:31 AM -
nested collapsing list
By roohja in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 01-05-2009, 07:15 AM -
Queue List
By nahid in forum Advanced JavaReplies: 4Last Post: 10-08-2008, 08:50 AM -
Mars Simulation Project 2.84
By Java Tip in forum Java SoftwareReplies: 0Last Post: 06-26-2008, 06:18 PM -
Pulley Simulation..HELP
By dazza-s in forum Java 2DReplies: 2Last Post: 06-18-2008, 10:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks