Class OrganicMoleculeBuilder

  • Direct Known Subclasses:
    CyclicOrganicMoleculeBuilder, LinearOrganicMoleculeBuilder

    public abstract class OrganicMoleculeBuilder
    extends java.lang.Object
    Provides a convenient way to construct OrganicMolecule objects. You do not need to use this class.
    
       SSSS TTTTT  OOO  PPPP  !
      S       T   O   O P   P !
       SSS    T   O   O PPPP  !
          S   T   O   O P     !
      SSSS    T    OOO  P     !
     
    Do not modify this class! Changes will be overwritten during official grading.
    • Constructor Detail

      • OrganicMoleculeBuilder

        public OrganicMoleculeBuilder​(int setCoreCarbons)
        Creates an organic molecule builder.
        Parameters:
        setCoreCarbons - The number of core carbons.
    • Method Detail

      • addSubstituent

        public OrganicMoleculeBuilder addSubstituent​(int position,
                                                     OrganicMoleculeBuilder.Substituent substituent)
        Adds a substituent to the backbone at the given position.
        Parameters:
        position - The position.
        substituent - The new substituent.
        Returns:
        This builder.
      • getSubstituents

        public OrganicMoleculeBuilder.Substituent[] getSubstituents​(int position)
        Gets all present substituents at the given position.
        Parameters:
        position - The carbon in the base.
        Returns:
        An array containing the carbon's substituents.
      • getCoreCarbons

        public int getCoreCarbons()
        Gets the number of carbons in the base chain/cycle of this molecule.
        Returns:
        The number of core carbons.
      • finishBackbone

        protected abstract void finishBackbone​(BondedAtom first,
                                               BondedAtom[] firstBonds,
                                               BondedAtom last,
                                               BondedAtom[] lastBonds)
        Completes the backbone as appropriate for the type of builder.
        Parameters:
        first - The first backbone carbon.
        firstBonds - The first carbon's connected atoms.
        last - The last backbone carbon.
        lastBonds - The last carbon's connected atoms.
      • build

        public BondedAtom build()
        Constructs a molecule.
        Returns:
        An atom in the molecule.
      • freeValence

        protected abstract int freeValence​(int position)
        Gets how many bonds of the given carbon are not satisfied in the backbone.
        Parameters:
        position - The zero-based index of the carbon.
        Returns:
        How many bonds the given carbon has yet to make.