public final class BondedAtom extends java.lang.Object implements java.lang.Iterable<BondedAtom>
Since references to all other atoms in the molecule can be reached through the methods of this class, it also represents the overall molecule.
One atom can be connected to another through at least one bond. For example, carbon should have 4 bonds, but may be connected to only 3 other atoms if one of the connections is a double bond.
For convenience BondedAtom implements the Iterable interface allow you to iterate through all of its neighbors using the enhanced Java for-each loop.
Constructor and Description |
---|
BondedAtom(ChemicalElement setElement,
BondedAtom[] setOtherAtoms,
int[] setBondCounts)
Creates a new atom connected to the given others.
|
Modifier and Type | Method and Description |
---|---|
java.util.List<edu.illinois.cs.cs125.spring2019.mp4.lib.BondedAtom.BondInfo> |
getBondInfo()
Return an iterable list of bond information about all neighboring atoms.
|
BondedAtom |
getConnectedAtom(int index)
Convenience method used by the test suite.
|
ChemicalElement |
getElement()
Gets what element this atom is an instance of.
|
boolean |
hasSubstituent(java.util.List<BondedAtom> backbone)
Convenience method for determining of this atom has a substituent.
|
int |
highPrioritySubstituentCount()
Return the count of high-priority substituents attached to this atom.
|
boolean |
isCarbon()
Convenience method for determining if this atom is carbon.
|
boolean |
isSubstituent(java.util.List<BondedAtom> backbone)
Convenience method for determining if this atom is a substituent.
|
java.util.Iterator<BondedAtom> |
iterator()
Return an iterator of BondedAtoms connected to this BondedAtom.
|
int |
lowPrioritySubstituentCount(java.util.List<BondedAtom> backbone)
Return the count of low-priority substituents attached to this atom.
|
java.lang.String |
nameEndGroup()
Gets the name of the end group substituent, if any, on this carbon.
|
java.lang.String |
nameSubstituent(BondedAtom substituent)
Gets the name of a substituent starting at this carbon.
|
java.lang.String |
toString()
Returns the string representation of this atom.
|
public BondedAtom(ChemicalElement setElement, BondedAtom[] setOtherAtoms, int[] setBondCounts)
setElement
- What element this atom is.setOtherAtoms
- The distinct other atoms this atom is connected to.setBondCounts
- The bond counts in each connection.public ChemicalElement getElement()
public java.util.Iterator<BondedAtom> iterator()
This is commonly used by the molecular analysis code to explore the molecule graph.
iterator
in interface java.lang.Iterable<BondedAtom>
public java.util.List<edu.illinois.cs.cs125.spring2019.mp4.lib.BondedAtom.BondInfo> getBondInfo()
Each BondInfo object includes both a reference to the neighbor and it bond count. It is frequently more convenient to use the other iterator method above that returns BondedAtoms. Only use this if you need both the BondedAtom and the bond count.
public BondedAtom getConnectedAtom(int index)
index
- index of the BondedAtom to returnpublic boolean isCarbon()
public boolean isSubstituent(java.util.List<BondedAtom> backbone)
backbone
- the backbone of this molecule to use to identify off-backbone carbonspublic boolean hasSubstituent(java.util.List<BondedAtom> backbone)
This could either mean it has an attached substituent or off-backbone carbon.
backbone
- the backbone of this molecule to use to identify off-backbone carbonspublic int highPrioritySubstituentCount()
public int lowPrioritySubstituentCount(java.util.List<BondedAtom> backbone)
backbone
- the backbone of this molecule to use to identify off-backbone carbonspublic java.lang.String nameSubstituent(BondedAtom substituent)
Assumes that there is no end group on the core/base carbon.
substituent
- the first atom of the substituentpublic java.lang.String nameEndGroup()
public java.lang.String toString()
toString
in class java.lang.Object