Rename the class to separate functionality from what the class is about
This commit is contained in:
parent
632f6d6c9e
commit
6ba82d38cc
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.containscaseinsensitive;
|
package com.baeldung.contains;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -19,7 +19,7 @@ import org.openjdk.jmh.annotations.State;
|
||||||
@State(Scope.Benchmark)
|
@State(Scope.Benchmark)
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
public class ContainsWorkarounds {
|
public class CaseInsensitiveWorkarounds {
|
||||||
|
|
||||||
private String src;
|
private String src;
|
||||||
private String dest;
|
private String dest;
|
||||||
|
@ -49,23 +49,26 @@ public class ContainsWorkarounds {
|
||||||
return src.matches("(?i).*" + dest + ".*");
|
return src.matches("(?i).*" + dest + ".*");
|
||||||
}
|
}
|
||||||
|
|
||||||
// String regionMatches()
|
public boolean processRegionMatches(String localSrc, String localDest) {
|
||||||
@Benchmark
|
final char firstLo = Character.toLowerCase(localDest.charAt(0));
|
||||||
public boolean regionMatches() {
|
final char firstUp = Character.toUpperCase(localDest.charAt(0));
|
||||||
|
|
||||||
final char firstLo = Character.toLowerCase(dest.charAt(0));
|
for (int i = localSrc.length() - localDest.length(); i >= 0; i--) {
|
||||||
final char firstUp = Character.toUpperCase(dest.charAt(0));
|
final char ch = localSrc.charAt(i);
|
||||||
|
|
||||||
for (int i = src.length() - dest.length(); i >= 0; i--) {
|
|
||||||
final char ch = src.charAt(i);
|
|
||||||
if (ch != firstLo && ch != firstUp)
|
if (ch != firstLo && ch != firstUp)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (src.regionMatches(true, i, dest, 0, dest.length()))
|
if (localSrc.regionMatches(true, i, localDest, 0, localDest.length()))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// String regionMatches()
|
||||||
|
@Benchmark
|
||||||
|
public boolean regionMatches() {
|
||||||
|
return processRegionMatches(src, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pattern CASE_INSENSITIVE with regexp
|
// Pattern CASE_INSENSITIVE with regexp
|
Loading…
Reference in New Issue