• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / mybatis-3 / 2604

03 Jan 2025 10:00AM UTC coverage: 87.524% (+0.3%) from 87.177%
2604

Pull #3146

github

web-flow
Merge 60c1f5fea into 8ac3920af
Pull Request #3146: Shared ambiguity instance

3633 of 4401 branches covered (82.55%)

4 of 4 new or added lines in 1 file covered. (100.0%)

254 existing lines in 22 files now uncovered.

9569 of 10933 relevant lines covered (87.52%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/src/main/java/org/apache/ibatis/scripting/xmltags/ExpressionEvaluator.java
1
/*
2
 *    Copyright 2009-2024 the original author or authors.
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
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.apache.ibatis.scripting.xmltags;
17

18
import java.lang.reflect.Array;
19
import java.math.BigDecimal;
20
import java.util.ArrayList;
21
import java.util.List;
22
import java.util.Map;
23

24
import org.apache.ibatis.builder.BuilderException;
25

26
/**
27
 * @author Clinton Begin
28
 */
29
public class ExpressionEvaluator {
1✔
30

31
  public static final ExpressionEvaluator INSTANCE = new ExpressionEvaluator();
1✔
32

33
  public boolean evaluateBoolean(String expression, Object parameterObject) {
34
    Object value = OgnlCache.getValue(expression, parameterObject);
1✔
35
    if (value instanceof Boolean) {
1✔
36
      return (Boolean) value;
1✔
37
    }
38
    if (value instanceof Number) {
1✔
39
      return new BigDecimal(String.valueOf(value)).compareTo(BigDecimal.ZERO) != 0;
1✔
40
    }
41
    return value != null;
1✔
42
  }
43

44
  /**
45
   * @deprecated Since 3.5.9, use the {@link #evaluateIterable(String, Object, boolean)}.
46
   */
47
  @Deprecated
48
  public Iterable<?> evaluateIterable(String expression, Object parameterObject) {
49
    return evaluateIterable(expression, parameterObject, false);
1✔
50
  }
51

52
  /**
53
   * @since 3.5.9
54
   */
55
  public Iterable<?> evaluateIterable(String expression, Object parameterObject, boolean nullable) {
56
    Object value = OgnlCache.getValue(expression, parameterObject);
1✔
57
    if (value == null) {
1✔
58
      if (nullable) {
1✔
59
        return null;
1✔
60
      }
61
      throw new BuilderException("The expression '" + expression + "' evaluated to a null value.");
1✔
62
    }
63
    if (value instanceof Iterable) {
1✔
64
      return (Iterable<?>) value;
1✔
65
    }
66
    if (value.getClass().isArray()) {
1✔
67
      // the array may be primitive, so Arrays.asList() may throw
68
      // a ClassCastException (issue 209). Do the work manually
69
      // Curse primitives! :) (JGB)
70
      int size = Array.getLength(value);
1✔
71
      List<Object> answer = new ArrayList<>();
1✔
72
      for (int i = 0; i < size; i++) {
1✔
73
        Object o = Array.get(value, i);
1✔
74
        answer.add(o);
1✔
75
      }
76
      return answer;
1✔
77
    }
78
    if (value instanceof Map) {
1!
79
      return ((Map) value).entrySet();
1✔
80
    }
UNCOV
81
    throw new BuilderException(
×
82
        "Error evaluating expression '" + expression + "'.  Return value (" + value + ") was not iterable.");
83
  }
84

85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc