⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testreport.java

📁 java编写的OCR软件
💻 JAVA
字号:
package de.spieleck.app.jacson.report;

import java.io.*;
import java.util.Iterator;

import gnu.trove.THashSet;

import de.spieleck.app.jacson.JacsonConfigException;

import de.spieleck.config.ConfigNode;

/**
 * Report to test generated events against a reference file 
 * generated by PrintingReport.
 * @author fsn
 */
public class TestReport
    extends PrintingReport
{
    public final static String REFERENCE_FILE = "reference";
    public final static String IGNORE = "ignore";

    /** Input for the reference file. */
    protected LineNumberReader lnr;

    /** Count different lines */
    protected int diffCount;

    /** names to be ignored on comparison */
    protected THashSet ignores;

    /** Number of ignored lines */
    protected int ignored;

    /** Number of values */
    protected int valueCount;

    public TestReport() 
    {
        clear();
    }

    public void init(ConfigNode config)
        throws JacsonConfigException
    {
        String iName = config.getString(REFERENCE_FILE, null);
        setReference(iName);
        Iterator it = config.childrenNamed(IGNORE);
        while ( it.hasNext() )
        {
            ConfigNode cnode = (ConfigNode) it.next();
            addIgnore(cnode.getString());
        }
        super.init(config);
    }

    public void clear()
    {
        diffCount = 0;
        ignored = 0;
        valueCount = 0;
        ignores = new THashSet();
    }

    public void setReference(String referenceName)
        throws JacsonConfigException
    {
        if ( referenceName == null )
            throw new JacsonConfigException("Missing "+REFERENCE_FILE);
        try
        {
            lnr = new LineNumberReader(new FileReader(referenceName));
        }
        catch ( IOException e )
        {
            throw new JacsonConfigException("Cannot open "+referenceName+" "+e);
        }
    }

    public void addIgnore(String ignore)
    {
        ignores.add(ignore);
    }

    public boolean accept(ConfigNode cn)
    {
        String name = cn.getName();
        return super.accept(cn)
            || name.equals(REFERENCE_FILE)
            || name.equals(IGNORE)
            ;
    }

    protected StringBuffer sb = new StringBuffer(100);

    public void report(String localName, String value)
    {
        valueCount++;
        String oldl = null;
        try
        {
            if ( lnr != null )
                oldl = lnr.readLine();
        }
        catch ( IOException stay_null ) 
        { 
            // let it be as it is!
            stay_null.printStackTrace();
        }
        sb.setLength(0);
        Iterator it = begins.iterator();
        while ( it.hasNext() )
        {
            sb.append((String)it.next()).append('.');
        }
        sb.append(localName);
        if ( ignores.contains(sb.toString()) )
        {
            ignored++;
        }
        else
        {
            sb.append('=').append(value);
            String newl = sb.toString();
            if ( !newl.equals(oldl) )
            {
                diffCount++;
                if ( pw != null )
                {
                    pw.println("*"+diffCount+". difference in line "
                                                        +getLineNumber());
                    pw.println("+old:"+oldl);
                    pw.println("+new:"+newl);
                }
            }
        }
    }

    public void finish(boolean close)
    {
        String msg = "*inspected items:"+getLineNumber()
                                  +" "+diffCount+" differences"
                                  +", ignored "+ignored
                                  +", valueCount="+valueCount;
        if ( pw != null )
        {
            pw.println(msg);
            if ( close )
                pw.close();
        }
        else
            System.out.println(msg);
    }

    public int getDiffCount()
    {
        return diffCount;
    }

    public int getIgnores()
    {
        return ignored;
    }

    public int getLineNumber()
    {
        if ( lnr == null )
            return -1;
        else
            return lnr.getLineNumber();
    }

    public int getValueCount()
    {
        return valueCount;
    }
}
//
//    Jacson - Text Filtering with Java.
//    Copyright (C) 2002 Frank S. Nestel (nestefan -at- users.sourceforge.net)
//
//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -