📄 iodescription.java
字号:
/*
* YALE - Yet Another Learning Environment
* Copyright (C) 2001-2004
* Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,
* Katharina Morik, Oliver Ritthoff
* Artificial Intelligence Unit
* Computer Science Department
* University of Dortmund
* 44221 Dortmund, Germany
* email: yale-team@lists.sourceforge.net
* 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;
import java.util.List;
import java.util.LinkedList;
import java.util.Iterator;
/** This class is a description of the (expected) input and (guaranteed) output classes
* of operators. It provides easy default implementations. <br>
*
* @author Simon, Ingo
* @version $Id: IODescription.java,v 2.4 2004/08/27 11:57:34 ingomierswa Exp $
*/
public class IODescription {
public static final int PASS_UNUSED_INPUT_TO_OUTPUT = 1;
public static final int DELETE_UNUSED_INPUT = 2;
private Class[] inputClasses, outputClasses;
private int outputBehaviour;
/** Constructs a new IODescription where all input and output classes are
* expected exactly once. output is the minimum set of output classes,
* the real output classes are determined by the outputBehaviour.
* Both <tt>input</tt> and <tt>ouput</tt> may be null and may contain
* a class more than once. */
public IODescription(Class[] input, Class[] output, int outputBehaviour) {
this.inputClasses = input;
this.outputClasses = output;
if (inputClasses == null) inputClasses = new Class[0];
if (outputClasses == null) outputClasses = new Class[0];
this.outputBehaviour = outputBehaviour;
}
/** Assumes PASS_UNUSED_INPUT_TO_OUTPUT. */
public IODescription(Class[] input, Class[] output) {
this(input, output, PASS_UNUSED_INPUT_TO_OUTPUT);
}
/** Returns the classes that are expected as input. */
public Class[] getInputClasses() {
return inputClasses;
}
/** Returns the output classes dependent on the outputBehaviour
* <ul>
* <li><tt>PASS_UNUSED_INPUT_TO_OUTPUT:</tt>output classes are the classes
* used in the constructor plus those classes in <tt>input[]</tt> that were
* not consumed. Classes are supposed to be consumed by the operator if
* they find a matching class in the input classes used in the constructor (which
* can be a superclass or interface)
* <li><tt>DELETE_UNUSED_INPUT:</tt>output classes are exactly those classes used
* in the constructor.
* </ul>
* In either case the output classes precede the unused input classes. Their order
* is conserved.
**/
public Class[] getOutputClasses(Class[] input, Operator operator) throws IllegalInputException {
switch (outputBehaviour) {
case PASS_UNUSED_INPUT_TO_OUTPUT:
List outputList = new LinkedList();
for (int i = 0; i < input.length; i++) {
outputList.add(input[i]);
}
for (int i = 0; i < inputClasses.length; i++) {
boolean found = false;
Iterator j = outputList.iterator();
while (j.hasNext()) {
if (inputClasses[i].isAssignableFrom((Class)j.next())) {
j.remove();
found = true;
break;
}
}
if (!found) throw new IllegalInputException(operator,inputClasses[i]);
}
for (int i = 0; i < outputClasses.length; i++) {
outputList.add(outputClasses[i]);
}
Class[] outputArray = new Class[outputList.size()];
outputList.toArray(outputArray);
return outputArray;
case DELETE_UNUSED_INPUT:
return outputClasses;
}
return null;
}
/** Returns true if oc contains a class which is a superclass of c. */
public static boolean containsClass(Class c, Class[] oc) {
for (int i = 0; i < oc.length; i++) {
if (c.isAssignableFrom(oc[i])) return true;
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -