| |||||||||||
Using Stringtokenizer to add to DoubleLinkedList Posted by dawn (dawn), 18 September 2002 Hello Everyone!I'm a new Java student, grasping things like stringtokenizer (a type of parser, i believe), PrintWriter/reader, BufferedReader/writer and FileWriter/Reader and Double Linked Lists (which i have created and it works). I'm currently working on a program that involves creating a parser class that contains a list of commands to initialise my double linked list with, add to the list, remove the last command from the list, trace the list(which all invlove my linked list), save the list(which would involve bufferedReader and FileReader), clear the list and finally catch exceptions (such as an invalid command). I know what to do - it's HOW to go about doing it that's bothering me! Can anyone give me some helpful tips or source code that involves parsing (using stringtokenizer) in a command from a class (creating an instance of it), adding it to my DoubleLinkList and doing all the other things mentioned above?! If you are willing, you can send helpful hints to my address - nugget_84@hotmail.com. Any help is much appreciated! Anticipating anyone's reply... Ooops - one thing i forgot to mention is that the command come from a number of subclasses (i.e - a class for forward, a class for backward) which i must add to the doublelinkedlist using stringtokeniser. Posted by admin (Graham Ellis), 18 September 2002 Hi, Dawn, and welcome. Good question - needs more than the five minutes that I have now, so I'll come back to you this evening (it's lunchtime now; I'm in the UK).I'll post the answer here, and email you a copy too. As the question is of general interest, can anyone else who answers please copy the board for everyone's benefit? Thanks Posted by dawn (dawn), 18 September 2002 Thankyou!Urgent need of advise... Posted by admin (Graham Ellis), 19 September 2002 OK - let me make sure that I understand the application and question.You've already implemented a double linked list class in Java, with a number of methods that you can use to manipulate the list. I hope that you've written some good strong test code to test that your methods work and do what yoou intend? If not, that's the next stage before you write any more code - write each class that has any code of substance, test and debug it before you more on to writing the next class. You now want to go on and write a command based handler to manipulate your double linked list so that you can type in a command such as delete 10 and it will delete the item at position 10 in the linked list, or insert 15 demo.txt and it will insert an element into the linked list which is the content of demo.txt before element i5 in the list. And you're looking for tips ... I hope that when you wrote your double linked list class, you thought carefully about what methods would be needed by any caalling classes. In just the same way, you should start by working out what facilities the user of the handler application will need, and then you'll want to specify those in a simple language which is both user friendly and easy to code. You'll notice that my suggestion above uses a command based rather than a function based approach, with space separators between each elements, one action per line, and all parameters space specified. Write some test code in your proposed language, and ensure that it's fit for everything your users want before you start coding your application class(es). Application classes - a parser that take in a command as a string, tokenises it, and returns an array (or ArrayList or Vector) of the elements, and the main application class itself which reads a command, calls the command parser, then goes through a switch to implement each of your commands. You'll have lots of other methods, probably static ones, used in each case, so that you only write / use each block of code once. If your command language is going to get substantially complex in the future and on a projcet that's to be used for years, then the metrics and the design approach would vary. Hope this is of some use - hope I've read the application spec close enough to not be completely off track Posted by dawn (dawn), 20 September 2002 Your insight and advise is greatly appreciated - currently in the middle of creating my parser class. It is, indeed, a command that accepts two tokens as in 'fd 100'. Thankyou once again!This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |