Class BondRef

java.lang.Object
org.openscience.cdk.BondRef
All Implemented Interfaces:
Cloneable, IBond, ICDKObject, IChemObject, IElectronContainer

public class BondRef extends Object implements IBond
A bond ref, references a CDK IBond indirectly. All methods are passed through to the referenced bond. The reference can be used to override the behaviour of the base bond.
Author:
John Mayfield
  • Constructor Details

    • BondRef

      public BondRef(IBond bond)
      Create a pointer for the provided bond.
      Parameters:
      bond - the bond to reference
  • Method Details

    • deref

      public static IBond deref(IBond bond)
      Utility method to dereference an bond pointer. If the bond is not an BondRef it simply returns the input.
      Parameters:
      bond - the bond
      Returns:
      non-pointer bond
    • deref

      public IBond deref()
      Dereference the bond pointer once providing access to the base bond.
      Returns:
      the bond pointed to
    • getElectronCount

      public Integer getElectronCount()
      Returns the number of electrons in this electron container.
      Specified by:
      getElectronCount in interface IElectronContainer
      Returns:
      The number of electrons in this electron container.
      See Also:
    • setElectronCount

      public void setElectronCount(Integer count)
      Sets the number of electrons in this electron container.
      Specified by:
      setElectronCount in interface IElectronContainer
      Parameters:
      count - The number of electrons in this electron container.
      See Also:
    • atoms

      public Iterable<IAtom> atoms()
      Returns the Iterable to atoms making up this bond.
      Specified by:
      atoms in interface IBond
      Returns:
      An Iterable to atoms participating in this bond
      See Also:
    • setAtoms

      public void setAtoms(IAtom[] atoms)
      Sets the array of atoms making up this bond.
      Specified by:
      setAtoms in interface IBond
      Parameters:
      atoms - An array of atoms that forms this bond
      See Also:
    • getBegin

      public IAtom getBegin()
      Access the begin (or first) atom of the bond.
      Specified by:
      getBegin in interface IBond
      Returns:
      the begin atom
    • getEnd

      public IAtom getEnd()
      Access the end (or second) atom of the bond.
      Specified by:
      getEnd in interface IBond
      Returns:
      the end atom
    • getIndex

      public int getIndex()
      Specified by:
      getIndex in interface IBond
    • getContainer

      public IAtomContainer getContainer()
      Specified by:
      getContainer in interface IBond
    • getAtomCount

      public int getAtomCount()
      Returns the number of Atoms in this Bond.
      Specified by:
      getAtomCount in interface IBond
      Returns:
      The number of Atoms in this Bond
    • getAtom

      public IAtom getAtom(int position)
      Returns an Atom from this bond.
      Specified by:
      getAtom in interface IBond
      Parameters:
      position - The position in this bond where the atom is
      Returns:
      The atom at the specified position
      See Also:
    • getConnectedAtom

      public IAtom getConnectedAtom(IAtom atom)
      Returns the other atom in the bond, the atom is connected to the given atom. This method is only correct for two-centre bonds, for n-centre bonds the behaviour is undefined and the more correct IBond.getConnectedAtoms(IAtom) should be used.

      
       IAtom beg = bond.getBegin();
       IAtom end = bond.getEnd();
       // bond.getConnectedAtom(beg) == end
       // bond.getConnectedAtom(end) == beg
       
      Specified by:
      getConnectedAtom in interface IBond
      Parameters:
      atom - The atom the bond partner is searched of
      Returns:
      the connected atom or null if the given atom is not part of the bond
    • getOther

      public IAtom getOther(IAtom atom)
      Returns the other atom in the bond, the atom is connected to the given atom.This method is only correct for two-centre bonds, for n-centre bonds the behaviour is undefined and the more correct IBond.getConnectedAtoms(IAtom) should be used.

      
       IAtom beg = bond.getBegin();
       IAtom end = bond.getEnd();
       // bond.getOther(beg) == end
       // bond.getOther(end) == beg
       
      Specified by:
      getOther in interface IBond
      Parameters:
      atom - The atom the bond partner is searched of
      Returns:
      the connected atom or null if the given atom is not part of the bond
    • getConnectedAtoms

      public IAtom[] getConnectedAtoms(IAtom atom)
      Returns all the atoms in the bond connected to the given atom.
      Specified by:
      getConnectedAtoms in interface IBond
      Parameters:
      atom - The atoms the bond partner is searched of
      Returns:
      the connected atoms or null if the given atom is not part of the bond
    • contains

      public boolean contains(IAtom atom)
      Returns true if the given atom participates in this bond.
      Specified by:
      contains in interface IBond
      Parameters:
      atom - The atom to be tested if it participates in this bond
      Returns:
      true if the atom participates in this bond
    • setAtom

      public void setAtom(IAtom atom, int position)
      Sets an Atom in this bond.
      Specified by:
      setAtom in interface IBond
      Parameters:
      atom - The atom to be set
      position - The position in this bond where the atom is to be inserted
      See Also:
    • getOrder

      public IBond.Order getOrder()
      Returns the bond order of this bond.
      Specified by:
      getOrder in interface IBond
      Returns:
      The bond order of this bond
      See Also:
    • setOrder

      public void setOrder(IBond.Order order)
      Sets the bond order of this bond.
      Specified by:
      setOrder in interface IBond
      Parameters:
      order - The bond order to be assigned to this bond
      See Also:
    • getStereo

      public IBond.Stereo getStereo()
      Returns the stereo descriptor for this bond.
      Specified by:
      getStereo in interface IBond
      Returns:
      The stereo descriptor for this bond
      See Also:
    • setStereo

      public void setStereo(IBond.Stereo stereo)
      Sets the stereo descriptor for this bond. Note this function will also modify the bond display style.
      Specified by:
      setStereo in interface IBond
      Parameters:
      stereo - The stereo descriptor to be assigned to this bond.
      See Also:
    • getDisplay

      public IBond.Display getDisplay()
      Access the bond display style.
      Specified by:
      getDisplay in interface IBond
      Returns:
      the bond display
    • setDisplay

      public void setDisplay(IBond.Display display)
      Set the bond display style.
      Specified by:
      setDisplay in interface IBond
      Parameters:
      display - the display
    • get2DCenter

      public javax.vecmath.Point2d get2DCenter()
      Returns the geometric 2D center of the bond.
      Specified by:
      get2DCenter in interface IBond
      Returns:
      The geometric 2D center of the bond
    • get3DCenter

      public javax.vecmath.Point3d get3DCenter()
      Returns the geometric 3D center of the bond.
      Specified by:
      get3DCenter in interface IBond
      Returns:
      The geometric 3D center of the bond
    • compare

      public boolean compare(Object object)
      Compares a bond with this bond.
      Specified by:
      compare in interface IBond
      Parameters:
      object - Object of type Bond
      Returns:
      Return true, if the bond is equal to this bond
    • isConnectedTo

      public boolean isConnectedTo(IBond bond)
      Checks whether a bond is connected to another one. This can only be true if the bonds have an Atom in common.
      Specified by:
      isConnectedTo in interface IBond
      Parameters:
      bond - The bond which is checked to be connect with this one
      Returns:
      True, if the bonds share an atom, otherwise false
    • isAromatic

      public boolean isAromatic()
      Access whether this bond has been marked as aromatic. The default value is false and you must explicitly perceive aromaticity with one of the available models.
      Specified by:
      isAromatic in interface IBond
      Returns:
      aromatic status
      See Also:
    • setIsAromatic

      public void setIsAromatic(boolean arom)
      Mark this bond as being aromatic.
      Specified by:
      setIsAromatic in interface IBond
      Parameters:
      arom - aromatic status
      See Also:
    • isInRing

      public boolean isInRing()
      Access whether this bond has been flagged as in a ring. The default value is false and you must explicitly find rings first.
      Specified by:
      isInRing in interface IBond
      Returns:
      ring status
      See Also:
    • setIsInRing

      public void setIsInRing(boolean ring)
      Mark this bond as being in a ring.
      Specified by:
      setIsInRing in interface IBond
      Parameters:
      ring - ring status
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • clone

      public IBond clone() throws CloneNotSupportedException
      Returns a deep clone of this IChemObject.
      Specified by:
      clone in interface IBond
      Specified by:
      clone in interface IChemObject
      Returns:
      Object the clone of this IChemObject.
      Throws:
      CloneNotSupportedException - if the IChemObject cannot be cloned
    • toString

      public String toString()
      Description copied from interface: IChemObject
      Returns a one line description of this IChemObject.
      Specified by:
      toString in interface IChemObject
      Overrides:
      toString in class Object
      Returns:
      a String representation of this object
    • getBuilder

      public IChemObjectBuilder getBuilder()
      Returns a IChemObjectBuilder for the data classes that extend this class.
      Specified by:
      getBuilder in interface ICDKObject
      Returns:
      The IChemObjectBuilder matching this ICDKObject
    • addListener

      public void addListener(IChemObjectListener col)
      Use this to add yourself to this IChemObject as a listener. In order to do so, you must implement the ChemObjectListener Interface.
      Specified by:
      addListener in interface IChemObject
      Parameters:
      col - the ChemObjectListener
      See Also:
    • getListenerCount

      public int getListenerCount()
      Returns the number of ChemObjectListeners registered with this object.
      Specified by:
      getListenerCount in interface IChemObject
      Returns:
      the number of registered listeners.
    • removeListener

      public void removeListener(IChemObjectListener col)
      Use this to remove a ChemObjectListener from the ListenerList of this IChemObject. It will then not be notified of change in this object anymore.
      Specified by:
      removeListener in interface IChemObject
      Parameters:
      col - The ChemObjectListener to be removed
      See Also:
    • setNotification

      public void setNotification(boolean bool)
      Set a flag to use or not use notification. By default it should be set to true.
      Specified by:
      setNotification in interface IChemObject
      Parameters:
      bool - if true, then notification messages are sent.
      See Also:
    • getNotification

      public boolean getNotification()
      Returns the flag that indicates whether notification messages are sent around.
      Specified by:
      getNotification in interface IChemObject
      Returns:
      true if messages are sent.
      See Also:
    • notifyChanged

      public void notifyChanged()
      This should be triggered by an method that changes the content of an object to that the registered listeners can react to it.
      Specified by:
      notifyChanged in interface IChemObject
    • notifyChanged

      public void notifyChanged(IChemObjectChangeEvent evt)
      This should be triggered by an method that changes the content of an object to that the registered listeners can react to it. This is a version of notifyChanged() which allows to propagate a change event while preserving the original origin.
      Specified by:
      notifyChanged in interface IChemObject
      Parameters:
      evt - A ChemObjectChangeEvent pointing to the source of where the change happend
    • setProperty

      public void setProperty(Object description, Object property)
      Sets a property for a IChemObject.
      Specified by:
      setProperty in interface IChemObject
      Parameters:
      description - An object description of the property (most likely a unique string)
      property - An object with the property itself
      See Also:
    • removeProperty

      public void removeProperty(Object description)
      Removes a property for a IChemObject.
      Specified by:
      removeProperty in interface IChemObject
      Parameters:
      description - The object description of the property (most likely a unique string)
      See Also:
    • getProperty

      public <T> T getProperty(Object description)
      Returns a property for the IChemObject - the object is automatically cast to the required type. This does however mean if the wrong type is provided then a runtime ClassCastException will be thrown.
      
      
           IAtom atom = new Atom("C");
           atom.setProperty("number", 1); // set an integer property
      
           // access the property and automatically cast to an int
           Integer number = atom.getProperty("number");
      
           // if the method is in a chain or needs to be nested the type
           // can be provided
           methodAcceptingInt(atom.getProperty("number", Integer.class));
      
           // the type cannot be checked and so...
           String number = atom.getProperty("number"); // ClassCastException
      
           // if the type is provided a more meaningful error is thrown
           atom.getProperty("number", String.class); // IllegalArgumentException
      
       
      Specified by:
      getProperty in interface IChemObject
      Type Parameters:
      T - generic return type
      Parameters:
      description - An object description of the property (most likely a unique string)
      Returns:
      The object containing the property. Returns null if property is not set.
      See Also:
    • getProperty

      public <T> T getProperty(Object description, Class<T> c)
      Access a property of the given description and cast the specified class.
      
      
           IAtom atom = new Atom("C");
           atom.setProperty("number", 1); // set an integer property
      
           // access the property and automatically cast to an int
           Integer number = atom.getProperty("number");
      
           // if the method is in a chain or needs to be nested the type
           // can be provided
           methodAcceptingInt(atom.getProperty("number", Integer.class));
      
           // the type cannot be checked and so...
           String number = atom.getProperty("number"); // ClassCastException
      
           // if the type is provided a more meaningful error is thrown
           atom.getProperty("number", String.class); // IllegalArgumentException
      
       
      Specified by:
      getProperty in interface IChemObject
      Type Parameters:
      T - generic type (of provided class)
      Parameters:
      description - description of a property (normally a string)
      c - type of the value to be returned
      Returns:
      the value stored for the specified description.
      See Also:
    • getProperties

      public Map<Object,Object> getProperties()
      Returns a Map with the IChemObject's properties.
      Specified by:
      getProperties in interface IChemObject
      Returns:
      The object's properties as an Map
      See Also:
    • getID

      public String getID()
      Returns the identifier (ID) of this object.
      Specified by:
      getID in interface IChemObject
      Returns:
      a String representing the ID value
      See Also:
    • setID

      public void setID(String identifier)
      Sets the identifier (ID) of this object.
      Specified by:
      setID in interface IChemObject
      Parameters:
      identifier - a String representing the ID value
      See Also:
    • setFlag

      public void setFlag(int mask, boolean value)
      Sets the value of some flag. The flag is a mask from a given CDKConstant (e.g. CDKConstants.ISAROMATIC or CDKConstants.VISITED). The flags are intrinsic internal properties and should not be used to store custom values, please use IChemObject.setProperty(Object, Object).
      
       // set this chem object to be aromatic
       chemObject.setFlag(CDKConstants.ISAROMATIC, Boolean.TRUE);
       // ...
       // indicate we have visited this chem object
       chemObject.setFlag(CDKConstants.VISITED, Boolean.TRUE);
       
      Specified by:
      setFlag in interface IChemObject
      Parameters:
      mask - flag to set the value for
      value - value to assign to flag
      See Also:
    • getFlag

      public boolean getFlag(int mask)
      Returns the value of a given flag. The flag is a mask from a given CDKConstant (e.g. CDKConstants.ISAROMATIC).
      
       if(chemObject.getFlag(CDKConstants.ISAROMATIC)){
           // handle aromatic flag on this chem object
       }
       
      Specified by:
      getFlag in interface IChemObject
      Parameters:
      mask - flag to retrieve the value of
      Returns:
      true if the flag flag_type is set
      See Also:
    • setProperties

      public void setProperties(Map<Object,Object> properties)
      Set the properties of this object to the provided map (shallow copy). Any existing properties are removed.
      Specified by:
      setProperties in interface IChemObject
      Parameters:
      properties - map key-value pairs
    • addProperties

      public void addProperties(Map<Object,Object> properties)
      Add properties to this object, duplicate keys will replace any existing value.
      Specified by:
      addProperties in interface IChemObject
      Parameters:
      properties - a Map specifying the property values
      See Also:
    • setFlags

      public void setFlags(boolean[] newFlags)
      Sets the whole set of flags. This set will iteratively invoke IChemObject.setFlag(int, boolean) for each value in the array and use CDKConstants.FLAG_MASKS to look up the correct mask. If only a single flag is being set it is a lot faster to use IChemObject.setFlag(int, boolean).
      Specified by:
      setFlags in interface IChemObject
      Parameters:
      newFlags - the new flags to set.
      See Also:
    • getFlags

      public boolean[] getFlags()
      Returns the whole set of flags. This method will create a new array on each invocation and it is recommend you use IChemObject.getFlagValue() if you need all the flags. For individual flags please use IChemObject.getFlag(int)
      Specified by:
      getFlags in interface IChemObject
      Returns:
      the flags.
      See Also:
    • getFlagValue

      public Number getFlagValue()
      Access the internal value used to store the flags. The flags are stored on a single numeric value and are set/cleared.
      Specified by:
      getFlagValue in interface IChemObject
      Returns:
      numeric representation of the flags