• Post Reply Bookmark Topic Watch Topic
  • New Topic

RowFilters and doubles as Strings not working as expected.  RSS feed

 
Jason Richard
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
e
I'm working with RowFilters and trying to get the following to happen.

One of my columns might be doubles. there might be several values like

Column FOO
-------------
392.444444
433.33333
123.333354
2.33331


and I have a separate table that I use to filter these columns

but I'm looking for pattern matching so if the first character that is entered is 3 my table is filtered down 4 my table is filtered down to

Column FOO
-------------
392.444444
433.33333
123.333354

This all works fantastic

however I seem to be having a problem with the .

for example if my filter is 3. my filter seems to be using the . as a "there is a character there"

so the above filtering wont' change. but if I add a 3.2 my results would be

Column FOO
-------------
392.444444

String value = "3.2"
filters.add(RowFilter.regexFilter("(?i)" + value, k));

what I would prefer is that the . be the decimal place, so if I type 3. my filter would be

Column FOO
-------------
433.33333
123.333354

and If I typed 3.2 as my filter, then I would have no results.


Any help would be appreciated.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dot is a metacharacter in regex and matches *any* character. To match a literal dot, you need to escape it. In a String literal, that would mean prefacing it with a double backslash; in a String input, a single backslash would suffice. Or you could process the entire input, prefacing it and suffixing it with the regex quote characters "\\Q" and "\\E"
 
Jason Richard
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:The dot is a metacharacter in regex and matches *any* character. To match a literal dot, you need to escape it. In a String literal, that would mean prefacing it with a double backslash; in a String input, a single backslash would suffice. Or you could process the entire input, prefacing it and suffixing it with the regex quote characters "\\Q" and "\\E"


Brilliant!


except I'm still confused. I understand completely what you are saying, but I'm having a hard time making it work.

I've tried String value = "3\\.2"
as well as String value = "\\Q3.2\\E"

as well as some other things, but it's still working the same
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

Include several inputs (possibly as an array or List) and the expected and actual outputs.
 
Jason Richard
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, sorry i was trying to keep it pretty general, but mostly because my code is in several different places.

Mostly I'm looking at the following




The filtering model works great outside of the "."
 
Jason Richard
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
Include several inputs (possibly as an array or List) and the expected and actual outputs.



So basically if value was 3.2

and my values were
1233.2
332.42
2443.432
321.123
321123123.1
3.2

I'd only want the 1233.2 and the 3.2 back or the same if I had just typed 3.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!