3
* $Date: 2006-03-29 10:27:08 +0200 (Wed, 29 Mar 2006) $
6
* Copyright (C) 2006-2007 The Chemistry Development Kit (CDK) project
8
* Contact: cdk-devel@lists.sourceforge.net
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public License
12
* as published by the Free Software Foundation; either version 2.1
13
* of the License, or (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
package org.openscience.cdk.qsar;
26
import java.util.HashMap;
29
import org.openscience.cdk.interfaces.IAtom;
30
import org.openscience.cdk.interfaces.IAtomContainer;
31
import org.openscience.cdk.qsar.result.IDescriptorResult;
34
* Abstract atomic descriptor class with helper functions for descriptors
35
* that require the whole molecule to calculate the descriptor values,
36
* which in turn need to be cached for all atoms, so that they can be
37
* retrieved one by one.
41
public abstract class AbstractAtomicDescriptor implements IAtomicDescriptor {
43
private static final String PREVIOUS_ATOMCONTAINER = "previousAtomContainer";
45
private Map cachedDescriptorValues = null;
48
* Returns true if the cached IDescriptorResult's are for the given IAtomContainer.
51
* @return false, if the cache is for a different IAtomContainer
53
public boolean isCachedAtomContainer(IAtomContainer container) {
54
if (cachedDescriptorValues == null) return false;
55
return (cachedDescriptorValues.get(PREVIOUS_ATOMCONTAINER) == container);
59
* Returns the cached DescriptorValue for the given IAtom.
61
* @param atom the IAtom for which the DescriptorValue is requested
62
* @return null, if no DescriptorValue was cached for the given IAtom
64
public IDescriptorResult getCachedDescriptorValue(IAtom atom) {
65
if (cachedDescriptorValues == null) return null;
66
return (IDescriptorResult)cachedDescriptorValues.get(atom);
70
* Caches a DescriptorValue for a given IAtom. This method may only
71
* be called after setNewContainer() is called.
73
* @param atom IAtom to cache the value for
74
* @param value DescriptorValue for the given IAtom
76
public void cacheDescriptorValue(IAtom atom, IAtomContainer container, IDescriptorResult value) {
77
if (cachedDescriptorValues == null) {
78
cachedDescriptorValues = new HashMap();
79
cachedDescriptorValues.put(PREVIOUS_ATOMCONTAINER, container);
80
} else if (cachedDescriptorValues.get(PREVIOUS_ATOMCONTAINER) != container) {
81
cachedDescriptorValues.clear();
82
cachedDescriptorValues.put(PREVIOUS_ATOMCONTAINER, container);
84
cachedDescriptorValues.put(atom, value);