de.pewpewproject.lasertag.common.util.StringUtil   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A stringEndsWithList(String,String[]) 0 8 3
A splitAtNthChar(String,char,int) 0 12 3
1
package de.pewpewproject.lasertag.common.util;
2
3
/**
4
 * Utility class for string operations
5
 *
6
 * @author Étienne Muser
7
 */
8
public class StringUtil {
9
    public static boolean stringEndsWithList(String path, String[] endings) {
10
        for (var ending : endings) {
11
            if (path.endsWith(ending)) {
12
                return true;
13
            }
14
        }
15
16
        return false;
17
    }
18
19
    public static String[] splitAtNthChar(String string, char character, int n) {
20
        var idx = -1;
21
22
        for(int i = 0; i < n; i++) {
23
            if (idx + 1 >= string.length()) {
24
                return new String[] { string, "" };
25
            }
26
27
            idx = string.indexOf(character, idx + 1);
28
        }
29
30
        return new String[] {string.substring(0, idx), string.substring(idx + 1)};
31
    }
32
}
33