1 /***
2 * Copyright 2003, 2004, 2005. CodeStreet LLC.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15 package com.codestreet.selector.parser;
16
17 import java.util.Iterator;
18 import java.util.Map;
19 import java.util.Set;
20
21 /***
22 * Class to represent <tt>set</tt> membership operator. Immutable.
23 *
24 * @author Jawaid Hakim.
25 */
26 class OpIN implements IExpressionString
27 {
28 /***
29 * Ctor.
30 *
31 * @param lhs
32 * Data to check for.
33 * @param rhs
34 * Membership set.
35 */
36 public OpIN(final IExpression lhs, final Set rhs)
37 {
38 lhs_ = lhs;
39 rhs_ = rhs;
40 }
41
42 public Object eval(final Map identifiers)
43 {
44 Object oLhs = lhs_.eval(identifiers);
45 if (!(oLhs instanceof String))
46 return Result.RESULT_UNKNOWN;
47
48 return (rhs_.contains(oLhs)) ? Result.RESULT_TRUE : Result.RESULT_FALSE;
49 }
50
51 public Object eval(final IValueProvider provider, final Object corr)
52 {
53 Object oLhs = lhs_.eval(provider, corr);
54 if (!(oLhs instanceof String))
55 return Result.RESULT_UNKNOWN;
56
57 return (rhs_.contains(oLhs)) ? Result.RESULT_TRUE : Result.RESULT_FALSE;
58 }
59
60 public String toString()
61 {
62 StringBuffer buf = new StringBuffer(lhs_.toString());
63 buf.append(" IN (");
64 boolean first = true;
65 for (Iterator iter = rhs_.iterator(); iter.hasNext();)
66 {
67 if (!first)
68 buf.append(',');
69 buf.append('\'').append(iter.next()).append('\'');
70 first = false;
71 }
72 buf.append(')');
73 return buf.toString();
74 }
75
76 private final IExpression lhs_;
77
78 private final Set rhs_;
79 }
This page was automatically generated by Maven