svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / operator / RegExpOperator.java @ 44198
History | View | Annotate | Download (1.03 KB)
1 | 43512 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.operator; |
---|---|---|---|
2 | |||
3 | 43532 | jjdelcerro | import java.util.Objects; |
4 | import java.util.regex.Matcher; |
||
5 | import java.util.regex.Pattern; |
||
6 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Function; |
7 | import org.gvsig.expressionevaluator.Interpreter; |
||
8 | |||
9 | 43532 | jjdelcerro | public class RegExpOperator extends AbstractBinaryOperator { |
10 | 43512 | jjdelcerro | |
11 | 44139 | jjdelcerro | public static final String NAME = "~"; |
12 | |||
13 | 43532 | jjdelcerro | public RegExpOperator() {
|
14 | 44139 | jjdelcerro | super(Function.GROUP_BOOLEAN, NAME);
|
15 | 43512 | jjdelcerro | } |
16 | |||
17 | @Override
|
||
18 | 44009 | jjdelcerro | public boolean allowConstantFolding() { |
19 | return true; |
||
20 | } |
||
21 | |||
22 | @Override
|
||
23 | 43532 | jjdelcerro | public Object call(Interpreter interpreter, Object op1, Object op2) { |
24 | String re = Objects.toString(op2, ""); |
||
25 | Pattern exp = (Pattern) interpreter.getCache().get(this.getClass(), re); |
||
26 | if( exp == null ) { |
||
27 | exp = Pattern.compile(re);
|
||
28 | interpreter.getCache().put(this.getClass(), re, exp);
|
||
29 | } |
||
30 | Matcher m = exp.matcher(Objects.toString(op1,"")); |
||
31 | if( m == null ) { |
||
32 | return false; |
||
33 | 43512 | jjdelcerro | } |
34 | 43532 | jjdelcerro | return m.matches();
|
35 | 43512 | jjdelcerro | } |
36 | |||
37 | } |