| 1 | package fr.sii.ogham.core.util; | |
| 2 | ||
| 3 | /** | |
| 4 | * Helper class for string manipulation: | |
| 5 | * <ul> | |
| 6 | * <li>Join an array or list into a string with a delimiter</li> | |
| 7 | * </ul> | |
| 8 | * <p> | |
| 9 | * This work can be done by several libraries. The aim of this class is to be | |
| 10 | * able to change the implementation easily to use another library for example. | |
| 11 | * </p> | |
| 12 | * <p> | |
| 13 | * For example, we could read which library is available in the classpath and | |
| 14 | * use this library instead of forcing users to include Apache Commons Lang | |
| 15 | * library. | |
| 16 | * </p> | |
| 17 | * | |
| 18 | * @author Aurélien Baudet | |
| 19 | * | |
| 20 | */ | |
| 21 | public final class StringUtils { | |
| 22 | ||
| 23 | /** | |
| 24 | * <p> | |
| 25 | * Joins the elements of the provided array into a single String containing | |
| 26 | * the provided list of elements. | |
| 27 | * </p> | |
| 28 | * <p> | |
| 29 | * No delimiter is added before or after the list. A null separator is the | |
| 30 | * same as an empty String (""). Null objects or empty strings within the | |
| 31 | * array are represented by empty strings. | |
| 32 | * </p> | |
| 33 | * | |
| 34 | * <pre> | |
| 35 | * StringUtils.join(null, *) = null | |
| 36 | * StringUtils.join([], *) = "" | |
| 37 | * StringUtils.join([null], *) = "" | |
| 38 | * StringUtils.join(["a", "b", "c"], "--") = "a--b--c" | |
| 39 | * StringUtils.join(["a", "b", "c"], null) = "abc" | |
| 40 | * StringUtils.join(["a", "b", "c"], "") = "abc" | |
| 41 | * StringUtils.join([null, "", "a"], ',') = ",,a" | |
| 42 | * </pre> | |
| 43 | * | |
| 44 | * | |
| 45 | * @param array | |
| 46 | * the array of values to join together, may be null | |
| 47 | * @param separator | |
| 48 | * the separator character to use, null treated as "" | |
| 49 | * @return the joined String, null if null array input | |
| 50 | */ | |
| 51 | public static String join(Object[] array, String separator) { | |
| 52 |
1
1. join : replaced return value with "" for fr/sii/ogham/core/util/StringUtils::join → NO_COVERAGE |
return org.apache.commons.lang3.StringUtils.join(array, separator); |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * <p> | |
| 57 | * Joins the elements of the provided Iterable into a single String | |
| 58 | * containing the provided elements. | |
| 59 | * </p> | |
| 60 | * <p> | |
| 61 | * No delimiter is added before or after the list. A null separator is the | |
| 62 | * same as an empty String (""). | |
| 63 | * </p> | |
| 64 | * <p> | |
| 65 | * See the examples here: {@link #join(Object[], String)}. | |
| 66 | * </p> | |
| 67 | * | |
| 68 | * @param iterable | |
| 69 | * the Iterable providing the values to join together, may be | |
| 70 | * null | |
| 71 | * @param separator | |
| 72 | * the separator character to use, null treated as "" | |
| 73 | * @return the joined String, null if null iterator input | |
| 74 | */ | |
| 75 | public static String join(Iterable<?> iterable, String separator) { | |
| 76 |
4
1. join : replaced return value with "" for fr/sii/ogham/core/util/StringUtils::join → NO_COVERAGE 2. join : replaced return value with "" for fr/sii/ogham/core/util/StringUtils::join → SURVIVED 3. join : replaced return value with "" for fr/sii/ogham/core/util/StringUtils::join → TIMED_OUT 4. join : replaced return value with "" for fr/sii/ogham/core/util/StringUtils::join → KILLED |
return org.apache.commons.lang3.StringUtils.join(iterable, separator); |
| 77 | } | |
| 78 | ||
| 79 | /** | |
| 80 | * <p> | |
| 81 | * Left pad a String with a specified character. | |
| 82 | * </p> | |
| 83 | * | |
| 84 | * <p> | |
| 85 | * Pad to a size of {@code size}. | |
| 86 | * </p> | |
| 87 | * | |
| 88 | * <pre> | |
| 89 | * StringUtils.leftPad(null, *, *) = null | |
| 90 | * StringUtils.leftPad("", 3, 'z') = "zzz" | |
| 91 | * StringUtils.leftPad("bat", 3, 'z') = "bat" | |
| 92 | * StringUtils.leftPad("bat", 5, 'z') = "zzbat" | |
| 93 | * StringUtils.leftPad("bat", 1, 'z') = "bat" | |
| 94 | * StringUtils.leftPad("bat", -1, 'z') = "bat" | |
| 95 | * </pre> | |
| 96 | * | |
| 97 | * @param str | |
| 98 | * the String to pad out, may be null | |
| 99 | * @param size | |
| 100 | * the size to pad to | |
| 101 | * @param padChar | |
| 102 | * the character to pad with | |
| 103 | * @return left padded String or original String if no padding is necessary, | |
| 104 | * {@code null} if null String input | |
| 105 | */ | |
| 106 | public static String leftPad(String str, int size, char padChar) { | |
| 107 |
2
1. leftPad : replaced return value with "" for fr/sii/ogham/core/util/StringUtils::leftPad → NO_COVERAGE 2. leftPad : replaced return value with "" for fr/sii/ogham/core/util/StringUtils::leftPad → KILLED |
return org.apache.commons.lang3.StringUtils.leftPad(str, size, padChar); |
| 108 | } | |
| 109 | ||
| 110 | /** | |
| 111 | * <p> | |
| 112 | * Capitalizes a String changing the first character to title case. No other | |
| 113 | * characters are changed. | |
| 114 | * </p> | |
| 115 | * | |
| 116 | * <p> | |
| 117 | * A {@code null} input String returns {@code null}. | |
| 118 | * </p> | |
| 119 | * | |
| 120 | * <pre> | |
| 121 | * StringUtils.capitalize(null) = null | |
| 122 | * StringUtils.capitalize("") = "" | |
| 123 | * StringUtils.capitalize("cat") = "Cat" | |
| 124 | * StringUtils.capitalize("cAt") = "CAt" | |
| 125 | * StringUtils.capitalize("'cat'") = "'cat'" | |
| 126 | * </pre> | |
| 127 | * | |
| 128 | * @param str | |
| 129 | * the String to capitalize, may be null | |
| 130 | * @return the capitalized String, {@code null} if null String input | |
| 131 | */ | |
| 132 | public static String capitalize(String str) { | |
| 133 |
2
1. capitalize : replaced return value with "" for fr/sii/ogham/core/util/StringUtils::capitalize → NO_COVERAGE 2. capitalize : replaced return value with "" for fr/sii/ogham/core/util/StringUtils::capitalize → SURVIVED |
return org.apache.commons.lang3.StringUtils.capitalize(str); |
| 134 | } | |
| 135 | ||
| 136 | private StringUtils() { | |
| 137 | super(); | |
| 138 | } | |
| 139 | } | |
Mutations | ||
| 52 |
1.1 |
|
| 76 |
1.1 2.2 3.3 4.4 |
|
| 107 |
1.1 2.2 |
|
| 133 |
1.1 2.2 |