Re: Need to Parse delimited File into DataStructures .....
LuckyBoy wrote:
I used ArrayList . 3 ArrayLists.
and have successfully collected UNIQUE NAMES with the Code below:
My only hitch is the storage Class of multiple field values of ROLE and
RESOURCES for one UNIQUE record NAME:
List alRec = new ArrayList();
FileReader fr = new FileReader(csvFile);
BufferedReader br = new BufferedReader(fr);
while((strRec=br.readLine()) != null){
feedRecCtr++;
alRec.add(strRec); // gets line records
}
FeedFileLength = feedRecCtr;
Iterator itr = alRec.iterator();
while(itr.hasNext()){
strRec = (String)itr.next();
StringTokenizer strtok = new StringTokenizer(strRec,":");
while(strtok.hasMoreElements()){
if(tokenCtr == 1){
String kerbToken = strtok.nextToken();
if((null != alNameID) && !(alNameID.contains(kerbToken))) // For
UNIQUE Names
{
alNameID.add(kerbToken); // ADDs UNIQUE NAMEs
}
}
if(tokenCtr == 2){
alRole.add(strtok.nextToken()); // ADDS ROLES
}
if(tokenCtr == 3){
alResourceType.add(strtok.nextToken()); // ADDS RESOURCES
tokenCtr = 0;
}
tokenCtr++;
}
I can't read the above code the way it is formatted. I can say that you
are doing things in a difficult manner. My suggestion wasn't to use only
ArrayLists, in fact it's quite a bad implementation that way you have
done it because it seems to rely on the indexes in each array being
aligned so to speak.
I get the feeling that this is an assignment question? If so you should
really figure out what you have to do yourself or you won't learn anything.
You can also perform the above with one while loop and less code, I'll
leave you to think about it for a while with the hint that you really do
need to create a new class.
Lionel.