Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions CODE_OF_CONDUCT.md
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
Expand Up @@ -1315,7 +1315,7 @@ private static String findSubProtocolsString(String url) {
if (startIndex > -1) {
int endIndex = url.indexOf("://", startIndex);
if (endIndex > startIndex) {
return url.substring(startIndex, endIndex);
return url.substring(startIndex + 1, endIndex);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand All @@ -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"]
Expand All @@ -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));
}
}

return toStringArray(result);
}

/**
Expand Down Expand Up @@ -780,6 +816,26 @@ public static String uncapitalize(String str) {
return changeFirstCharacter(str, false);
}

/**
* Convert the given {@link Collection} into a {@code String} array.
* <p>The {@code Collection} must contain {@code String} elements only.
*
* <h3>Example Usage</h3>
* <pre>{@code
* StringUtils.toStringArray(null) = []
* StringUtils.toStringArray(new ArrayList<>()) = []
* StringUtils.toStringArray(Arrays.asList("a", "b", "c")) = ["a", "b", "c"]
* }</pre>
*
* @param collection the {@code Collection} to convert
* (potentially {@code null} or empty)
* @return the resulting {@code String} array
*/
@Nonnull
public static String[] toStringArray(@Nullable Collection<String> collection) {
return isEmpty(collection) ? EMPTY_STRING_ARRAY : collection.toArray(EMPTY_STRING_ARRAY);
}

static String changeFirstCharacter(String str, boolean capitalize) {
int len = length(str);
if (len < 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ void testDeleteDirectoryOnNotExists() throws IOException {

@Test
void testDeleteDirectoryOnIOException() throws Exception {
ExecutorService executor = newSingleThreadExecutor();
executor.submit(this::testDeleteDirectoryOnIOException0);
shutdown(executor);
while (!executor.isTerminated()) {
}
}

Void testDeleteDirectoryOnIOException0() throws Exception {
File testDir = createRandomTempDirectory();

ExecutorService fileCreationExecutor = newSingleThreadExecutor();
Expand Down Expand Up @@ -161,6 +169,8 @@ void testDeleteDirectoryOnIOException() throws Exception {
assertNotNull(ioExceptionReference.get());
assertFalse(creatingFile.get());
assertFalse(deletingDirectory.get());

return null;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void testGetClassNamesInClassPath() {
for (String classPath : classPaths) {
Set<String> classNames = repository.getClassNamesInClassPath(classPath, true);
assertNotNull(classNames);
assertThrows(UnsupportedOperationException.class, classNames::clear);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -81,26 +86,37 @@ 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);
if (length(delimiter) == 1) {
assertArrayEquals(split(str, delimiter.charAt(0)), values);
}
String[] valuesFromString = delimitedListToStringArray(str, delimiter);
assertArrayEquals(valuesFromString, values);
return values;
}

@Test
Expand Down Expand Up @@ -161,6 +177,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, 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));
Expand All @@ -173,6 +193,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
Expand Down Expand Up @@ -227,6 +250,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"));
Expand All @@ -246,6 +270,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
Expand Down Expand Up @@ -326,4 +351,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")));
}

}
14 changes: 13 additions & 1 deletion microsphere-java-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
<jsr305.version>3.0.2</jsr305.version>
<apache.commons.logging.version>1.3.2</apache.commons.logging.version>
<spring.version>5.3.31</spring.version>
<spring.version>6.2.11</spring.version>
<slf4j.version>1.7.36</slf4j.version>
<logback.version>1.2.13</logback.version>
<!-- Testing -->
Expand Down Expand Up @@ -106,4 +106,16 @@
</dependencies>

</dependencyManagement>

<profiles>
<profile>
<id>spring5</id>
<activation>
<jdk>[1.8,17)</jdk>
</activation>
<properties>
<spring.version>5.3.31</spring.version>
</properties>
</profile>
</profiles>
</project>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-build</artifactId>
<version>0.2.0</version>
<version>0.2.1</version>
</parent>

<groupId>io.github.microsphere-projects</groupId>
Expand Down