01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.query.algebra;
07:
08: /**
09: * Compares the string representation of a value expression to a pattern.
10: */
11: public class Like extends UnaryValueOperator {
12:
13: /*-----------*
14: * Variables *
15: *-----------*/
16:
17: private String pattern;
18:
19: private boolean caseSensitive;
20:
21: /**
22: * Operational pattern, equal to pattern but converted to lower case when not
23: * case sensitive.
24: */
25: private String opPattern;
26:
27: /*--------------*
28: * Constructors *
29: *--------------*/
30:
31: public Like() {
32: }
33:
34: public Like(ValueExpr expr, String pattern, boolean caseSensitive) {
35: super (expr);
36: setPattern(pattern, caseSensitive);
37: }
38:
39: /*---------*
40: * Methods *
41: *---------*/
42:
43: public void setPattern(String pattern, boolean caseSensitive) {
44: assert pattern != null : "pattern must not be null";
45: this .pattern = pattern;
46: this .caseSensitive = caseSensitive;
47: opPattern = caseSensitive ? pattern : pattern.toLowerCase();
48: }
49:
50: public String getPattern() {
51: return pattern;
52: }
53:
54: public boolean isCaseSensitive() {
55: return caseSensitive;
56: }
57:
58: public String getOpPattern() {
59: return opPattern;
60: }
61:
62: public <X extends Exception> void visit(QueryModelVisitor<X> visitor)
63: throws X {
64: visitor.meet(this );
65: }
66:
67: @Override
68: public String getSignature() {
69: StringBuilder sb = new StringBuilder(128);
70:
71: sb.append(super .getSignature());
72: sb.append(" \"");
73: sb.append(pattern);
74: sb.append("\"");
75:
76: if (caseSensitive) {
77: sb.append(" IGNORE CASE");
78: }
79:
80: return sb.toString();
81: }
82:
83: @Override
84: public Like clone() {
85: return (Like) super.clone();
86: }
87: }
|