Skip to content

Commit

Permalink
0.11.3 - Updated to Java 9, JUnit 5. Changed StringCompare and String…
Browse files Browse the repository at this point in the history
…Index StringBuilder parameters to CharSequence.
  • Loading branch information
TeamworkGuy2 committed Dec 21, 2017
1 parent 8749509 commit 3224c1d
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 75 deletions.
9 changes: 7 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-9">
<attributes>
<attribute name="module" value="true"/>
<attribute name="limit-modules" value="java.base,java.xml.ws"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/ANTLR"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/TemplateUtil"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/TestChecks"/>
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
### [0.11.2](https://github.com/TeamworkGuy2/JTextUtil/commit/295e57a6016ecedbf3f68eb7f65aff98b27961c7) - 2016-10-30
### [0.11.3](N/A) - 2017-12-20
#### Changed
* Upgrade to Java 9
* Changed `StringCompare` `anyStartWith()`, `compareStartsWith()`, and `equal()` `StringBuilder` parameters to `CharSequence`
* Changed `StringIndex` `indexOf()`, `lastIndexOf()`, `indexOfSupplement()`, and `startsWithIndex()` `StringBuilder` parameters to `CharSequence`


--------
### [0.11.2](https://github.com/TeamworkGuy2/JTextUtil/commit/874950940409f0cd71e62c499504abb5a56c0f0f) - 2017-08-12
#### Added
* Added StringCompare.compareIgnoreCase(String, String) overload and unit test

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
JTextUtil
==============
version: 0.11.2
version: 0.11.3

Dependencies: none

Expand All @@ -15,4 +15,4 @@ String utility methods for join, pad, split, substring, trim, replace, n-th matc
Meant to provide more options than available in the Java API as of Java 1.8.

### twg2.text.test
JUnit tests and examples (requires [JUnit 4] (http://junit.org/))
JUnit tests and examples (requires [JUnit 5](http://junit.org/))
Binary file modified bin/jtext_util-with-tests.jar
Binary file not shown.
Binary file modified bin/jtext_util.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion package-lib.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version" : "0.11.2",
"version" : "0.11.3",
"name" : "jtext-util",
"description" : "String search, replace, and transform functions that provide more control, at the trade-off of verbosity, than those already in the Java API",
"homepage" : "https://github.com/TeamworkGuy2/JTextUtil",
Expand Down
10 changes: 5 additions & 5 deletions src/twg2/text/stringSearch/StringCompare.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/** Utility methods for comparing portions of strings.<br>
* Includes {@link #startsWithAny(String, String...)} and {@link #endsWithAny(String, String...)}
* to find common prefixes and suffixes amongst a group of strings.<br>
* And the complementary {@link #anyStartWith(List, StringBuilder)} that searching for
* And the complementary {@link #anyStartWith(List, CharSequence)} that searching for
* any string in a list that starts with a specified sub-string.<br>
* {@link #compareEqualCount(CharSequence, CharSequence)} to compare how many consecutive
* characters are equal between two strings.
Expand Down Expand Up @@ -85,7 +85,7 @@ public static final boolean startsWith(final char[] str, int strOff, final char[
* @return true if any of the strings in {@code strs} starts with the contents of {@code startStr},
* false if none of the strings start with {@code startStr}
*/
public static final boolean anyStartWith(final List<String> strs, final StringBuilder startStr) {
public static final boolean anyStartWith(final List<String> strs, final CharSequence startStr) {
for(int i = 0, len = strs.size(); i < len; i++) {
if(compareStartsWith(strs.get(i), startStr, 0) == 0) {
return true;
Expand All @@ -103,7 +103,7 @@ public static final boolean anyStartWith(final List<String> strs, final StringBu
* @return true if any of the strings in {@code strs} starts with the contents of {@code startStr},
* false if none of the strings start with {@code startStr}
*/
public static final boolean anyStartWith(List<String> strs, final StringBuilder startStr, int startStrOffset) {
public static final boolean anyStartWith(List<String> strs, final CharSequence startStr, int startStrOffset) {
for(int i = 0, len = strs.size(); i < len; i++) {
if(compareStartsWith(strs.get(i), startStr, startStrOffset) == 0) {
return true;
Expand All @@ -129,7 +129,7 @@ public static final boolean anyStartWith(List<String> strs, final StringBuilder
* @return 0 if {@code str} starts with {@code startStr}, greater than 0 if {@code str}
* is greater than {@code startStr}, less than 0 if {@code str} is less than {@code startStr}
*/
public static final int compareStartsWith(String str, final StringBuilder startStr, int startStrOffset) {
public static final int compareStartsWith(String str, final CharSequence startStr, int startStrOffset) {
int sbRemLen = startStr.length() - startStrOffset;
int len = str.length() > sbRemLen ? sbRemLen : str.length();
int k = 0;
Expand All @@ -152,7 +152,7 @@ public static final int compareStartsWith(String str, final StringBuilder startS
* @param strB the string builder to compare
* @return true if the string and string builder's contents are equal, false otherwise
*/
public static final boolean equal(String str, final StringBuilder strB) {
public static final boolean equal(String str, final CharSequence strB) {
if(str.length() != strB.length()) { return false; }

for(int i = str.length() - 1; i > -1; i--) {
Expand Down
47 changes: 13 additions & 34 deletions src/twg2/text/stringSearch/StringIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ private static final int indexOfSupplement(char[] str, int strOff, int strLen, i


/**
* @see #indexOf(StringBuilder, int, int, int)
* @see #indexOf(CharSequence, int, int, int)
*/
public static final int indexOf(StringBuilder str, int strOff, int matchChar) {
public static final int indexOf(CharSequence str, int strOff, int matchChar) {
return indexOf(str, strOff, str.length() - strOff, matchChar);
}

Expand All @@ -198,7 +198,7 @@ public static final int indexOf(StringBuilder str, int strOff, int matchChar) {
* @param matchChar the character to search for in {@code str}
* @return the index of the found matching character, from index 0, or -1 if the character could not be found
*/
public static final int indexOf(StringBuilder str, int strOff, int strLen, int matchChar) {
public static final int indexOf(CharSequence str, int strOff, int strLen, int matchChar) {
int strLength = strOff + strLen;

if(matchChar < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
Expand All @@ -224,7 +224,7 @@ public static final int indexOf(StringBuilder str, int strOff, int strLen, int m
* @param matchChar the character to search for in {@code str}
* @return the index of the found matching character, from index 0, or -1 if the character could not be found
*/
public static final int lastIndexOf(StringBuilder str, int strOff, int strLen, int matchChar) {
public static final int lastIndexOf(CharSequence str, int strOff, int strLen, int matchChar) {
int strLength = strOff + strLen;

if(matchChar < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
Expand All @@ -251,7 +251,7 @@ public static final int lastIndexOf(StringBuilder str, int strOff, int strLen, i
* @param matchChar the supplementary characters to search for
* @return the lower index within the {@code str} array of the matching {@code matchChar}
*/
private static final int indexOfSupplement(StringBuilder str, int strOff, int strLen, int matchChar) {
private static final int indexOfSupplement(CharSequence str, int strOff, int strLen, int matchChar) {
if(Character.isValidCodePoint(matchChar)) {
final char high = Character.highSurrogate(matchChar);
final char low = Character.lowSurrogate(matchChar);
Expand Down Expand Up @@ -839,38 +839,17 @@ public static final int indexOf(CharSequence str, int strOff, CharSequence subSt
}


/** Search for a sub string of characters in an array of characters and return the absolute index
* where the sub string begins, or -1 if the sub string does not exist in the main array
* @param str the char sequence to search
* @param strOff the offset into the character array at which to start searching
* @param subStr the sub string to search for in {@code str}
* @param subStrOff the offset into the sub string array at which to start searching
* @return the index of the found sub string, from index 0, or -1 if the sub string could not be found
*/
public static final int indexOf(CharSequence str, int strOff, int searchChar) {
int maxI = str.length();

for(int i = strOff; i < maxI; i++) {
if(str.charAt(i) == searchChar) {
return i;
}
}
return -1;
}


/** Returns the list index of the string that starts with {@code strBuilder}
* @param strs the list of strings, the start of each is compared to {@code strBuilder}
* @param strBuilder the string builder contents to compare to the start of each string
* in {@code strs}
* @param offsetStrB the offset into the string builder's contents at which to start
/** Returns the list index of the string that starts with {@code startStr}
* @param strs the list of strings, the start of each is compared to {@code startStr}
* @param startStr the character sequence to compare to the start of each string in {@code strs}
* @param offsetStartStr the offset into the start string's contents at which to start
* comparing characters to strings from {@code strs}
* @return the {@code str} index of the string that starts with the contents of {@code strBldr},
* -1 if none of the strings start with {@code strBuilder}
* @return the {@code str} index of the string that starts with the contents of {@code startStr},
* -1 if none of the strings start with {@code startStr}
*/
public static final int startsWithIndex(List<String> strs, StringBuilder strBuilder, int offsetStrB) {
public static final int startsWithIndex(List<String> strs, CharSequence startStr, int offsetStartStr) {
for(int strI = 0, len = strs.size(); strI < len; strI++) {
if(StringCompare.compareStartsWith(strs.get(strI), strBuilder, offsetStrB) == 0) {
if(StringCompare.compareStartsWith(strs.get(strI), startStr, offsetStartStr) == 0) {
return strI;
}
}
Expand Down
37 changes: 8 additions & 29 deletions src/twg2/text/templates/TStringIndex.stg
Original file line number Diff line number Diff line change
Expand Up @@ -464,38 +464,17 @@ $singleTypes:{type | /**
}


/** Search for a sub string of characters in an array of characters and return the absolute index
* where the sub string begins, or -1 if the sub string does not exist in the main array
* @param str the char sequence to search
* @param strOff the offset into the character array at which to start searching
* @param subStr the sub string to search for in {@code str}
* @param subStrOff the offset into the sub string array at which to start searching
* @return the index of the found sub string, from index 0, or -1 if the sub string could not be found
*/
public static final int indexOf(CharSequence str, int strOff, int searchChar) {
int maxI = str.length();

for(int i = strOff; i < maxI; i++) {
if(str.charAt(i) == searchChar) {
return i;
}
}
return -1;
}


/** Returns the list index of the string that starts with {@code strBuilder}
* @param strs the list of strings, the start of each is compared to {@code strBuilder}
* @param strBuilder the string builder contents to compare to the start of each string
* in {@code strs}
* @param offsetStrB the offset into the string builder's contents at which to start
/** Returns the list index of the string that starts with {@code startStr}
* @param strs the list of strings, the start of each is compared to {@code startStr}
* @param startStr the character sequence to compare to the start of each string in {@code strs}
* @param offsetStartStr the offset into the start string's contents at which to start
* comparing characters to strings from {@code strs}
* @return the {@code str} index of the string that starts with the contents of {@code strBldr},
* -1 if none of the strings start with {@code strBuilder}
* @return the {@code str} index of the string that starts with the contents of {@code startStr},
* -1 if none of the strings start with {@code startStr}
*/
public static final int startsWithIndex(List<String> strs, StringBuilder strBuilder, int offsetStrB) {
public static final int startsWithIndex(List<String> strs, CharSequence startStr, int offsetStartStr) {
for(int strI = 0, len = strs.size(); strI < len; strI++) {
if(StringCompare.compareStartsWith(strs.get(strI), strBuilder, offsetStrB) == 0) {
if(StringCompare.compareStartsWith(strs.get(strI), startStr, offsetStartStr) == 0) {
return strI;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static final void generateStringIndex() throws IOException {
stringType.getElementEnd = ")";

RandomAccessTypeInfo stringBuilderType = new RandomAccessTypeInfo();
stringBuilderType.type = "StringBuilder";
stringBuilderType.type = "CharSequence";
stringBuilderType.getLength = ".length()";
stringBuilderType.getElement = ".charAt(";
stringBuilderType.getElementEnd = ")";
Expand Down

0 comments on commit 3224c1d

Please sign in to comment.