[
https://issues.apache.org/activemq/browse/CAMEL-401?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=41832#action_41832
]
Roman Kalukiewicz commented on CAMEL-401:
-----------------------------------------
This patch has string-contains behavior only, when expression evaluates
directly to String, while any other type is converted into collection/iterator
and has collection-contains behavior.
This is different than other such constructs when we implicitly convert things
to string (or any other required type). In this case we cannot do it, because
anything could be converted both into String (with {{toString()}}) and into
Iterator (with single element).
If we want to have string-contains functionality I would recommend to simply
rename those methods somehow, so they are different like {{stringContains()}}
and {{hasElement()}}. Then it would be clear what they do.
The patch is OK, but then we can deprecate {{contains()}} method and prefer to
use one, that explicitly defines if it tries to convert body into String or
Collection.
Honestly saying I was fooled by this name once already and I thought it is
string-contains - I had to look into the code to actually find what it does so
I agree that it is an issue ;)
My $0.02
> header().contains() could have natural specialisation for String arguments
> --------------------------------------------------------------------------
>
> Key: CAMEL-401
> URL: https://issues.apache.org/activemq/browse/CAMEL-401
> Project: Apache Camel
> Issue Type: Improvement
> Components: camel-core
> Affects Versions: 1.2.0
> Reporter: Gary Tully
> Attachments: camel-401.patch
>
>
> Filtering on a header that contains a string with a hyphen, the following
> works:
> from(file://temp).filter(header(FileComponent.HEADER_FILE_NAME).matchesRegex(".*-.*")).to("mock:result");
> but contains is more natural and should also work.
> from(file://temp).filter(header(FileComponent.HEADER_FILE_NAME).contains("-")).to("mock:result");
> It does not as contains() is focused on collections and reduces to checking
> equality on single values. A string specialisation could use string.contains.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.