/* * File: InputOutputPair.java * Author: Justin Basilico * Course: PO CS 152: Neural Networks * Assignment: Final Project * Updated: 2001.12.18 * Created: 2001.12.03 * * Description: * This file contains the InputOutputPair class, which is just a simple * NetworkInput that stores an input and an output Object that can be * retrieved. * * Copyright: Justin Basilico (2001). */ /** * InputOutputPair class * * This class implements a simple NetworkInput that is a pair of two Objects, * one that is the input Object and another that is the output Object. These * two Objects can be accessed by the getProperty() method and providing * PROPERTY_INPUT or "input" to get the input Object and PROPERTY_OUTPUT or * "output" to get the output Object. Any other property name or number will * just make the InputOutputPair return null. * * This class just deals with Objects so that it can be generalized for a lot * of different uses. Most implementations probably will just assume that the * Object that is returned is of the proper class and will cast it to that * class automatically. * * @author Justin Basilico * @version 2001.12.18 * @see NetworkInput * @see UnitEncoder */ public class InputOutputPair extends Object implements NetworkInput { /** PROPERTY_INPUT * This integer is the property number for the input Object for the * InputOutputPair. */ public static final int PROPERTY_INPUT = 0; /** PROPERTY_OUTPUT * This integer is the property number for the output Object for the * InputOutputPair. */ public static final int PROPERTY_OUTPUT = 1; /** input * The Object stored as the input for this InputOutputPair. */ private Object input = null; /** output * The Object stored as the output for this InputOutputPair. */ private Object output = null; /** * InputOutputPair basic constructor * * This constructor takes an input and output Object to store in the pair * and just stores them in the created InputOutputPair. * * @param input The input Object to store in the pair. * @param output The output Object to store in the pair. */ public InputOutputPair( Object input, // Input Object for the pair. Object output) // Output Object for the pair. { // Just point to the given Objects. this.input = input; this.output = output; } /** * getProperty (integer) * * This method takes an integer property name and returns the Object for * that property. The two property numbers used by InputOutputPair are * PROPERTY_INPUT and PROPERTY_OUTPUT for the input and output Objects * stored in the InputOutputPair. If the given number does not match * either one, then null is returned. * * @param propertyNum The integer property number to get from this * NetworkInput. * @return The Object with the given property number. The input is * returned for PROPERTY_INPUT and the output is returned for * PROPERTY_OUTPUT. Otherwise, null is returned. * @see InputOutputPair.PROPERTY_INPUT * @see InputOutputPair.PROPERTY_OUTPUT * @see InputOutputPair.getProperty(String) * @see NetworkInput.getProperty(int) */ public Object getProperty( int propertyNum) // Property number to get. { if ( propertyNum == PROPERTY_INPUT ) return input; else if ( propertyNum == PROPERTY_OUTPUT ) return output; else return null; } /** * getProperty (String) * * This method takes a String property name and returns the Object for * that property. The two properties used by InputOutputPair are "input" * and "output" for the input and output Objects in the InputOutputPair. * It ignores case when comparing the given property name to the two * Strings. If the given String does not match either one, then null is * returned. * * @param propertyName The String name of the property to get from this * NetworkInput. * @return The Object with the given property name. The input is returned * for the property "input" and the output is returned for the * property "output". Otherwise, null is returned. * @see InputOutputPair.getProperty(int) * @see NetworkInput.getProperty(String) */ public Object getProperty( String propertyName) // Property name to get. { if ( propertyName.equalsIgnoreCase("input") ) return input; else if ( propertyName.equalsIgnoreCase("output") ) return output; else return null; } /** * getInput * * This method returns the input Object in this InputOutputPair. * * @return The input Object in this pair. */ public Object getInput() { return input; } /** * getOutput * * This method returns the output Object in this InputOutputPair. * * @return The output Object in this pair. */ public Object getOutput() { return output; } }