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

mybatis / generator / 1602

26 Feb 2025 05:58PM UTC coverage: 88.328% (-0.01%) from 88.339%
1602

push

github

web-flow
Merge pull request #1297 from jeffgbutler/java-17

Code Cleanup after Java 17 Update

2518 of 3412 branches covered (73.8%)

163 of 180 new or added lines in 53 files covered. (90.56%)

12 existing lines in 5 files now uncovered.

11192 of 12671 relevant lines covered (88.33%)

0.88 hits per line

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

73.91
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/internal/util/StringUtility.java
1
/*
2
 *    Copyright 2006-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 org.mybatis.generator.internal.util;
17

18
import java.util.HashSet;
19
import java.util.Set;
20
import java.util.StringTokenizer;
21

22
public class StringUtility {
23

24
    /**
25
     * Utility class. No instances allowed
26
     */
27
    private StringUtility() {
28
        super();
29
    }
30

31
    public static boolean stringHasValue(String s) {
32
        return s != null && !s.isEmpty();
1✔
33
    }
34

35
    public static String composeFullyQualifiedTableName(String catalog,
36
            String schema, String tableName, char separator) {
37
        StringBuilder sb = new StringBuilder();
1✔
38

39
        if (stringHasValue(catalog)) {
1✔
40
            sb.append(catalog);
1✔
41
            sb.append(separator);
1✔
42
        }
43

44
        if (stringHasValue(schema)) {
1✔
45
            sb.append(schema);
1✔
46
            sb.append(separator);
1✔
47
        } else {
48
            if (!sb.isEmpty()) {
1✔
49
                sb.append(separator);
1✔
50
            }
51
        }
52

53
        sb.append(tableName);
1✔
54

55
        return sb.toString();
1✔
56
    }
57

58
    public static boolean stringContainsSpace(String s) {
59
        return s != null && s.indexOf(' ') != -1;
1✔
60
    }
61

62
    public static String escapeStringForJava(String s) {
63
        StringTokenizer st = new StringTokenizer(s, "\"", true); //$NON-NLS-1$
1✔
64
        StringBuilder sb = new StringBuilder();
1✔
65
        while (st.hasMoreTokens()) {
1✔
66
            String token = st.nextToken();
1✔
67
            if ("\"".equals(token)) { //$NON-NLS-1$
1✔
68
                sb.append("\\\""); //$NON-NLS-1$
1✔
69
            } else {
70
                sb.append(token);
1✔
71
            }
72
        }
1✔
73

74
        return sb.toString();
1✔
75
    }
76

77
    public static String escapeStringForKotlin(String s) {
78
        StringTokenizer st = new StringTokenizer(s, "\"$", true); //$NON-NLS-1$
1✔
79
        StringBuilder sb = new StringBuilder();
1✔
80
        while (st.hasMoreTokens()) {
1✔
81
            String token = st.nextToken();
1✔
82
            if ("\"".equals(token)) { //$NON-NLS-1$
1✔
83
                sb.append("\\\""); //$NON-NLS-1$
1✔
84
            } else if ("$".equals(token)) { //$NON-NLS-1$
1✔
85
                sb.append("\\$"); //$NON-NLS-1$
1✔
86
            } else {
87
                sb.append(token);
1✔
88
            }
89
        }
1✔
90

91
        return sb.toString();
1✔
92
    }
93

94
    public static boolean isTrue(String s) {
95
        return "true".equalsIgnoreCase(s); //$NON-NLS-1$
1✔
96
    }
97

98
    public static boolean stringContainsSQLWildcard(String s) {
99
        if (s == null) {
×
100
            return false;
×
101
        }
102

103
        return s.indexOf('%') != -1 || s.indexOf('_') != -1;
×
104
    }
105

106
    /**
107
     * Given an input string, tokenize on the commas and trim all token. Returns an empty set if the input string is
108
     * null.
109
     *
110
     * @param in
111
     *            strong to tokenize.
112
     *
113
     * @return Set of tokens
114
     */
115
    public static Set<String> tokenize(String in) {
116
        Set<String> answer = new HashSet<>();
×
117
        if (StringUtility.stringHasValue(in)) {
×
118
            StringTokenizer st = new StringTokenizer(in, ","); //$NON-NLS-1$
×
119
            while (st.hasMoreTokens()) {
×
120
                String s = st.nextToken().trim();
×
NEW
121
                if (!s.isEmpty()) {
×
122
                    answer.add(s);
×
123
                }
124
            }
×
125
        }
126
        return answer;
×
127
    }
128

129
}
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

© 2026 Coveralls, Inc