Clover coverage report - Replica - 1.0-Alpha
Coverage timestamp: Dom Fev 1 2004 17:00:58 WET
file stats: LOC: 161   Methods: 5
NCLOC: 138   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
RelopCondition.java 0% 0% 0% 0%
coverage
 1   
 package mobisnap.mobile_trx;
 2   
 
 3   
 public class RelopCondition
 4   
     extends ColumnCondition
 5   
     implements java.io.Serializable
 6   
 {
 7   
     public static final int OP_EQUAL = 1;
 8   
     public static final int OP_NOTEQUAL = 2;
 9   
     public static final int OP_CARDINAL = 3;
 10   
     public static final int OP_MOREORLESS = 4;
 11   
     public static final int OP_MORE = 5;
 12   
     public static final int OP_MOREEQUAL = 6;
 13   
     public static final int OP_LESS = 7;
 14   
     public static final int OP_LESSEQUAL = 8;
 15   
     
 16   
     String columnName;
 17   
     int relop;
 18   
     Object value;
 19   
 
 20  0
     public RelopCondition( String columnName, int relop, Object value) {
 21  0
         this.columnName = columnName.trim();
 22  0
         this.relop = relop;
 23  0
         this.value = value;
 24   
     }
 25   
     
 26   
     /**
 27   
      * Returns true if this condition is the same that is represented by the
 28   
      * given node
 29   
      */
 30  0
     public boolean sameCondition( SimpleNode node) {
 31  0
         if( node instanceof ASTSQLRelationalExpression) {
 32  0
             ASTSQLRelationalExpression expr = (ASTSQLRelationalExpression)node;
 33  0
             if( expr.firstprior || expr.secondprior || expr.type != 1 ||
 34   
                     expr.secondquery)
 35  0
                 return false;
 36  0
             if ( ((ASTRelop)expr.v1).type != ASTRelop.OP_EQUAL )
 37  0
                  return belongsTo( new RelopCondition( expr.first.toString( mobisnap.MobisnapConstants.MSQL_SERVER).trim() , ((ASTRelop)expr.v1).type, ((SimpleNode)expr.v2).toString( mobisnap.MobisnapConstants.MSQL_SERVER). trim() ));
 38   
     
 39  0
             Object obj1 = null;
 40  0
             Object obj2 = null;
 41   
             
 42  0
             try {
 43  0
                 obj1 = expr.first.value( mobisnap.MobisnapConstants.MSQL_SERVER, false);
 44   
             } catch( Exception e) {
 45  0
                 obj1 = expr.first.toString( mobisnap.MobisnapConstants.MSQL_SERVER). trim();
 46   
             }
 47  0
             try {
 48  0
                 obj2 = ((SimpleNode)expr.v2).value( mobisnap.MobisnapConstants.MSQL_SERVER, false);
 49   
             } catch( Exception e) {
 50  0
                 obj2 = ((SimpleNode)expr.v2).toString( mobisnap.MobisnapConstants.MSQL_SERVER). trim();
 51   
             }
 52  0
             if( obj1 instanceof String && obj2 instanceof String) {
 53  0
                 if( columnName.equals( ((String)obj1).trim()))
 54  0
                    obj1 = obj2;
 55  0
                 else if( ! columnName.equals( ((String)obj2).trim()))
 56  0
                     return false;
 57  0
             } else if( obj1 instanceof String) {
 58  0
                 if( columnName.equals( ((String)obj1).trim()))
 59  0
                    obj1 = obj2;
 60   
                 else
 61  0
                     return false;
 62  0
             } else if( obj2 instanceof String) {
 63  0
                 if( ! columnName.equals( ((String)obj2).trim()))
 64  0
                     return false;
 65   
             }
 66   
             
 67  0
             try {
 68  0
                 Object obj = MSQLTypeUtil.equal( obj1, value);
 69  0
                 if( obj instanceof Boolean) {
 70  0
                     return ((Boolean)obj).booleanValue();
 71   
                 }
 72   
             } catch( Exception e) {
 73  0
                 return false;
 74   
             }
 75  0
             return false;
 76   
         } else
 77  0
             return false;
 78   
     }
 79   
 
 80   
     /**
 81   
      * Returns true if this condition intersected with the given node equals 
 82   
      * the given condition, resulting int the fact that the given node "belongs" to this condition
 83   
      */
 84  0
     public boolean belongsTo( RelopCondition cond) {
 85   
                 
 86  0
             if (!cond.columnName.equals(columnName))
 87  0
                 return false;
 88   
             
 89  0
             if ( cond.relop == OP_EQUAL && relop == OP_EQUAL) {
 90  0
                 try {
 91  0
                     Object obj = MSQLTypeUtil.equal( cond.value, value);
 92  0
                     if( obj instanceof Boolean) {
 93  0
                         return ((Boolean)obj).booleanValue();
 94   
                     }
 95   
                 } catch( Exception e) {
 96  0
                     return false;
 97   
                 }
 98   
             }
 99   
             
 100  0
             if ( ( cond.relop == OP_MORE || cond.relop == OP_MOREEQUAL ) && ( relop == OP_MORE || relop == OP_MOREEQUAL || relop == OP_EQUAL) ) {
 101  0
                 try {
 102  0
                     Object obj = MSQLTypeUtil.moreEqual( value, cond.value);
 103  0
                     if( obj instanceof Boolean) {
 104  0
                         return ((Boolean)obj).booleanValue();
 105   
                     }
 106   
                 } catch( Exception e) {
 107  0
                     return false;
 108   
                 }
 109   
             }
 110   
             
 111  0
             if ( ( cond.relop == OP_LESS || cond.relop == OP_LESSEQUAL ) && ( relop == OP_LESS || relop == OP_LESSEQUAL || relop == OP_EQUAL) ) {
 112  0
                 try {
 113  0
                     Object obj = MSQLTypeUtil.lessEqual( value, cond.value);
 114  0
                     if( obj instanceof Boolean) {
 115  0
                         return ((Boolean)obj).booleanValue();
 116   
                     }
 117   
                 } catch( Exception e) {
 118  0
                     return false;
 119   
                 }
 120   
             }
 121  0
             return false;
 122   
     }
 123   
     
 124  0
     public void sourceCode( StringBuffer buffer) {
 125  0
         buffer.append( columnName);
 126  0
         switch( relop) {
 127   
         case OP_EQUAL:
 128  0
             buffer.append( " = ");
 129  0
             break;
 130   
         case OP_NOTEQUAL:
 131  0
             buffer.append( " != ");
 132  0
             break;
 133   
         case OP_CARDINAL:
 134  0
             buffer.append( " # ");
 135  0
             break;
 136   
         case OP_MOREORLESS:
 137  0
             buffer.append( " <> ");
 138  0
             break;
 139   
         case OP_MORE:
 140  0
             buffer.append( " > ");
 141  0
             break;
 142   
         case OP_MOREEQUAL:
 143  0
             buffer.append( " >= ");
 144  0
             break;
 145   
         case OP_LESS:
 146  0
             buffer.append( " < ");
 147  0
             break;
 148   
         case OP_LESSEQUAL:
 149  0
             buffer.append( " <= ");
 150  0
             break;
 151   
         }
 152  0
         buffer.append( MSQLTypeUtil.value2String( value));
 153   
     }
 154   
     
 155  0
     public String toString() {
 156  0
         StringBuffer buffer = new StringBuffer();
 157  0
         sourceCode( buffer);
 158  0
         return buffer.toString();
 159   
     }
 160   
 }
 161