java hashmap

lakshmi2006's Avatar
Newbie Member
hello sir ,
To write a java program that parses a text file input.txt and the output of the program is a concurrent hashmap in the specified format.The below program makes use of vector data stucture to do this.Please modify this program so that the program should use hashmap data structure for parsing and outputing.please help me.
Program.java:
Code: JAVA
import java.io.*;
import org.w3c.dom.Document;
import org.w3c.dom.*;
import java.util.*;

class ConfigLine
{
    public Vector ctrlRtrList = new Vector();
    public Vector grpAddr = new Vector();
    public Vector srcList = new Vector();
    public Vector rtrList = new Vector();
    public Vector rPSpecs = new Vector();

    public void readData() throws IOException
    {
        BufferedReader filein = getFileStream();

        if (filein == null)
        return;


        String currentLine = null;

        // Read line by line
        while((currentLine = filein.readLine()) != null )
        {
            // Ignore comments
            if (currentLine.startsWith("#"))
            continue;

            else
            {
    StringTokenizer st=new StringTokenizer(currentLine, ":");

                int i=0;
                while (st.hasMoreElemen())
                {
        String tList(st.nextElement()).toString();
                    ++i;
                    switch (i)
                    {
                    case 1:
            fillVector(tList,ctrlRtrList); //Fill the vector with the list values
                        break;

                                case 2:grpAddr.addElement(tList);
                        break;

        case 3:
                                      fillVector(tList,srcList);
                        break;

        case 4:
        fillVector(tList,rtrList);
                        break;

                                  case 5:
            fillVector(tList,rPSpecs);
                        break;
                   
}
                }
            }
        }
    }

    public void fillVector(String listStr, Vector v)
    {
    StringTokenizer st1=new StringTokenizer(listStr, ",");
        while (st1.hasMoreElements())
        {
            v.addElement(st1.nextElement());
        }
    }

    // Gets the defaults file input stream as a buffered reader
    private static BufferedReader getFileStream()
    {
        try
        {
    FileReader fr = new FileReader(new File("input.txt"));
        BufferedReader br = new BufferedReader(fr);
            return br;
        }
        catch(FileNotFoundException fnfeEx)
        {
            System.out.println(fnfeEx.toString());
            return null;
        }
    }

    public void readVector()
    {
        if(ctrlRtrList.size()==0)
        System.out.println("\nNo Elements\n");
        else
        {
        System.out.println("Control Router List:");
            for(int i=0;i<ctrlRtrList.size();i++)
        System.out.println(ctrlRtrList.elementAt(i));
        }

        if(grpAddr.size()==0)
        System.out.println("\nNo Elements\n");
        else
        {
        System.out.println("Group Address:");
        System.out.println(grpAddr.elementAt(0));
        }

        if(srcList.size()==0)
        System.out.println("No Elements\n");
        else
{
            System.out.println("Source List:");
            for(int i=0;i<srcList.size();i++)
        System.out.println(srcList.elementAt(i));
        }

        if(rtrList.size()==0)
        System.out.println("No Elements\n");
        else
        {
            System.out.println("Router List:");
            for(int i=0;i<rtrList.size();i++)
        System.out.println(rtrList.elementAt(i));
        }

        if(rPSpecs.size()==0)
        System.out.println("No Elements\n");
        else
        {
            System.out.println("RP-Specs List:");
            for(int i=0;i<rPSpecs.size();i++)
        System.out.println(rPSpecs.elementAt(i));
        }
    }
}


class Program
{
    static ConfigLine cl=new ConfigLine();
    public static void main(String argv[])
    {
        try
        {
            cl.readData();
        }
        catch(Exception e)
        {
        System.out.println("Wow u'v an exception");
        }

        cl.readVector();
    }
}
input.txt:

#Format:
# <CtrRtrList>:<GrpAddr>:<SrcList>:<RtrList>[:RP-spec]
10.2.32.82:239.192.0.2:10.00.5.183,10.0.6.185:10.2 .32.85,10.2.32.81,10.2.32.82:10.0.2.82,,10.2.78.42
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
This forum is not for just putting your code and let ask to implement some more to it. Its for sharing of knowledge and ask your queries if you are stuck with something. If you are stuck with hashmap you can use the following links

Hashmap
Hashmap sample
kush_2207's Avatar, Join Date: Jun 2007
Go4Expert Member
What does hashmap ? Please explain.. It takes filename as an Input and what would be the output in the sense of hashmap ? Thank you.
LauDauns's Avatar, Join Date: Oct 2007
Newbie Member
I am sure you will find a good response!!
Good luck for you.

Last edited by shabbir; 12Oct2007 at 14:12.. Reason: Confine links to signatures
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
LauDauns, Please do not posts link to your site your account can be in trouble.