// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TwoStepAnalysis.java

import java.io.*;
import java.util.StringTokenizer;

public class TwoStepAnalysis
{

    public TwoStepAnalysis()
    {
        step1 = new int[26];
        step2 = new int[26][26];
        for(int i = 0; i < 26; i++)
        {
            step1[i] = 0;
            for(int j = 0; j < 26; j++)
                step2[i][j] = 0;

        }

    }

    public void analyzeList(String s)
    {
        if(!s.endsWith(".list"))
            s = s + ".list";
        try
        {
            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(new FileInputStream(s)));
            String s1 = "";
            Object obj = null;
            Object obj2 = null;
            Object obj4 = null;
            boolean flag = false;
            boolean flag1 = false;
            while(s1 != null) 
            {
                s1 = bufferedreader.readLine();
                if(s1 != null)
                {
                    for(StringTokenizer stringtokenizer = new StringTokenizer(s1); stringtokenizer.hasMoreTokens();)
                    {
                        String s2 = stringtokenizer.nextToken();
                        if(s2.length() > 1)
                        {
                            char ac[] = s2.toCharArray();
                            int i = ac[0] - 65;
                            int j;
                            if((char)i == 'Q' && ac.length > 2)
                                j = ac[2] - 65;
                            else
                                j = ac[1] - 65;
                            step1[i]++;
                            step2[i][j]++;
                        }
                    }

                    Object obj1 = null;
                    Object obj3 = null;
                }
            }
            bufferedreader.close();
            bufferedreader = null;
            System.gc();
            return;
        }
        catch(Exception exception)
        {
            System.out.println("Error while loading " + s + "!");
            exception.printStackTrace();
            System.out.println("Exiting...");
            System.exit(0);
            return;
        }
    }

    public void load(String s)
    {
        if(!s.endsWith(".step"))
            s = s + ".step";
        try
        {
            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(new FileInputStream(s)));
            String s1 = "";
            StringTokenizer stringtokenizer = null;
            String s3 = null;
            s1 = bufferedreader.readLine();
            stringtokenizer = new StringTokenizer(s1);
            for(int i = 0; i < 26; i++)
            {
                s3 = stringtokenizer.nextToken();
                step1[i] = Integer.parseInt(s3);
            }

            for(int j = 0; j < 26; j++)
            {
                String s2 = bufferedreader.readLine();
                if(s2 != null)
                {
                    stringtokenizer = new StringTokenizer(s2);
                    for(int k = 0; k < 26; k++)
                    {
                        s3 = stringtokenizer.nextToken();
                        step2[j][k] = Integer.parseInt(s3);
                    }

                }
            }

            bufferedreader.close();
            bufferedreader = null;
            s3 = null;
            stringtokenizer = null;
        }
        catch(Exception exception)
        {
            System.out.println("Error while loading " + s + "!");
            exception.printStackTrace();
            System.out.println("Exiting...");
            System.exit(0);
        }
        System.gc();
    }

    public void save(String s)
    {
        if(!s.endsWith(".step"))
            s = s + ".step";
        try
        {
            PrintWriter printwriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(s))));
            String s1 = "";
            for(int i = 0; i < 26; i++)
                s1 = s1 + " " + step1[i];

            printwriter.print(s1 + "\n");
            for(int j = 0; j < 26; j++)
            {
                String s2 = "";
                for(int k = 0; k < 26; k++)
                    s2 = s2 + " " + step2[j][k];

                printwriter.print(s2 + "\n");
            }

            printwriter.flush();
            printwriter.close();
            printwriter = null;
        }
        catch(Exception exception)
        {
            System.out.println("Error while loading " + s + "!");
            exception.printStackTrace();
            System.out.println("Exiting...");
            System.exit(0);
        }
        System.gc();
    }

    public static void main(String args[])
    {
        if(args.length < 1)
        {
            System.out.println("Commandline usage: java TwoStepAnalysis <file>");
            System.out.println("The <file> will be read from a <file>.list");
            System.out.println("and its analysis saved to <file>.step");
            System.exit(0);
        }
        for(int i = 0; i < args.length; i++)
        {
            if(args[i].endsWith(".list") || args[i].endsWith(".step"))
                args[i] = args[i].substring(0, args[i].length() - 5);
            TwoStepAnalysis twostepanalysis = new TwoStepAnalysis();
            twostepanalysis.analyzeList(args[i]);
            twostepanalysis.save(args[i]);
        }

    }

    public int step1[];
    public int step2[][];
}
