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 @ 43983
History | View | Annotate | Download (923 Bytes)
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 | 43532 | jjdelcerro | public RegExpOperator() {
|
12 | super(Function.GROUP_BOOLEAN, "~"); |
||
13 | 43512 | jjdelcerro | } |
14 | |||
15 | @Override
|
||
16 | 43532 | jjdelcerro | public Object call(Interpreter interpreter, Object op1, Object op2) { |
17 | String re = Objects.toString(op2, ""); |
||
18 | Pattern exp = (Pattern) interpreter.getCache().get(this.getClass(), re); |
||
19 | if( exp == null ) { |
||
20 | exp = Pattern.compile(re);
|
||
21 | interpreter.getCache().put(this.getClass(), re, exp);
|
||
22 | } |
||
23 | Matcher m = exp.matcher(Objects.toString(op1,"")); |
||
24 | if( m == null ) { |
||
25 | return false; |
||
26 | 43512 | jjdelcerro | } |
27 | 43532 | jjdelcerro | return m.matches();
|
28 | 43512 | jjdelcerro | } |
29 | |||
30 | } |