You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "s.marjanovic" <sl...@gmail.com> on 2015/06/01 12:34:08 UTC

Can simple() be made to compare strings in a case insensitive way?

Hello,

Is there a way to make simple() perform string comparison in a case
insensitive way ?

The use case is described below:

.setProperty("Service", ns.xpath("/MyMessage/Service", String.class))
.choice()
  .when().simple("${property.Service} == 'myService'")

If the value of /MyMessage/Service is "myService", simple() will evaluate to
true, but if /MyMessage/Service is "myservice" it will evaluate to false.

I can think of a number of hacks for this but I'd like to hear what is the
camel recommended way to deal with a situation like this.

Thanks,
Slavisa



--
View this message in context: http://camel.465427.n5.nabble.com/Can-simple-be-made-to-compare-strings-in-a-case-insensitive-way-tp5767732.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Can simple() be made to compare strings in a case insensitive way?

Posted by krajkumar <kr...@gmail.com>.
This thread was more than a year old, but just want to share the way I
handled this issue. 

.choice() 
.when().simple("${body.filter} == null || 
${body.filter.filterBy?.*equalsIgnoreCase*('department')}”)

Since we already having a option, why we need new operator?



--
View this message in context: http://camel.465427.n5.nabble.com/Can-simple-be-made-to-compare-strings-in-a-case-insensitive-way-tp5767732p5786084.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Can simple() be made to compare strings in a case insensitive way?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I logged a ticket
https://issues.apache.org/jira/browse/CAMEL-8832

We can still consider other alternatives for the operation symbols.

On Tue, Jun 2, 2015 at 11:23 PM, Pontus Ullgren <ul...@gmail.com> wrote:
> I would rather see a new operator than changing the behaviour of ==
>
>
> On Tue, 2 Jun 2015 at 09:44 Claus Ibsen <cl...@gmail.com> wrote:
>
>> Hi
>>
>> Yeah I am not sure if end users would be surprised if we change == to
>> be case insensitive for strings?
>>
>> Or we could consider having =~ as an alternative comparison operator
>> (although =~ may not be though as insensitive operator?)
>>
>> If we have a new operator or change the default behavior it would have
>> the performance benefit to avoid the reflection method invocation that
>> a .toLowerCase() would require.
>>
>>
>> Any thoughts in the community ?
>>
>>
>>
>>
>> On Mon, Jun 1, 2015 at 7:52 PM, s.marjanovic
>> <sl...@gmail.com> wrote:
>> > Hello Andrew,
>> >
>> > I managed to find the same information as you posted in the example,
>> > although without the "?" part.
>> >
>> > Great tip about that, thanks.
>> >
>> > Regards,
>> > Slavisa
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> http://camel.465427.n5.nabble.com/Can-simple-be-made-to-compare-strings-in-a-case-insensitive-way-tp5767732p5767756.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> hawtio: http://hawt.io/
>> fabric8 <http://hawt.io/fabric8>: http://fabric8.io/
>>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Can simple() be made to compare strings in a case insensitive way?

Posted by Pontus Ullgren <ul...@gmail.com>.
I would rather see a new operator than changing the behaviour of ==


On Tue, 2 Jun 2015 at 09:44 Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Yeah I am not sure if end users would be surprised if we change == to
> be case insensitive for strings?
>
> Or we could consider having =~ as an alternative comparison operator
> (although =~ may not be though as insensitive operator?)
>
> If we have a new operator or change the default behavior it would have
> the performance benefit to avoid the reflection method invocation that
> a .toLowerCase() would require.
>
>
> Any thoughts in the community ?
>
>
>
>
> On Mon, Jun 1, 2015 at 7:52 PM, s.marjanovic
> <sl...@gmail.com> wrote:
> > Hello Andrew,
> >
> > I managed to find the same information as you posted in the example,
> > although without the "?" part.
> >
> > Great tip about that, thanks.
> >
> > Regards,
> > Slavisa
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Can-simple-be-made-to-compare-strings-in-a-case-insensitive-way-tp5767732p5767756.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8 <http://hawt.io/fabric8>: http://fabric8.io/
>

Re: Can simple() be made to compare strings in a case insensitive way?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah I am not sure if end users would be surprised if we change == to
be case insensitive for strings?

Or we could consider having =~ as an alternative comparison operator
(although =~ may not be though as insensitive operator?)

If we have a new operator or change the default behavior it would have
the performance benefit to avoid the reflection method invocation that
a .toLowerCase() would require.


Any thoughts in the community ?




On Mon, Jun 1, 2015 at 7:52 PM, s.marjanovic
<sl...@gmail.com> wrote:
> Hello Andrew,
>
> I managed to find the same information as you posted in the example,
> although without the "?" part.
>
> Great tip about that, thanks.
>
> Regards,
> Slavisa
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Can-simple-be-made-to-compare-strings-in-a-case-insensitive-way-tp5767732p5767756.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Can simple() be made to compare strings in a case insensitive way?

Posted by "s.marjanovic" <sl...@gmail.com>.
Hello Andrew,

I managed to find the same information as you posted in the example,
although without the "?" part.

Great tip about that, thanks.

Regards,
Slavisa



--
View this message in context: http://camel.465427.n5.nabble.com/Can-simple-be-made-to-compare-strings-in-a-case-insensitive-way-tp5767732p5767756.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Can simple() be made to compare strings in a case insensitive way?

Posted by Andrew Block <an...@gmail.com>.
Slavisa,

Since the value you are comparing against is a String, you can call the toLowerCase method to convert test to lowercase and compare against that.

In your example, it would be:

.when().simple(“${property.Service?.toLowerCase()} == ‘myservice’)

The ? is added to ensure the value is not null before performing actions on the object. 

- Andy

-- 
Andrew Block


On June 1, 2015 at 5:34:53 AM, s.marjanovic (slavisa.marjanovic.83@gmail.com) wrote:

Hello,  

Is there a way to make simple() perform string comparison in a case  
insensitive way ?  

The use case is described below:  

.setProperty("Service", ns.xpath("/MyMessage/Service", String.class))  
.choice()  
.when().simple("${property.Service} == 'myService'")  

If the value of /MyMessage/Service is "myService", simple() will evaluate to  
true, but if /MyMessage/Service is "myservice" it will evaluate to false.  

I can think of a number of hacks for this but I'd like to hear what is the  
camel recommended way to deal with a situation like this.  

Thanks,  
Slavisa  



--  
View this message in context: http://camel.465427.n5.nabble.com/Can-simple-be-made-to-compare-strings-in-a-case-insensitive-way-tp5767732.html  
Sent from the Camel - Users mailing list archive at Nabble.com.