Service Virtualization

Expand all | Collapse all

How to execute/write match script for long integer equality??

  • 1.  How to execute/write match script for long integer equality??

    Posted Jul 18, 2017 02:41 AM

    How to execute match script for long integer equality??

    eg:

    if(variable==2258974152221){
      return true;//return particular mapped response
    }
    return false;
    if(variable==22589741522287){
      return true;//return particular mapped response
    }
    return false;
    also not working with equals method for string. ?
    Thanks,
    kartik


  • 2.  Re: How to execute/write match script for long integer equality??

    Posted Sep 05, 2017 01:37 PM

    Perhaps, Java is casting the primitive value 2258974152221 in your IF/ELSE into a Long wrapper object which makes "==" an object reference comparison not a value comparison.

    Not clear to me why you cannot just treat both values as string -- assuming 'variable' in your code snippet is an input request element which is probably already a string.  For example,

    if ( "2258974152221".equals( variable.toString() ) )

       return true;

     

    If you feel as though you must use long types, is it possible to use the Long wrapper object rather than the primitive and do what amounts to a string compare. For example, 

    Long long1 = Long.valueOf( "2258974152221" );

    Long var1  = Long.valueOf( variable.toString() );

    if ( long1.toString().equals( var1.toString() ) )

       return true;