Package org.openscience.cdk
Class Association
- java.lang.Object
-
- org.openscience.cdk.Association
-
- All Implemented Interfaces:
Serializable
,Cloneable
,ICDKObject
,IChemObject
,IElectronContainer
public class Association extends Object implements IElectronContainer, Serializable, Cloneable
Base class for storing interactions like hydrogen bonds and ionic interactions. The ElectronContainer contains zero electrons by default.- See Also:
- Serialized Form
- Source code:
- main
- Belongs to CDK module:
- extra
- Keywords:
- orbital, association, bond
-
-
Field Summary
Fields Modifier and Type Field Description protected int
atomCount
protected IAtom[]
atoms
The atoms which take part in the association.protected int
electronCount
Number of electrons in the association.-
Fields inherited from interface org.openscience.cdk.interfaces.IChemObject
ALIPHATIC, AROMATIC, CONJUGATED, HYDROGEN_BOND_ACCEPTOR, HYDROGEN_BOND_DONOR, IN_RING, MAPPED, NOT_IN_RING, PLACED, REACTIVE_CENTER, SINGLE_OR_DOUBLE, TYPEABLE, VISITED
-
-
Constructor Summary
Constructors Constructor Description Association()
Constructs an empty association.Association(IAtom atom1, IAtom atom2)
Constructs an association between two Atom's.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(IChemObjectListener col)
Use this to add yourself to this IChemObject as a listener.void
addProperties(Map<Object,Object> properties)
Sets the properties of this object.void
clear(int flags)
Clear the provided flags.Object
clone()
Clones thisIChemObject
.boolean
compare(Object object)
Compares a IChemObject with this IChemObject.boolean
contains(IAtom atom)
Returns true if the given atom participates in this Association.int
flags()
Access the current value of the flags for this ChemObject.IAtom
getAtomAt(int position)
Returns an Atom from this Association.int
getAtomCount()
Returns the number of Atoms in this Association.IAtom[]
getAtoms()
Returns the array of atoms making up this Association.IChemObjectBuilder
getBuilder()
Returns aIChemObjectBuilder
for the data classes that extend this class.Integer
getElectronCount()
Returns the number of electrons in a Association.boolean
getFlag(int mask)
Returns the value of a given flag.boolean[]
getFlags()
Returns the whole set of flags.Integer
getFlagValue()
Access the internal value used to store the flags.String
getID()
Returns the identifier (ID) of this object.int
getListenerCount()
Returns the number of ChemObjectListeners registered with this object.boolean
getNotification()
Returns the flag that indicates whether notification messages are sent around.Map<Object,Object>
getProperties()
Returns a Map with the IChemObject's properties.<T> T
getProperty(Object description)
Returns a property for the IChemObject.<T> T
getProperty(Object description, Class<T> c)
Access a property of the given description and cast the specified class.boolean
is(int flags)
Test if a flag(s) are set on this ChemObject.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.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.void
removeListener(IChemObjectListener col)
Use this to remove a ChemObjectListener from the ListenerList of this IChemObject.void
removeProperty(Object description)
Removes a property for a IChemObject.void
set(int flags)
Set the provided flags.void
setAtomAt(IAtom atom, int position)
Sets an Atom in this Association.void
setAtoms(IAtom[] atoms)
Sets the array of atoms making up this Association.void
setElectronCount(Integer electronCount)
Sets the number of electrons in this electron container.void
setFlag(int mask, boolean value)
Sets the value of some flag.void
setFlags(boolean[] flagsNew)
Sets the whole set of flags.void
setID(String identifier)
Sets the identifier (ID) of this object.void
setNotification(boolean bool)
Set a flag to use or not use notification.void
setProperties(Map<Object,Object> properties)
Set the properties of this object to the provided map (shallow copy).void
setProperty(Object description, Object property)
Sets a property for a IChemObject.Object
shallowCopy()
Clones thisIChemObject
, but preserves references toObject
s.String
toString()
Returns a one line string representation of this Container.
-
-
-
Field Detail
-
electronCount
protected final int electronCount
Number of electrons in the association.- See Also:
- Constant Field Values
-
atoms
protected IAtom[] atoms
The atoms which take part in the association.
-
atomCount
protected int atomCount
-
-
Constructor Detail
-
Association
public Association(IAtom atom1, IAtom atom2)
Constructs an association between two Atom's.- Parameters:
atom1
- An atom to be associated with another atomatom2
- An atom to be associated with another atom- See Also:
Atom
-
Association
public Association()
Constructs an empty association.- See Also:
Atom
-
-
Method Detail
-
getAtoms
public IAtom[] getAtoms()
Returns the array of atoms making up this Association.- Returns:
- An array of atoms participating in this Association
- See Also:
setAtoms(org.openscience.cdk.interfaces.IAtom[])
-
setAtoms
public void setAtoms(IAtom[] atoms)
Sets the array of atoms making up this Association.- Parameters:
atoms
- An array of atoms that forms this Association- See Also:
getAtoms()
-
getAtomCount
public int getAtomCount()
Returns the number of Atoms in this Association.- Returns:
- The number of Atoms in this Association
-
getElectronCount
public Integer getElectronCount()
Returns the number of electrons in a Association.- Specified by:
getElectronCount
in interfaceIElectronContainer
- Returns:
- The number of electrons in a Association.
- See Also:
IElectronContainer.setElectronCount(java.lang.Integer)
-
getAtomAt
public IAtom getAtomAt(int position)
Returns an Atom from this Association.- Parameters:
position
- The position in this bond where the atom is- Returns:
- The atom at the specified position
- See Also:
setAtomAt(org.openscience.cdk.interfaces.IAtom, int)
-
contains
public boolean contains(IAtom atom)
Returns true if the given atom participates in this Association.- Parameters:
atom
- The atom to be tested if it participates in this Association- Returns:
- true if the atom participates in this Association
-
setAtomAt
public void setAtomAt(IAtom atom, int position)
Sets an Atom in this Association.- Parameters:
atom
- The atom to be setposition
- The position in this Association where the atom is to be inserted- See Also:
getAtomAt(int)
-
toString
public String toString()
Returns a one line string representation of this Container. This method is conform RFC #9.- Specified by:
toString
in interfaceIChemObject
- Overrides:
toString
in classObject
- Returns:
- The string representation of this Container
-
setElectronCount
public void setElectronCount(Integer electronCount)
Sets the number of electrons in this electron container.- Specified by:
setElectronCount
in interfaceIElectronContainer
- Parameters:
electronCount
- The number of electrons in this electron container.- See Also:
getElectronCount()
-
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 interfaceIChemObject
- Parameters:
col
- the ChemObjectListener- See Also:
removeListener(org.openscience.cdk.interfaces.IChemObjectListener)
-
getListenerCount
public int getListenerCount()
Returns the number of ChemObjectListeners registered with this object.- Specified by:
getListenerCount
in interfaceIChemObject
- 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 interfaceIChemObject
- Parameters:
col
- The ChemObjectListener to be removed- See Also:
addListener(org.openscience.cdk.interfaces.IChemObjectListener)
-
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 interfaceIChemObject
-
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 interfaceIChemObject
- 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 interfaceIChemObject
- Parameters:
description
- An object description of the property (most likely a unique string)property
- An object with the property itself- See Also:
getProperty(java.lang.Object)
,removeProperty(java.lang.Object)
-
removeProperty
public void removeProperty(Object description)
Removes a property for a IChemObject.- Specified by:
removeProperty
in interfaceIChemObject
- Parameters:
description
- The object description of the property (most likely a unique string)- See Also:
setProperty(java.lang.Object, java.lang.Object)
,getProperty(java.lang.Object)
-
getProperty
public <T> T getProperty(Object description)
Returns a property for the IChemObject. The value will be cast to the required return type.- Specified by:
getProperty
in interfaceIChemObject
- 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 propert is not set.
- See Also:
setProperty(java.lang.Object, java.lang.Object)
,removeProperty(java.lang.Object)
-
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 interfaceIChemObject
- 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:
IChemObject.getProperty(Object)
,IChemObject.addProperties(java.util.Map)
-
getProperties
public Map<Object,Object> getProperties()
Returns a Map with the IChemObject's properties.- Specified by:
getProperties
in interfaceIChemObject
- Returns:
- The object's properties as an Hashtable
- See Also:
addProperties(java.util.Map<java.lang.Object, java.lang.Object>)
-
clone
public Object clone() throws CloneNotSupportedException
Clones thisIChemObject
. It clones the identifier, flags, properties and pointer vectors. The ChemObjectListeners are not cloned, and neither is the content of the pointer vectors.- Specified by:
clone
in interfaceIChemObject
- Overrides:
clone
in classObject
- Returns:
- The cloned object
- Throws:
CloneNotSupportedException
- if the IChemObject cannot be cloned
-
compare
public boolean compare(Object object)
Compares a IChemObject with this IChemObject.- Parameters:
object
- Object of type AtomType- Returns:
- true if the atom types are equal
-
getID
public String getID()
Returns the identifier (ID) of this object.- Specified by:
getID
in interfaceIChemObject
- Returns:
- a String representing the ID value
- See Also:
setID(java.lang.String)
-
setID
public void setID(String identifier)
Sets the identifier (ID) of this object.- Specified by:
setID
in interfaceIChemObject
- Parameters:
identifier
- a String representing the ID value- See Also:
getID()
-
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.IChemObject.AROMATIC
orIChemObject.VISITED
). The flags are intrinsic internal properties and should not be used to store custom values, please useIChemObject.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 interfaceIChemObject
- Parameters:
mask
- flag to set the value forvalue
- value to assign to flag- See Also:
IChemObject.getFlag(int)
-
getFlag
public boolean getFlag(int mask)
Returns the value of a given flag. The flag is a mask from a given CDKConstant (e.g.IChemObject.AROMATIC
).if(chemObject.getFlag(CDKConstants.ISAROMATIC)){ // handle aromatic flag on this chem object }
- Specified by:
getFlag
in interfaceIChemObject
- Parameters:
mask
- flag to retrieve the value of- Returns:
- true if the flag
flag_type
is set - See Also:
IChemObject.setFlag(int, boolean)
-
getFlagValue
public Integer 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 interfaceIChemObject
- Returns:
- numeric representation of the flags
-
set
public void set(int flags)
Description copied from interface:IChemObject
Set the provided flags. Any on-bits in the input parameter are set on in the ChemObject.- Specified by:
set
in interfaceIChemObject
- Parameters:
flags
- the flags
-
clear
public void clear(int flags)
Description copied from interface:IChemObject
Clear the provided flags. Any on-bits in the input parameter are set on in the ChemObject.- Specified by:
clear
in interfaceIChemObject
- Parameters:
flags
- the flags
-
is
public boolean is(int flags)
Description copied from interface:IChemObject
Test if a flag(s) are set on this ChemObject. If multiple flags are provided they must all be set to return true.atom.set(IS_IN_RING); atom.is(IS_IN_RING); // false! atom.is(IS_IN_RING+IS_AROMATIC); // false! atom.set(IS_AROMATIC); atom.is(IS_IN_RING+IS_AROMATIC); // true!
- Specified by:
is
in interfaceIChemObject
- Parameters:
flags
- the flags
-
flags
public int flags()
Description copied from interface:IChemObject
Access the current value of the flags for this ChemObject.- Specified by:
flags
in interfaceIChemObject
- Returns:
- the flag value (32-bit integer)
-
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 interfaceIChemObject
- Parameters:
properties
- map key-value pairs
-
addProperties
public void addProperties(Map<Object,Object> properties)
Sets the properties of this object.- Specified by:
addProperties
in interfaceIChemObject
- Parameters:
properties
- a Hashtable specifying the property values- See Also:
getProperties()
-
setFlags
public void setFlags(boolean[] flagsNew)
Sets the whole set of flags. This set will iteratively invokeIChemObject.setFlag(int, boolean)
for each value in the array and useCDKConstants.FLAG_MASKS
to look up the correct mask. If only a single flag is being set it is a lot faster to useIChemObject.setFlag(int, boolean)
.- Specified by:
setFlags
in interfaceIChemObject
- Parameters:
flagsNew
- the new flags to set.- See Also:
IChemObject.setFlag(int, boolean)
,IChemObject.getFlags()
-
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 useIChemObject.getFlagValue()
if you need all the flags. For individual flags please useIChemObject.getFlag(int)
- Specified by:
getFlags
in interfaceIChemObject
- Returns:
- the flags.
- See Also:
IChemObject.setFlags(boolean[])
,IChemObject.getFlag(int)
,IChemObject.getFlagValue()
-
shallowCopy
public Object shallowCopy()
Clones thisIChemObject
, but preserves references toObject
s.- Returns:
- Shallow copy of this IChemObject
- See Also:
clone()
-
getBuilder
public IChemObjectBuilder getBuilder()
Description copied from interface:ICDKObject
Returns aIChemObjectBuilder
for the data classes that extend this class.- Specified by:
getBuilder
in interfaceICDKObject
- Returns:
- The
IChemObjectBuilder
matching thisICDKObject
-
setNotification
public void setNotification(boolean bool)
Description copied from interface:IChemObject
Set a flag to use or not use notification. By default it should be set to true.- Specified by:
setNotification
in interfaceIChemObject
- Parameters:
bool
- if true, then notification messages are sent.- See Also:
IChemObject.getNotification()
-
getNotification
public boolean getNotification()
Description copied from interface:IChemObject
Returns the flag that indicates whether notification messages are sent around.- Specified by:
getNotification
in interfaceIChemObject
- Returns:
- true if messages are sent.
- See Also:
IChemObject.setNotification(boolean)
-
-