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

mybatis / ibatis-2 / 573

26 May 2025 06:21PM UTC coverage: 65.532%. Remained the same
573

push

github

web-flow
Merge pull request #284 from hazendaz/master

[java] Use diamond operators

1611 of 2820 branches covered (57.13%)

61 of 72 new or added lines in 37 files covered. (84.72%)

5082 of 7755 relevant lines covered (65.53%)

0.66 hits per line

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

54.05
/src/main/java/com/ibatis/sqlmap/engine/exchange/ListDataExchange.java
1
/*
2
 * Copyright 2004-2025 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 com.ibatis.sqlmap.engine.exchange;
17

18
import com.ibatis.common.beans.ProbeFactory;
19
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
20
import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping;
21
import com.ibatis.sqlmap.engine.mapping.result.ResultMap;
22
import com.ibatis.sqlmap.engine.mapping.result.ResultMapping;
23
import com.ibatis.sqlmap.engine.scope.StatementScope;
24

25
import java.util.ArrayList;
26
import java.util.List;
27
import java.util.Map;
28

29
/**
30
 * DataExchange implementation for List objects.
31
 */
32
public class ListDataExchange extends BaseDataExchange implements DataExchange {
33

34
  /**
35
   * Instantiates a new list data exchange.
36
   *
37
   * @param dataExchangeFactory
38
   *          the data exchange factory
39
   */
40
  protected ListDataExchange(DataExchangeFactory dataExchangeFactory) {
41
    super(dataExchangeFactory);
1✔
42
  }
1✔
43

44
  public void initialize(Map properties) {
45
  }
1✔
46

47
  public Object[] getData(StatementScope statementScope, ParameterMap parameterMap, Object parameterObject) {
48
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
1✔
49
    Object[] data = new Object[mappings.length];
1✔
50
    for (int i = 0; i < mappings.length; i++) {
1✔
51
      String propName = mappings[i].getPropertyName();
1✔
52

53
      // parse on the '.' notation and get nested properties
54
      String[] propertyArray = propName.split("\\.");
1✔
55

56
      if (propertyArray.length > 0) {
1!
57
        // iterate list of properties to discover values
58

59
        Object tempData = parameterObject;
1✔
60

61
        for (int x = 0; x < propertyArray.length; x++) {
1✔
62

63
          // is property an array reference
64
          int arrayStartIndex = propertyArray[x].indexOf('[');
1✔
65

66
          if (arrayStartIndex == -1) {
1✔
67

68
            // is a normal property
69
            tempData = ProbeFactory.getProbe().getObject(tempData, propertyArray[x]);
1✔
70

71
          } else {
72

73
            int index = Integer
1✔
74
                .parseInt(propertyArray[x].substring(arrayStartIndex + 1, propertyArray[x].length() - 1));
1✔
75
            tempData = ((List) tempData).get(index);
1✔
76

77
          }
78

79
        }
80

81
        data[i] = tempData;
1✔
82

83
      } else {
1✔
84

85
        int index = Integer.parseInt((propName.substring(propName.indexOf('[') + 1, propName.length() - 1)));
×
86
        data[i] = ((List) parameterObject).get(index);
×
87

88
      }
89

90
    }
91
    return data;
1✔
92
  }
93

94
  public Object setData(StatementScope statementScope, ResultMap resultMap, Object resultObject, Object[] values) {
95
    ResultMapping[] mappings = resultMap.getResultMappings();
×
NEW
96
    List data = new ArrayList<>();
×
97
    for (int i = 0; i < mappings.length; i++) {
×
98
      String propName = mappings[i].getPropertyName();
×
99
      int index = Integer.parseInt((propName.substring(1, propName.length() - 1)));
×
100
      data.set(index, values[i]);
×
101
    }
102
    return data;
×
103
  }
104

105
  public Object setData(StatementScope statementScope, ParameterMap parameterMap, Object parameterObject,
106
      Object[] values) {
107
    ParameterMapping[] mappings = parameterMap.getParameterMappings();
×
NEW
108
    List data = new ArrayList<>();
×
109
    for (int i = 0; i < mappings.length; i++) {
×
110
      if (mappings[i].isOutputAllowed()) {
×
111
        String propName = mappings[i].getPropertyName();
×
112
        int index = Integer.parseInt((propName.substring(1, propName.length() - 1)));
×
113
        data.set(index, values[i]);
×
114
      }
115
    }
116

117
    return data;
×
118
  }
119

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

© 2026 Coveralls, Inc