Skip to content

Commit 7d751fd

Browse files
committed
feat: 1.2.1
- gradle version upgrade - Strings.equalsIgnoreCase - interfaces
1 parent 06d4dff commit 7d751fd

File tree

6 files changed

+81
-3
lines changed

6 files changed

+81
-3
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.javaquery.util.iface;
2+
3+
/**
4+
* @author vicky.thakor
5+
* @since 2022-05-16
6+
*/
7+
public interface Processor<T, R> {
8+
9+
/**
10+
* Process T object and return the value.
11+
* @param t - input object
12+
* @return return value
13+
*/
14+
R process(T t);
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.javaquery.util.iface;
2+
3+
import com.javaquery.util.io.JFile;
4+
5+
import java.io.IOException;
6+
7+
/**
8+
* @author vicky.thakor
9+
* @since 2022-05-16
10+
*/
11+
public interface Reader<T> {
12+
/**
13+
* @param file - file to read
14+
* @return return the result
15+
* @throws IOException exception
16+
*/
17+
T read(JFile file) throws IOException;
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.javaquery.util.iface;
2+
3+
import com.javaquery.util.io.JFile;
4+
5+
import java.io.IOException;
6+
7+
/**
8+
* @author vicky.thakor
9+
* @since 2022-05-16
10+
*/
11+
public interface Writer<T> {
12+
/**
13+
* @param data - data to write
14+
* @param file - file to write
15+
* @throws IOException exception
16+
*/
17+
void write(T data, JFile file) throws IOException;
18+
}

src/main/java/com/javaquery/util/string/Strings.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,24 @@ public static void notEquals(String a, String b, ExecutableFunction executableFu
212212
}
213213
}
214214

215+
/**
216+
* Compares this String to another String, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case.
217+
* Two characters c1 and c2 are considered the same ignoring case if at least one of the following is true:
218+
* <ul>
219+
* <li>The two characters are the same (as compared by the == operator)</li>
220+
* <li>Calling Character.toLowerCase(Character.toUpperCase(char)) on each character produces the same result</li>
221+
* </ul>
222+
*
223+
* @param a String
224+
* @param b String to be compared with {@code a} for equality (ignoring case considerations)
225+
* @return {@code true} if the provided Strings are equalsIgnoreCase otherwise
226+
* * {@code false}
227+
*/
228+
public static boolean equalsIgnoreCase(String a, String b){
229+
return (a == null && b == null)
230+
|| (a != null && a.equalsIgnoreCase(b));
231+
}
232+
215233
/**
216234
* Compares this String to another String, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case.
217235
* Two characters c1 and c2 are considered the same ignoring case if at least one of the following is true:
@@ -225,7 +243,7 @@ public static void notEquals(String a, String b, ExecutableFunction executableFu
225243
* @param executableFunction lambda function given executed if the provided Strings are equals (ignoring case considerations).
226244
*/
227245
public static void equalsIgnoreCase(String a, String b, ExecutableFunction executableFunction){
228-
if(a != null && a.equalsIgnoreCase(b)){
246+
if(equalsIgnoreCase(a, b)){
229247
executableFunction.execute();
230248
}
231249
}
@@ -238,7 +256,7 @@ public static void equalsIgnoreCase(String a, String b, ExecutableFunction execu
238256
* @param executableFunction lambda function given executed if the provided Strings are non equals (ignoring case considerations).
239257
*/
240258
public static void notEqualsIgnoreCase(String a, String b, ExecutableFunction executableFunction){
241-
if(a != null && !a.equalsIgnoreCase(b)){
259+
if(!equalsIgnoreCase(a, b)){
242260
executableFunction.execute();
243261
}
244262
}

src/test/java/com/javaquery/util/string/TestStrings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ public void test_notEquals(){
116116

117117
@Test
118118
public void test_equalsIgnoreCase(){
119+
Assertions.assertTrue(Strings.equalsIgnoreCase("a", "A"));
120+
Assertions.assertTrue(Strings.equalsIgnoreCase("a", "a"));
121+
Assertions.assertTrue(Strings.equalsIgnoreCase(null, null));
122+
Assertions.assertFalse(Strings.equalsIgnoreCase("a", null));
123+
Assertions.assertFalse(Strings.equalsIgnoreCase(null, "b"));
124+
}
125+
126+
@Test
127+
public void test_equalsIgnoreCaseWithExecutableFunction(){
119128
Assertions.assertThrows(RuntimeException.class, () -> Strings.equalsIgnoreCase("A", "A", () -> {throw new RuntimeException("Function executed when two Strings are equalsIgnoreCase");}));
120129
Assertions.assertThrows(RuntimeException.class, () -> Strings.equalsIgnoreCase("A", "a", () -> {throw new RuntimeException("Function executed when two Strings are equalsIgnoreCase");}));
121130
Strings.equalsIgnoreCase("A", "b", () -> {throw new RuntimeException("Function won't execute when two Strings are not equalsIgnoreCase");});

0 commit comments

Comments
 (0)