Package org.openscience.cdk
Class ChemObject
java.lang.Object
org.openscience.cdk.ChemObject
- All Implemented Interfaces:
Serializable
,Cloneable
,ICDKObject
,IChemObject
- Direct Known Subclasses:
AtomContainer
,AtomContainerSet
,ChemFile
,ChemModel
,ChemSequence
,DebugChemObject
,ElectronContainer
,Element
,Mapping
,PDBStructure
,Reaction
,ReactionSet
The base class for all chemical objects in this cdk. It provides methods for
adding listeners and for their notification of events, as well a a hash
table for administration of physical or chemical properties
- Author:
- steinbeck
- See Also:
- Source code:
- main
- Belongs to CDK module:
- data
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new IChemObject.ChemObject
(IChemObject chemObject) Constructs a new IChemObject by copying the flags, and the identifier. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Use this to add yourself to this IChemObject as a listener.void
addProperties
(Map<Object, Object> properties) Sets the properties of this object.clone()
Clones thisIChemObject
.boolean
Compares a IChemObject with this IChemObject.Returns aIChemObjectBuilder
for the data classes that extend this class.boolean
getFlag
(int mask) Returns the value of a given flag.boolean[]
getFlags()
Returns the whole set of flags.Access the internal value used to store the flags.getID()
Returns the identifier (ID) of this object.int
Returns the number of ChemObjectListeners registered with this object.boolean
Returns the flag that indicates whether notification messages are sent around.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.void
This should be triggered by an method that changes the content of an object to that the registered listeners can react to it.void
This should be triggered by an method that changes the content of an object to that the registered listeners can react to it.void
Use this to remove a ChemObjectListener from the ListenerList of this IChemObject.void
removeProperty
(Object description) Removes a property for a IChemObject.void
setFlag
(int mask, boolean value) Sets the value of some flag.void
setFlags
(boolean[] flagsNew) Sets the whole set of flags.void
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.Clones thisIChemObject
, but preserves references toObject
s.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.openscience.cdk.interfaces.IChemObject
toString
-
Constructor Details
-
ChemObject
public ChemObject()Constructs a new IChemObject. -
ChemObject
Constructs a new IChemObject by copying the flags, and the identifier. It does not copy the listeners and properties.- Parameters:
chemObject
- the object to copy
-
-
Method Details
-
addListener
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:
-
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
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:
-
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
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 happened
-
setProperty
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:
-
removeProperty
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:
-
getProperty
Returns a property for the IChemObject.- 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:
-
getProperty
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:
-
getProperties
Returns a Map with the IChemObject's properties.- Specified by:
getProperties
in interfaceIChemObject
- Returns:
- The object's properties as an Hashtable
- See Also:
-
clone
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
Compares a IChemObject with this IChemObject.- Parameters:
object
- Object of type AtomType- Returns:
- true if the atom types are equal
-
getID
Returns the identifier (ID) of this object.- Specified by:
getID
in interfaceIChemObject
- Returns:
- a String representing the ID value
- See Also:
-
setID
Sets the identifier (ID) of this object.- Specified by:
setID
in interfaceIChemObject
- 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
orCDKConstants.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:
-
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 interfaceIChemObject
- Parameters:
mask
- flag to retrieve the value of- Returns:
- true if the flag
flag_type
is set - See Also:
-
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
-
setProperties
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
Sets the properties of this object.- Specified by:
addProperties
in interfaceIChemObject
- Parameters:
properties
- a Hashtable specifying the property values- See Also:
-
setFlags
public void setFlags(boolean[] flagsNew) Sets the whole set of flags.- Specified by:
setFlags
in interfaceIChemObject
- Parameters:
flagsNew
- the new flags.- See Also:
-
getFlags
public boolean[] getFlags()Returns the whole set of flags.- Specified by:
getFlags
in interfaceIChemObject
- Returns:
- the flags.
- See Also:
-
shallowCopy
Clones thisIChemObject
, but preserves references toObject
s.- Returns:
- Shallow copy of this IChemObject
- See Also:
-
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:
-
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:
-