4
* $Author: Sushil Ronghe $
8
* Copyright (C) 2002-2006 The Chemistry Development Kit (CDK) project
10
* Contact: cdk-devel@lists.sourceforge.net
12
* This program is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU Lesser General Public License
14
* as published by the Free Software Foundation; either version 2.1
15
* of the License, or (at your option) any later version.
16
* All I ask is that proper credit is given for my work, which includes
17
* - but is not limited to - adding the above copyright notice to the beginning
18
* of your source code files, and to any copyright notice that you may distribute
19
* with programs based on this work.
21
* This program is distributed in the hope that it will be useful,
22
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
* GNU Lesser General Public License for more details.
26
* You should have received a copy of the GNU Lesser General Public License
27
* along with this program; if not, write to the Free Software
28
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
32
package org.openscience.cdk.isomorphism.matchers.smarts;
33
import java.util.logging.Logger;
34
import org.openscience.cdk.isomorphism.matchers.*;
35
import org.openscience.cdk.interfaces.IAtom;
36
import org.openscience.cdk.tools.LoggingTool;
39
* THis class is special for matching the complex operator expression.
42
public class SMARTSOperatorAtom extends SMARTSAtom{
43
private IQueryAtomContainer IQAT;
44
private OperatorContainer OPC;
45
private IQueryAtom Previousatom;
46
private IQueryAtom Nextatom;
47
private boolean value;
48
/** Creates a new instance of SMARTSOperatorAtom */
49
public SMARTSOperatorAtom(IQueryAtomContainer m_IQAT,OperatorContainer m_OPC){
55
public SMARTSOperatorAtom(IQueryAtomContainer m_IQAT){
59
public boolean matches(IAtom atom){
60
int i=0;value = false;
62
while(i<IQAT.getAtomCount()){
63
Previousatom = (IQueryAtom)IQAT.getAtom(i);
64
value = Previousatom.matches(atom);
70
while(i<IQAT.getAtomCount()){
71
Previousatom = (IQueryAtom)IQAT.getAtom(i);i++;Nextatom = (IQueryAtom)IQAT.getAtom(i);
72
value = getOperationResult(atom);
74
value = getOperationResult(atom);
78
private boolean getOperationResult(IAtom atom){
79
if(Previousatom!=null && Nextatom!=null && OPC.hasMoreElements()){
80
switch(getOperatorValue(OPC.nextElement())){
81
case 1:{if (Previousatom.matches(atom)||Nextatom.matches(atom)) return true;}
82
case 2:{if (Previousatom.matches(atom)&& Nextatom.matches(atom)) return true;}
83
case 3:{if (Previousatom.matches(atom)&& Nextatom.matches(atom)) return true;}
87
else if(getOperatorValue(OPC.nextElement())==1)
92
private int getOperatorValue(String str){
93
if(str.equals(","))return 1;
94
else if(str.equals("&"))return 2;
95
else if(str.equals(";")) return 3;
98
public String toString(){
99
StringBuffer print = new StringBuffer();
100
for(int j=0;j<IQAT.getAtomCount();j++){
101
print.append(IQAT.getAtom(j).toString()+",");
103
return "SMARTSOperatorAtom("+print.toString()+")";