-
Notifications
You must be signed in to change notification settings - Fork 54
Release 0.1.6 #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release 0.1.6 #198
Changes from all commits
3ce2def
0e5e451
188b794
8c28af9
1d3d639
66405ee
413a9df
4e75e71
da1dfa8
c4ec584
6cc00dd
df7d7d7
fed4170
d73d621
72d1219
0c17b14
1607fc2
d6ed398
bd57ada
86ce818
5c20964
49094a2
2818838
2b29afd
70770cf
9882dc3
ce40551
d42bbbb
985ddc8
ed3ea11
8b07ae3
6c42c68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Contributor Code of Conduct | ||
|
|
||
| As contributors and maintainers of this project, and in the interest of | ||
| fostering an open and welcoming community, we pledge to respect all people who | ||
| contribute through reporting issues, posting feature requests, updating | ||
| documentation, submitting pull requests or patches, and other activities. | ||
|
|
||
| We are committed to making participation in this project a harassment-free | ||
| experience for everyone, regardless of level of experience, gender, gender | ||
| identity and expression, sexual orientation, disability, personal appearance, | ||
| body size, race, ethnicity, age, religion, or nationality. | ||
|
|
||
| Examples of unacceptable behavior by participants include: | ||
|
|
||
| * The use of sexualized language or imagery | ||
| * Personal attacks | ||
| * Trolling or insulting/derogatory comments | ||
| * Public or private harassment | ||
| * Publishing other's private information, such as physical or electronic | ||
| addresses, without explicit permission | ||
| * Other unethical or unprofessional conduct | ||
|
|
||
| Project maintainers have the right and responsibility to remove, edit, or | ||
| reject comments, commits, code, wiki edits, issues, and other contributions | ||
| that are not aligned to this Code of Conduct, or to ban temporarily or | ||
| permanently any contributor for other behaviors that they deem inappropriate, | ||
| threatening, offensive, or harmful. | ||
|
|
||
| By adopting this Code of Conduct, project maintainers commit themselves to | ||
| fairly and consistently applying these principles to every aspect of managing | ||
| this project. Project maintainers who do not follow or enforce the Code of | ||
| Conduct may be permanently removed from the project team. | ||
|
|
||
| This Code of Conduct applies both within project spaces and in public spaces | ||
| when an individual is representing the project or its community. | ||
|
|
||
| Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
| reported by contacting a project maintainer at [mercyblitz@gmail.com](mailto:mercyblitz@gmail.com). All | ||
| complaints will be reviewed and investigated and will result in a response that | ||
| is deemed necessary and appropriate to the circumstances. Maintainers are | ||
| obligated to maintain confidentiality with regard to the reporter of an | ||
| incident. | ||
|
|
||
|
|
||
| This Code of Conduct is adapted from the [Contributor Covenant][homepage], | ||
| version 1.3.0, available at https://www.contributor-covenant.org/version/1/3/0/code-of-conduct.html | ||
|
|
||
| [homepage]: https://www.contributor-covenant.org |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,11 +17,15 @@ | |||||||||||||
| package io.microsphere.util; | ||||||||||||||
|
|
||||||||||||||
| import io.microsphere.annotation.Immutable; | ||||||||||||||
| import io.microsphere.annotation.Nonnull; | ||||||||||||||
| import io.microsphere.annotation.Nullable; | ||||||||||||||
|
|
||||||||||||||
| import java.util.StringTokenizer; | ||||||||||||||
| import java.util.ArrayList; | ||||||||||||||
| import java.util.Collection; | ||||||||||||||
| import java.util.List; | ||||||||||||||
|
|
||||||||||||||
| import static io.microsphere.util.ArrayUtils.asArray; | ||||||||||||||
| import static io.microsphere.collection.CollectionUtils.isEmpty; | ||||||||||||||
| import static io.microsphere.util.ArrayUtils.ofArray; | ||||||||||||||
| import static io.microsphere.util.CharSequenceUtils.isEmpty; | ||||||||||||||
| import static io.microsphere.util.CharSequenceUtils.length; | ||||||||||||||
| import static java.lang.Character.isDigit; | ||||||||||||||
|
|
@@ -127,7 +131,8 @@ public static boolean isNotBlank(String value) { | |||||||||||||
| * @param delimiter the char used as a delimiter to split the String | ||||||||||||||
| * @return an array of Strings, split by the delimiter; never null | ||||||||||||||
| */ | ||||||||||||||
| public static String[] split(String value, char delimiter) { | ||||||||||||||
| @Nonnull | ||||||||||||||
| public static String[] split(@Nullable String value, char delimiter) { | ||||||||||||||
| return split(value, valueOf(delimiter)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -140,7 +145,9 @@ public static String[] split(String value, char delimiter) { | |||||||||||||
| * <h3>Example Usage</h3> | ||||||||||||||
| * <pre>{@code | ||||||||||||||
| * StringUtils.split(null, ",") = [] | ||||||||||||||
| * StringUtils.split("", null) = [] | ||||||||||||||
| * StringUtils.split("", ";") = [] | ||||||||||||||
| * StringUtils.split("abc", "") = ["a", "b", "c"] | ||||||||||||||
| * StringUtils.split("a,b,c", ",") = ["a", "b", "c"] | ||||||||||||||
| * StringUtils.split("a;b;c", ",") = ["a;b;c"] | ||||||||||||||
| * StringUtils.split("a,,b,c", ",") = ["a", "", "b", "c"] | ||||||||||||||
|
Comment on lines
145
to
153
|
||||||||||||||
|
|
@@ -150,12 +157,41 @@ public static String[] split(String value, char delimiter) { | |||||||||||||
| * @param delimiter the String used as a delimiter to split the String, may be null or empty | ||||||||||||||
| * @return an array of Strings, split by the delimiter; never null | ||||||||||||||
| */ | ||||||||||||||
| public static String[] split(String value, String delimiter) { | ||||||||||||||
| if (isEmpty(value) || isEmpty(delimiter)) { | ||||||||||||||
| @Nonnull | ||||||||||||||
| public static String[] split(@Nullable String value, @Nullable String delimiter) { | ||||||||||||||
| int length = length(value); | ||||||||||||||
| if (length < 1) { | ||||||||||||||
| return EMPTY_STRING_ARRAY; | ||||||||||||||
| } | ||||||||||||||
| StringTokenizer stringTokenizer = new StringTokenizer(value, delimiter); | ||||||||||||||
| return (String[]) asArray(stringTokenizer, String.class); | ||||||||||||||
|
|
||||||||||||||
| if (delimiter == null) { | ||||||||||||||
| return ofArray(value); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| int delimiterLength = delimiter.length(); | ||||||||||||||
|
|
||||||||||||||
| List<String> result = new ArrayList<>(); | ||||||||||||||
|
|
||||||||||||||
| if (delimiterLength == 0) { | ||||||||||||||
| for (int i = 0; i < value.length(); i++) { | ||||||||||||||
| result.add(value.substring(i, i + 1)); | ||||||||||||||
| } | ||||||||||||||
| } else { | ||||||||||||||
| int startIndex = 0; | ||||||||||||||
| int endIndex; | ||||||||||||||
|
|
||||||||||||||
| while ((endIndex = value.indexOf(delimiter, startIndex)) > -1) { | ||||||||||||||
| String part = value.substring(startIndex, endIndex); | ||||||||||||||
| result.add(part); | ||||||||||||||
| startIndex = endIndex + delimiterLength; | ||||||||||||||
| } | ||||||||||||||
| if (startIndex <= length) { | ||||||||||||||
| // Add rest of String, but not in case of empty input. | ||||||||||||||
| result.add(value.substring(startIndex)); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+188
to
+191
|
||||||||||||||
| if (startIndex <= length) { | |
| // Add rest of String, but not in case of empty input. | |
| result.add(value.substring(startIndex)); | |
| } | |
| // Add rest of String, but not in case of empty input. | |
| result.add(value.substring(startIndex)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,15 @@ | |
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static io.microsphere.collection.ListUtils.newLinkedList; | ||
| import static io.microsphere.collection.Lists.ofList; | ||
| import static io.microsphere.constants.SymbolConstants.COMMA; | ||
| import static io.microsphere.constants.SymbolConstants.COMMA_CHAR; | ||
| import static io.microsphere.constants.SymbolConstants.DOT; | ||
| import static io.microsphere.constants.SymbolConstants.SHARP; | ||
| import static io.microsphere.constants.SymbolConstants.SPACE; | ||
| import static io.microsphere.constants.SymbolConstants.SPACE_CHAR; | ||
| import static io.microsphere.constants.SymbolConstants.VERTICAL_BAR; | ||
| import static io.microsphere.util.ArrayUtils.ofArray; | ||
| import static io.microsphere.util.CharSequenceUtils.length; | ||
| import static io.microsphere.util.CharSequenceUtilsTest.TEST_BLANK_STRING; | ||
| import static io.microsphere.util.CharSequenceUtilsTest.TEST_CSV_STRING; | ||
| import static io.microsphere.util.CharSequenceUtilsTest.TEST_EMPTY_STRING; | ||
|
|
@@ -31,17 +33,20 @@ | |
| import static io.microsphere.util.StringUtils.substringBefore; | ||
| import static io.microsphere.util.StringUtils.substringBeforeLast; | ||
| import static io.microsphere.util.StringUtils.substringBetween; | ||
| import static io.microsphere.util.StringUtils.toStringArray; | ||
| import static io.microsphere.util.StringUtils.trimAllWhitespace; | ||
| import static io.microsphere.util.StringUtils.trimLeadingWhitespace; | ||
| import static io.microsphere.util.StringUtils.trimTrailingWhitespace; | ||
| import static io.microsphere.util.StringUtils.trimWhitespace; | ||
| import static io.microsphere.util.StringUtils.uncapitalize; | ||
| import static java.util.Collections.emptyList; | ||
| import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.springframework.util.StringUtils.delimitedListToStringArray; | ||
|
|
||
| /** | ||
| * {@link StringUtils} Test | ||
|
|
@@ -81,26 +86,39 @@ void testIsNotBlank() { | |
|
|
||
| @Test | ||
| void testSplit() { | ||
| String[] values = split(null, SPACE_CHAR); | ||
| assertSame(EMPTY_STRING_ARRAY, values); | ||
| assertSame(EMPTY_STRING_ARRAY, assertSplit(null, SPACE)); | ||
|
|
||
| values = split(TEST_EMPTY_STRING, SPACE); | ||
| assertSame(EMPTY_STRING_ARRAY, values); | ||
| assertSame(EMPTY_STRING_ARRAY, assertSplit(TEST_EMPTY_STRING, SPACE)); | ||
|
|
||
| values = split(TEST_BLANK_STRING, null); | ||
| assertSame(EMPTY_STRING_ARRAY, values); | ||
| assertSame(EMPTY_STRING_ARRAY, assertSplit(TEST_EMPTY_STRING, EMPTY_STRING)); | ||
|
|
||
| values = split(TEST_BLANK_STRING, SPACE); | ||
| assertArrayEquals(EMPTY_STRING_ARRAY, values); | ||
| assertArrayEquals(ofArray(TEST_BLANK_STRING), assertSplit(TEST_BLANK_STRING, null)); | ||
|
|
||
| values = split(SPACE + SPACE, SPACE); | ||
| assertArrayEquals(EMPTY_STRING_ARRAY, values); | ||
| assertArrayEquals(ofArray(TEST_BLANK_STRING), assertSplit(TEST_BLANK_STRING, EMPTY_STRING)); | ||
|
|
||
| values = split(SPACE + SPACE + SPACE, SPACE); | ||
| assertArrayEquals(EMPTY_STRING_ARRAY, values); | ||
| assertArrayEquals(ofArray(EMPTY_STRING, EMPTY_STRING), assertSplit(TEST_BLANK_STRING, SPACE)); | ||
|
|
||
| values = split(TEST_CSV_STRING, COMMA_CHAR); | ||
| assertArrayEquals(ofArray("a", "b", "c"), values); | ||
| assertArrayEquals(ofArray(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING), assertSplit(SPACE + SPACE, SPACE)); | ||
|
|
||
| assertArrayEquals(ofArray(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING), assertSplit(SPACE + SPACE + SPACE, SPACE)); | ||
|
|
||
| assertArrayEquals(ofArray("a", "b", "c"), assertSplit(TEST_CSV_STRING, COMMA)); | ||
|
|
||
| assertArrayEquals(ofArray(TEST_CSV_STRING), assertSplit(TEST_CSV_STRING, SPACE)); | ||
|
|
||
| assertArrayEquals(ofArray("a", "", "b", "c"), assertSplit("a, , b, c", ", ")); | ||
| } | ||
|
|
||
| String[] assertSplit(String str, String delimiter) { | ||
| String[] values = split(str, delimiter); | ||
| int length = length(delimiter); | ||
| if (length == 1) { | ||
| assertArrayEquals(split(str, delimiter.charAt(0)), values); | ||
| } else if (length > 1) { | ||
| String[] valuesFromString = delimitedListToStringArray(str, delimiter); | ||
| assertArrayEquals(valuesFromString, values); | ||
| } | ||
| return values; | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -161,7 +179,10 @@ void testEndsWith() { | |
| @Test | ||
| void testReplace() { | ||
| assertNull(replace(null, null, null)); | ||
|
|
||
| assertEquals(TEST_EMPTY_STRING, replace(TEST_EMPTY_STRING, null, null)); | ||
|
||
| assertEquals(TEST_EMPTY_STRING, replace(TEST_EMPTY_STRING, "null", null)); | ||
| assertEquals(TEST_CSV_STRING, replace(TEST_CSV_STRING, "null", "null")); | ||
| assertEquals(TEST_EMPTY_STRING, replace(TEST_EMPTY_STRING, TEST_EMPTY_STRING, null)); | ||
| assertEquals(TEST_EMPTY_STRING, replace(TEST_EMPTY_STRING, TEST_EMPTY_STRING, TEST_EMPTY_STRING, 0)); | ||
|
|
||
|
|
@@ -173,6 +194,9 @@ void testReplace() { | |
| assertEquals("a|b|c", replace(TEST_CSV_STRING, COMMA, VERTICAL_BAR)); | ||
| assertEquals("a|b|c", replace(TEST_CSV_STRING, COMMA, VERTICAL_BAR, 100)); | ||
| assertEquals("a|b,c", replace(TEST_CSV_STRING, COMMA, VERTICAL_BAR, 1)); | ||
|
|
||
| assertEquals("abc", replace(TEST_CSV_STRING, COMMA, EMPTY_STRING)); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -227,6 +251,7 @@ void testSubstringBeforeLast() { | |
| assertSame(TEST_EMPTY_STRING, substringBeforeLast(TEST_EMPTY_STRING, null)); | ||
| assertSame(TEST_CSV_STRING, substringBeforeLast(TEST_CSV_STRING, null)); | ||
| assertSame(TEST_CSV_STRING, substringBeforeLast(TEST_CSV_STRING, TEST_EMPTY_STRING)); | ||
| assertSame(TEST_CSV_STRING, substringBeforeLast(TEST_CSV_STRING, SHARP)); | ||
|
|
||
| assertEquals("a,b", substringBeforeLast(TEST_CSV_STRING, COMMA)); | ||
| assertEquals("a,", substringBeforeLast(TEST_CSV_STRING, "b")); | ||
|
|
@@ -246,6 +271,7 @@ void testSubstringAfterLast() { | |
| assertEquals(",c", substringAfterLast(TEST_CSV_STRING, "b")); | ||
| assertEquals("c", substringAfterLast(TEST_CSV_STRING, COMMA)); | ||
| assertEquals(TEST_EMPTY_STRING, substringAfterLast(TEST_CSV_STRING, "c")); | ||
| assertEquals(TEST_EMPTY_STRING, substringAfterLast(TEST_CSV_STRING, SHARP)); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -326,4 +352,12 @@ void testUncapitalize() { | |
| assertSame("hello world", uncapitalize("hello world")); | ||
| } | ||
|
|
||
| @Test | ||
| void testToStringArray() { | ||
| assertSame(EMPTY_STRING_ARRAY, toStringArray(null)); | ||
| assertSame(EMPTY_STRING_ARRAY, toStringArray(emptyList())); | ||
| assertSame(EMPTY_STRING_ARRAY, toStringArray(newLinkedList())); | ||
| assertArrayEquals(ofArray("a", "b", "c"), toStringArray(ofList("a", "b", "c"))); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document the behavior for a non-empty String with a null delimiter (returns the whole String as a single element) to clarify the difference from empty and blank inputs.