org.concord.biologica.engine
Class GenotypeToPhenotypeRule

java.lang.Object
  |
  +--org.xml.sax.HandlerBase
        |
        +--org.concord.biologica.engine.EngineObject
              |
              +--org.concord.biologica.engine.GenotypeToPhenotypeRule
All Implemented Interfaces:
org.xml.sax.DocumentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, java.util.EventListener, java.beans.PropertyChangeListener, java.io.Serializable

public final class GenotypeToPhenotypeRule
extends EngineObject
implements java.io.Serializable, java.beans.PropertyChangeListener

This class represents a rule for choosing a phenotype from a genotype.

In detail, an object of this class represents a statement of the form: if then <"then characteristic"> else <"else characteristic"> So the instance variables and properties of this class are named appropriately (ifAlleles, thenCharacteristic, elseCharacteristic, etc.).

An object of this class will generate the following property change events:

Version:
$Revision: 1.1.1.1 $ $Date: 2001/04/28 00:39:12 $
Author:
$Author: ed $
See Also:
EngineProp.DELETED, EngineProp.ELSE_CHARACTERISTIC, EngineProp.GENDER, EngineProp.ID, EngineProp.IF_SPECIES_ALLELE_ADDED, EngineProp.IF_SPECIES_ALLELE_REMOVED, EngineProp.LOCKED_STATE, EngineProp.NAME, EngineProp.THEN_CHARACTERISTIC, PropertyChangeListener, Serialized Form

Fields inherited from class org.concord.biologica.engine.EngineObject
AUTOMATIC_LOCKED, AUTOMATIC_LOCKED_STRING, changes, deleted, FALSE, id, lockedState, MANUAL_AND_AUTOMATIC_LOCKED, MANUAL_AND_AUTOMATIC_LOCKED_STRING, MANUAL_LOCKED, MANUAL_LOCKED_STRING, NULL_ID, TRUE, UNLOCKED, UNLOCKED_STRING, xmlElementContext
 
Constructor Summary
GenotypeToPhenotypeRule(Species aSpecies, java.lang.String aName)
          Creates a new genotype to phenotype rule with the given name.
GenotypeToPhenotypeRule(Species aSpecies, java.lang.String aName, GenotypeToPhenotypeRule aRule, SpeciesAllele oldIfSpeciesAllele, SpeciesAllele newIfSpeciesAllele)
          Creates a new genotype to phenotype rule with the given name, an existing rule as a template and 2 species alleles.
GenotypeToPhenotypeRule(Species aSpecies, java.lang.String anElementName, int anElementID, com.sun.xml.parser.Parser anXMLParser, ImportContext importContext)
          Create a new genotype to phenotype rule and start handling XML parsing events to set the properties of this object.
 
Method Summary
 void addIfSpeciesAllele(SpeciesAllele anIfSpeciesAllele)
          Adds an if species allele to this rule.
 void characters(char[] ch, int start, int length)
          Receive notification of character data.
 boolean containsIfSpeciesAllele(SpeciesAllele anIfSpeciesAllele)
          Return if the if species alleles contains the given species allele
 void delete()
          Delete this object, notifying parent objects and deleting any child objects.
 void delete(boolean notifyChange)
           
 void endElement(java.lang.String anElementName)
          Handle notification that the parsing of the given element has ended.
 Characteristic getElseCharacteristic()
          Return the else characteristic of this genotype to phenotype rule.
 int getGender()
          Return the gender of this rule, which will be one of Species.FEMALE_AND_MALE, Species.FEMALE_ONLY or Species.MALE_ONLY.
 java.lang.String getGenderAsString()
          Return the gender of this rule, which will be one of Species.FEMALE_AND_MALE_STRING, Species.FEMALE_ONLY_STRING or Species.MALE_ONLY_STRING.
 java.util.Enumeration getIfSpeciesAlleles()
          Returns an enumeration over the rule's if species alleles.
 java.lang.String getName()
          Return the name of this genotype to phenotype rule.
 int getNumberOfIfSpeciesAlleles()
          Return the number of if species alleles of this rule.
 Species getSpecies()
          Return the species of this genotype to phenotype rule.
 Characteristic getThenCharacteristic()
          Return the then characteristic of this genotype to phenotype rule.
 World getWorld()
          Get the world containing this object.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable white space character data.
 void propertyChange(java.beans.PropertyChangeEvent event)
          Handle property change events, mostly DELETED events.
 void replaceIfSpeciesAllele(SpeciesAllele oldIfSpeciesAllele, SpeciesAllele newIfSpeciesAllele)
          Replace the given old if species allele with the given new if species allele.
 void setElseCharacteristic(Characteristic aCharacteristic)
          Sets the else characteristic of this genotype to phenotype rule.
 void setGender(int aGender)
          Set the gender of this genotype to phenotype rule.
 void setGenderAsString(java.lang.String aGenderString)
          Set the gender of this genotype to phenotype rule.
 void setName(java.lang.String aName)
          Sets the name.
 void setThenCharacteristic(Characteristic aCharacteristic)
          Sets the then characteristic of this genotype to phenotype rule.
 void startElement(java.lang.String anElementName, org.xml.sax.AttributeList amap)
          Handle notification that the parser has hit the start of a new element with the given name and attributes.
 void test(int sex, java.util.Vector speciesAlleles, java.util.Vector characteristics, java.util.Vector traits)
          Test this rule given a sex, a set of species alleles and generating zero or one characteristic, which is placed on the given characteristics vector and its trait put on the traits UNLESS there is already another characteristic of that trait on the traits vector.
 java.lang.String toString()
          Return a string representation of this object, usually the object's name.
 void writeToStream(java.io.PrintWriter stream)
          Writes this object to the given stream in XML format.
 
Methods inherited from class org.concord.biologica.engine.EngineObject
addPropertyChangeListener, getID, getLockedState, getLockedStateAsString, isAutomaticLocked, isDeleted, isLocked, isManualLocked, notifySelected, release, removePropertyChangeListener, setAutomaticLocked, setID, setLockedState, setLockedStateAsString, setManualLocked
 
Methods inherited from class org.xml.sax.HandlerBase
endDocument, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, startDocument, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GenotypeToPhenotypeRule

public GenotypeToPhenotypeRule(Species aSpecies,
                               java.lang.String aName)
Creates a new genotype to phenotype rule with the given name.

Parameters:
aSpecies - Species - the species containing this character, may not be null
aName - String - name of this rule, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

GenotypeToPhenotypeRule

public GenotypeToPhenotypeRule(Species aSpecies,
                               java.lang.String aName,
                               GenotypeToPhenotypeRule aRule,
                               SpeciesAllele oldIfSpeciesAllele,
                               SpeciesAllele newIfSpeciesAllele)
Creates a new genotype to phenotype rule with the given name, an existing rule as a template and 2 species alleles. This new rule should be a copy of the given one with all references to the first allele replaced with references to the second allele.
Parameters:
aSpecies - Species - the species containing this rule, may not be null
aName - String - name of this rule, may not be null
aRule - GenotypeToPhenotypeRule - rule to copy, may not be null
oldIfSpeciesAllele - SpeciesAllele - original if species allele, may not be null
newIfSpeciesAllele - SpeciesAllele - new if species allele, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

GenotypeToPhenotypeRule

public GenotypeToPhenotypeRule(Species aSpecies,
                               java.lang.String anElementName,
                               int anElementID,
                               com.sun.xml.parser.Parser anXMLParser,
                               ImportContext importContext)
Create a new genotype to phenotype rule and start handling XML parsing events to set the properties of this object.

Parameters:
aSpecies - Species - the enclosing species for this new genotype to phenotype rule
anElementName - String - the element name
anElementID - int - the element id
anXMLParser - com.sun.xml.parser.Parser - the element parser
importContext - ImportContext - import context for mapping ids from file to this world
Throws:
java.lang.IllegalArgumentException - - input arguments illegal
Method Detail

startElement

public void startElement(java.lang.String anElementName,
                         org.xml.sax.AttributeList amap)
                  throws org.xml.sax.SAXException
Handle notification that the parser has hit the start of a new element with the given name and attributes.

For internal elements (elements that are non-EngineObject instance variables of this object), call xmlElementContext.startElement() and xmlElementContext will receive the remaining element notifications. For external elements (elements that are EngineObject instance variables of this object), create an object of the appropriate class and that object will receive the remaining element notifications.

Overrides:
startElement in class org.xml.sax.HandlerBase
Parameters:
anElementName - String - name of element
amap - AttributeList - an attribute list

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Receive notification of character data.
Overrides:
characters in class org.xml.sax.HandlerBase
Parameters:
ch - char[] - characters
start - int - start of string
length - int - length of string

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Receive notification of ignorable white space character data.
Overrides:
ignorableWhitespace in class org.xml.sax.HandlerBase
Parameters:
ch - char[] - characters
start - int - start of string
length - int - length of string

endElement

public void endElement(java.lang.String anElementName)
                throws org.xml.sax.SAXException
Handle notification that the parsing of the given element has ended.
Overrides:
endElement in class org.xml.sax.HandlerBase
Parameters:
anElementName - String - the element name

delete

public void delete()
Delete this object, notifying parent objects and deleting any child objects.

When this method is successful, a property change event is generated for the property named EngineProp.DELETED.

Overrides:
delete in class EngineObject

delete

public void delete(boolean notifyChange)

toString

public java.lang.String toString()
Return a string representation of this object, usually the object's name.

Overrides:
toString in class EngineObject
Returns:
String - string representation of object

getSpecies

public Species getSpecies()
Return the species of this genotype to phenotype rule.

Returns:
Species - species of this genotype to phenotype rule, never null

getWorld

public World getWorld()
Get the world containing this object.

Overrides:
getWorld in class EngineObject
Returns:
World - the world containing this object, never null.

getName

public java.lang.String getName()
Return the name of this genotype to phenotype rule.

Returns:
String - name of this genotype to phenotype rule, may not be null

setName

public void setName(java.lang.String aName)
Sets the name.

When this method is successful, a property change event is fired for the property named EngineProp.NAME.

Parameters:
aName - String - rule name, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument illegal

getGender

public int getGender()
Return the gender of this rule, which will be one of Species.FEMALE_AND_MALE, Species.FEMALE_ONLY or Species.MALE_ONLY.

Returns:
int - gender aspect of this rule
See Also:
Species.FEMALE_AND_MALE, Species.FEMALE_ONLY, Species.MALE_ONLY

getGenderAsString

public java.lang.String getGenderAsString()
Return the gender of this rule, which will be one of Species.FEMALE_AND_MALE_STRING, Species.FEMALE_ONLY_STRING or Species.MALE_ONLY_STRING. Returns a string.

Returns:
int - gender aspect of this rule
See Also:
Species.FEMALE_AND_MALE_STRING, Species.FEMALE_ONLY_STRING, Species.MALE_ONLY_STRING

setGender

public void setGender(int aGender)
Set the gender of this genotype to phenotype rule.

The new gender must be one of Species.FEMALE_AND_MALE, Species.FEMALE_ONLY or Species.MALE_ONLY.

When this method is successful, a property change event is fired for the property named EngineProp.COLUMN_GENDER.

Parameters:
aGender - int - the new gender of this rule
Throws:
java.lang.IllegalArgumentException - - input argument illegal
ObjectDeletedException - - object is deleted and cannot be modified
ObjectLockedException - - object is locked and cannot be modified
See Also:
Species.FEMALE_AND_MALE, Species.FEMALE_ONLY, Species.MALE_ONLY

setGenderAsString

public void setGenderAsString(java.lang.String aGenderString)
Set the gender of this genotype to phenotype rule.

The new gender must be one of Species.FEMALE_AND_MALE_STRING, Species.FEMALE_ONLY_STRING or Species.MALE_ONLY_STRING.

When this method is successful, a property change event is fired for the property named EngineProp.COLUMN_GENDER.

Parameters:
aGenderString - String - the new gender of this rule as a string
Throws:
java.lang.IllegalArgumentException - - input argument illegal
ObjectDeletedException - - object is deleted and cannot be modified
ObjectLockedException - - object is locked and cannot be modified
See Also:
Species.FEMALE_AND_MALE_STRING, Species.FEMALE_ONLY_STRING, Species.MALE_ONLY_STRING

getIfSpeciesAlleles

public java.util.Enumeration getIfSpeciesAlleles()
Returns an enumeration over the rule's if species alleles.

If there are no if species alleles in this rule, an enumeration with no elements is returned.

Returns:
Enumeration - an enumeration over the vector of if species alleles of this rule, never null

containsIfSpeciesAllele

public boolean containsIfSpeciesAllele(SpeciesAllele anIfSpeciesAllele)
Return if the if species alleles contains the given species allele
Parameters:
anIfSpeciesAllele - SpeciesAllele - an if species allele, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

getNumberOfIfSpeciesAlleles

public int getNumberOfIfSpeciesAlleles()
Return the number of if species alleles of this rule.

Returns:
int - the number of if species alleles of this rule

addIfSpeciesAllele

public void addIfSpeciesAllele(SpeciesAllele anIfSpeciesAllele)
Adds an if species allele to this rule. Does not check if this allele or an equivalent allele already has been added to this rule.

Parameters:
anIfSpeciesAllele - SpeciesAllele - the allele to add to this rule, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal
ObjectDeletedException - - object is deleted and cannot be modified
ObjectLockedException - - object is locked and cannot be deleted

replaceIfSpeciesAllele

public void replaceIfSpeciesAllele(SpeciesAllele oldIfSpeciesAllele,
                                   SpeciesAllele newIfSpeciesAllele)
Replace the given old if species allele with the given new if species allele. The key here is that we should maintain the position, so the old and new if species alleles have the same order in this object.

If the oldIfSpeciesAllele is null or not found, then we just add the newIfSpeciesAllele on to the end of the list of ifSpeciesAlleles.

If the newIfSpeciesAllele is null, then we just remove the oldIfSpeciesAllele.

If both the oldIfSpeciesAllele and the newIfSpeciesAllele are null or not found, do nothing.

Parameters:
SpeciesAllele - oldIfSpeciesAllele - if species allele to remove, may be null
SpeciesAllele - newIfSpeciesAllele - if species allele to add, may be null

getThenCharacteristic

public Characteristic getThenCharacteristic()
Return the then characteristic of this genotype to phenotype rule.

Returns:
Characteristic - then characteristic of this genotype to phenotype rule, may be null

setThenCharacteristic

public void setThenCharacteristic(Characteristic aCharacteristic)
Sets the then characteristic of this genotype to phenotype rule.

When this method is successful, a property change event is fired for the property named EngineProp.THEN_CHARACTERISTIC.

Parameters:
aCharacteristic - Characteristic - new then characteristic, may be null
Throws:
java.lang.IllegalArgumentException - - input argument illegal

getElseCharacteristic

public Characteristic getElseCharacteristic()
Return the else characteristic of this genotype to phenotype rule.

Returns:
Characteristic - else characteristic of this genotype to phenotype rule, may be null

setElseCharacteristic

public void setElseCharacteristic(Characteristic aCharacteristic)
Sets the else characteristic of this genotype to phenotype rule.

When this method is successful, a property change event is fired for the property named EngineProp.ELSE_CHARACTERISTIC.

Parameters:
aCharacteristic - Characteristic - new else characteristic, may be null
Throws:
java.lang.IllegalArgumentException - - input argument illegal

test

public void test(int sex,
                 java.util.Vector speciesAlleles,
                 java.util.Vector characteristics,
                 java.util.Vector traits)
Test this rule given a sex, a set of species alleles and generating zero or one characteristic, which is placed on the given characteristics vector and its trait put on the traits UNLESS there is already another characteristic of that trait on the traits vector. This last bit prevents 2 characteristics of the same trait being put on the characteristics vector, meaning that rules should be evaluated in priority order (highest to lowest) to get the proper characteristics on the vector.

Parameters:
sex - int - sex of organism - Organism.MALE, Organism.FEMALE or Organism.NO_SEX
speciesAlleles - Vector - species alleles vector
characteristics - Vector - characteristics vector
traits - Vector - traits vector

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
Handle property change events, mostly DELETED events.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
event - PropertyChangeEvent - the property change event

writeToStream

public void writeToStream(java.io.PrintWriter stream)
                   throws java.io.IOException
Writes this object to the given stream in XML format. Usually this method is used to write the object to a file for saving it, but that is potentially not the only use.

We could supply a default implementation that knows how to write the id value. But that convenience is not chosen because it's never correct to use just this implementation of these methods, so I'd rather have a compilation fail if a derived class fails to implement this method.

The inverse of this method is a constructor that takes a org.xml.sax.Parser argument and other arguments.

Overrides:
writeToStream in class EngineObject
Parameters:
stream - PrintWriter - print stream
Throws:
java.lang.IllegalArgumentException - - input arguments illegal
java.io.IOException - - an IO error occurred in java libraries