Jump to content
We've recently updated our Privacy Statement, available here ×

Variable expression


daniele

Recommended Posts

Hi,

I want to count the number of row where a fields is equals ="hello". I did a new variabile (type counter) and put in a variable expression something like this:

 

$F(nameField).equals("hello")

but it doesn't work: CannotÂcastÂfromÂbooleanÂtoÂObject

 

What's the problem??

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

There was an excellent post on this just a couple of days ago, but I can't find it.

 

 

The crux of the problem is that your comparison results in a primitive boolean result but your variable is defined as an Integer object.

 

 

What you need to put in your variable's expression is something like this:

 

 

$F{ProtocolName}.compareTo("hello")==0 ? new java.lang.Integer(1) : null

 

 

If you wanted to use a Sum variable instead of a counter then your variable's expression would be

 

 

$F{ProtocolName}.compareTo("hello")==0 ? new java.lang.Integer(1) : new java.lang.Integer(0)

Link to comment
Share on other sites

You should buy the documentation, it's worth it - saved me a lot of trouble.

 

Some more info on count: Count will incriment when it reaches any non-null data, therefore you have to use a single line expression to say that if it's NOT equal to your comparison, consider it null.

 

I like using methods that return a boolean, but depending on what JRE you're using, you'll have to choose your own method. If you're returning a boolean on count simply say:

 

$F{ProtocolName}.equals("hello") ? "count me" : null

 

where count me could be literally anything.

 

On the contrary, if you want to count everything that DOES NOT meet that criteria, simply change it to:

 

$F{ProtocolName}.equals("hello") ? null : "count me"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...