~ubuntu-branches/ubuntu/trusty/cdk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/isomorphism/matchers/smarts/SMARTSOperatorAtom.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 *  $RCSfile$
 
4
 *  $Author: Sushil Ronghe $
 
5
 *  $Date: 2007-04-12  $
 
6
 *  $Revision: 6631 $
 
7
 *
 
8
 *  Copyright (C) 2002-2006  The Chemistry Development Kit (CDK) project
 
9
 *
 
10
 *  Contact: cdk-devel@lists.sourceforge.net
 
11
 *
 
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.
 
20
 *
 
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.
 
25
 *
 
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.
 
29
 *
 
30
 */
 
31
 
 
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;
 
37
 
 
38
/**
 
39
 *    THis class is special for matching the complex operator expression.
 
40
 * 
 
41
 */
 
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){
 
50
        IQAT = m_IQAT;
 
51
        OPC = m_OPC;
 
52
        
 
53
        
 
54
    }
 
55
    public SMARTSOperatorAtom(IQueryAtomContainer m_IQAT){
 
56
        IQAT = m_IQAT;
 
57
        OPC = null;
 
58
    }
 
59
    public boolean matches(IAtom atom){
 
60
           int i=0;value = false;
 
61
        if(OPC==null){
 
62
             while(i<IQAT.getAtomCount()){
 
63
                Previousatom = (IQueryAtom)IQAT.getAtom(i);
 
64
                value = Previousatom.matches(atom);
 
65
                i++;
 
66
             }
 
67
             return value;
 
68
        }
 
69
        else{
 
70
        while(i<IQAT.getAtomCount()){
 
71
           Previousatom = (IQueryAtom)IQAT.getAtom(i);i++;Nextatom = (IQueryAtom)IQAT.getAtom(i);
 
72
            value = getOperationResult(atom);    
 
73
        }
 
74
        value = getOperationResult(atom);
 
75
        return value;
 
76
        }
 
77
    }
 
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;}
 
84
                default:return false;
 
85
            }
 
86
        }
 
87
        else if(getOperatorValue(OPC.nextElement())==1)
 
88
              return value;
 
89
        else
 
90
            return value;
 
91
    }
 
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;
 
96
        else return 4;
 
97
    }
 
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()+",");
 
102
        }
 
103
        return "SMARTSOperatorAtom("+print.toString()+")";
 
104
    }
 
105
}