| |||||||||||
implemeting using hashes or array Posted by sachin_chat (sachin_chat), 19 June 2006 hi , i am very new to java programming. i want to implement some thing shown below.i read a file and parse a line and find tokens from it. for example cache M var1 p1_seg ram i get tokens by instCache = tokens.nextToken(); instType = tokens.nextToken(); instVar = tokens.nextToken(); instSeg = tokens.nextToken(); instModule = tokens.nextToken(); i have such type of many strings in file. i have to parse them and find the names of variable, type of cahe operation , segment name and module name. there can be many strings which have same combinations of variable name , mod name , seg. what i want to do is for each combination of var name , seg name and mod name , i will maintain a entry and will update tyoe count if it M or H as many times. for example cache M var1 p1_seg ram cache M var1 p1_seg ram if there are two such entries , var1.p1_seg_ram will have count of M to be 2 how this can be impleted using hashes or arrays effectively Posted by admin (Graham Ellis), 19 June 2006 If each of the lines can have a different format, then it stikes me that you would be better to hold all the various attributes that are possible in an object, and use object inheritance to relate them to one another - that way you decouple your data structure from your model.Then store the objects in an ArrayList or Vector ... you won't be using a hash unless you have a unique key for each, and you won't be using an array unless you're sure of the number of items you have before you start populating it. Posted by sachin_chat (sachin_chat), 19 June 2006 thanks graham,what i was thinking was to use a class ( as structure in c) and define two members string name ( to hold name of variable+mod+seg) int index then i will create a object of it . every time after i parse the line , i will compare it with object.name. if it is null then i will add object to some array ( that i have to think of) and if it matches with any of onject.name i will incraese my index count by 1. what are your suggestion on this please comment any thing wich i had thought wrong Posted by admin (Graham Ellis), 20 June 2006 It looks sensible from such a short / summary spec.; some people might question the need for a separate index held within each item, but I'll encourage it for anything except the tinisest of jobs. That way, so can keep track of which object is which without having to rely on the position that something's found at in a list.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 |