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

📄 performancevector.java

📁 著名的开源仿真软件yale
💻 JAVA
字号:
/* *  YALE - Yet Another Learning Environment *  Copyright (C) 2002, 2003 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,  *          Katharina Morik, Oliver Ritthoff *      Artificial Intelligence Unit *      Computer Science Department *      University of Dortmund *      44221 Dortmund,  Germany *  email: yale@ls8.cs.uni-dortmund.de *  web:   http://yale.cs.uni-dortmund.de/ * *  This program is free software; you can redistribute it and/or *  modify it under the terms of the GNU General Public License as  *  published by the Free Software Foundation; either version 2 of the *  License, or (at your option) any later version.  * *  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 for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *  USA. */package edu.udo.cs.yale.operator.performance;import edu.udo.cs.yale.tools.ResultService;import edu.udo.cs.yale.operator.ResultObjectAdapter;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.operator.Operator; import java.util.ArrayList;import java.util.Iterator;import java.awt.Component;import javax.swing.JLabel;/** Handles several performance criteria. It is possible to obtain more than one criterion *  and therefore they are added to a criteria list.  *  *  @author Ingo *  @version $Id: PerformanceVector.java,v 2.8 2003/04/30 17:02:13 fischer Exp $ */public class PerformanceVector extends ResultObjectAdapter implements Comparable {    public static class DefaultComparator implements PerformanceComparator {	public double compare(PerformanceVector pv1, PerformanceVector pv2) {	    return pv1.getMainCriterion().compareTo(pv2.getMainCriterion());	}    }    /** Used to compare two performance vectors. */    private PerformanceComparator comparator = new DefaultComparator();    /** Name of the main criterion. */    private String mainCriterion = null;    /** Prefix for the result string. */    private ArrayList criteriaList = new ArrayList();    /** Creates a new performance criteria vector with a default result prefix. */    public PerformanceVector() {    }    public void setComparator(PerformanceComparator comparator) {	this.comparator = comparator;    }    /** Returns the number of performance criteria in the list. */    public int size() { return criteriaList.size(); }    /** Adds a {@link PerformanceCriterion} to the list of criteria. */    public void addCriterion(PerformanceCriterion pc) {	criteriaList.add(pc);    }    /** Sets the name of the main criterion      *  (must be added by {@link #addCriterion(PerformanceCriterion)}) */    public void setMainCriterionName(String mcName) {	if (get(mcName) == null) {	    LogService.logMessage("Main criterion not found: '"+mcName+"'.", LogService.ERROR);	}	this.mainCriterion = mcName;    }    /** Returns the main {@link PerformanceCriterion}. If the main criterion is not specified     *  by {@link #setMainCriterionName(String)}, the first criterion is returned. */    public PerformanceCriterion getMainCriterion() {	if (mainCriterion == null) {	    return get(0);	} else {	    PerformanceCriterion pc = get(mainCriterion);	    if (pc == null) return get(0);	    return pc;	}    }    /** Returns the PerformanceCriterion by index. */    public PerformanceCriterion get(int index) {	return (PerformanceCriterion)criteriaList.get(index);    }    /** Returns the PerformanceCriterion by name. */    public PerformanceCriterion get(String name) {	Iterator i = criteriaList.iterator();	while (i.hasNext()) {	    PerformanceCriterion c = (PerformanceCriterion )i.next();	    if (c.getName().equals(name)) return c;	}	return null;    }    public String toResultString() {	String result = getName() + ":\n";	Iterator i = criteriaList.listIterator();	while (i.hasNext()) {	    result += ((PerformanceCriterion)i.next()).toResultString()+"\n";	}	return result;    }    public String toString() {	String result = "PerformanceVector [";	for (int i = 0; i < size(); i++) {	    PerformanceCriterion pc = get(i);	    if (i > 0) result += ", ";	    if ((mainCriterion != null) && (pc.getName().equals(mainCriterion))) result += "*";	    result += pc;	}	return result + "]";    }    public int compareTo(Object o) {	double result = comparator.compare(this, (PerformanceVector)o);	if (result < 0.0) return -1;	else if (result > 0.0) return +1;	else return 0;    }    protected Object clone() {	PerformanceVector pv = new PerformanceVector();	Iterator i = criteriaList.listIterator();	while (i.hasNext()) {	    PerformanceCriterion pc = (PerformanceCriterion)i.next();	    pv.addCriterion((PerformanceCriterion)(pc).clone());	}	pv.comparator = this.comparator;	return pv;    }    public String toHTML() {	String result = "<h1>"+getName()+"</h1><ol>";	Iterator i = criteriaList.listIterator();	while (i.hasNext()) {	    result += "<li>" + ((PerformanceCriterion)i.next()).toString() + "</li>";	}	result += "</ol>";	return result;    }    public Component getVisualisationComponent() {	JLabel label = new JLabel("<html>"+toHTML()+"</html>");	label.setFont(label.getFont().deriveFont(java.awt.Font.PLAIN));	return label;    }    public void buildAverages(PerformanceVector pv) {	if (this.size() != pv.size()) throw new IllegalArgumentException("Performance vectors have different size!");	for (int i = 0; i < size(); i++)	    this.get(i).buildAverage(pv.get(i));    }}

⌨️ 快捷键说明

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