checker.java

来自「cqME :java framework for TCK test.」· Java 代码 · 共 131 行

JAVA
131
字号
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program 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 * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tdk.sampletck.api.com.sun.tdk.sampleapi.StockInfoManager;import com.sun.tdk.sampleapi.*;import java.io.PrintStream;/** * Checker meant for checking of StockInfoManager * container-specific methods correctness. * */class Checker {    /**     *   internal container of <code>QuoteAgent</code> objects.     */    java.util.Vector state = new java.util.Vector();    PrintStream log = null;    StockInfoManager mgr = null;    /**     * Create Checker object     *     * @param mgr the <code>StockInfoManager</code> to check elements order within.     * @param log <code>PrintStream</code> for errors logging     */    public Checker(StockInfoManager mgr, PrintStream log) {        this.mgr = mgr;        this.log = log;    }    /**     * Add element into the linked StockInfoManager     *     * @param agent the <code>QuoteAgent</code> object to be added into StockInfoManager.     */    public void add(QuoteAgent agent) {        addAgain(agent);        state.addElement(agent);    }    /**     * Add element into the linked StockInfoManager again.     * This method invocation is applicable if and only if <code>agent</code>     * was already added via method <code>add(QuoteAgent)</code>.     *     * @param agent the <code>QuoteAgent</code> object to be added into StockInfoManager.     */    public void addAgain(QuoteAgent agent) {        mgr.addQuoteAgent(agent);    }    /**     * Remove an element from the linked StockInfoManager lookup table.     *     * @param agent the <code>QuoteAgent</code> object to be removed from StockInfoManager.     */    public void remove(QuoteAgent agent) {        mgr.removeQuoteAgent(agent);        state.removeElement(agent);    }    /**     * Compare two ordered containers: StockInfoManager lookup table and internal     * Checker container.     *     * @return true if and only if StockInfoManager lookup table and     *         internal Checker container of <code>QuoteAgent</code> objects     *         are equal as Enumerations.     */    public boolean checkState() {        if (mgr == null) {            return false;        }        if (!equal(mgr.getQuoteAgents(), state.elements())) {            return false;        }        return true;    }    private boolean equal(java.util.Enumeration e1, java.util.Enumeration e2) {        int idx = 0;        while (e1.hasMoreElements() && e2.hasMoreElements()) {            Object o1 = e1.nextElement();            Object o2 = e2.nextElement();            log.println(idx + "th element in StockInfoManager lookup table: "                    + o1);            log.println("Expected " + idx + "th element: " + o2);            if (o1 != o2) {                return false;            }            idx++;        }        if (e1.hasMoreElements() != e2.hasMoreElements()) {            log.println("StockInfoManager lookup table length is not equal to expected.");            return false;        }        return true;    }}

⌨️ 快捷键说明

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