From 6ba82d38ccce0ceae3f5fa6bbf6091e8fd89441c Mon Sep 17 00:00:00 2001 From: Cavero Barca Date: Mon, 27 Jan 2020 13:01:50 +0100 Subject: [PATCH] Rename the class to separate functionality from what the class is about --- .../CaseInsensitiveWorkarounds.java} | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) rename core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/{containscaseinsensitive/ContainsWorkarounds.java => contains/CaseInsensitiveWorkarounds.java} (79%) diff --git a/core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/containscaseinsensitive/ContainsWorkarounds.java b/core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/contains/CaseInsensitiveWorkarounds.java similarity index 79% rename from core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/containscaseinsensitive/ContainsWorkarounds.java rename to core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/contains/CaseInsensitiveWorkarounds.java index 75150f6edb..5965c6eb4f 100644 --- a/core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/containscaseinsensitive/ContainsWorkarounds.java +++ b/core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/contains/CaseInsensitiveWorkarounds.java @@ -1,4 +1,4 @@ -package com.baeldung.containscaseinsensitive; +package com.baeldung.contains; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; @@ -19,7 +19,7 @@ import org.openjdk.jmh.annotations.State; @State(Scope.Benchmark) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) -public class ContainsWorkarounds { +public class CaseInsensitiveWorkarounds { private String src; private String dest; @@ -49,23 +49,26 @@ public class ContainsWorkarounds { return src.matches("(?i).*" + dest + ".*"); } - // String regionMatches() - @Benchmark - public boolean regionMatches() { + public boolean processRegionMatches(String localSrc, String localDest) { + final char firstLo = Character.toLowerCase(localDest.charAt(0)); + final char firstUp = Character.toUpperCase(localDest.charAt(0)); - final char firstLo = Character.toLowerCase(dest.charAt(0)); - final char firstUp = Character.toUpperCase(dest.charAt(0)); - - for (int i = src.length() - dest.length(); i >= 0; i--) { - final char ch = src.charAt(i); + for (int i = localSrc.length() - localDest.length(); i >= 0; i--) { + final char ch = localSrc.charAt(i); if (ch != firstLo && ch != firstUp) continue; - if (src.regionMatches(true, i, dest, 0, dest.length())) + if (localSrc.regionMatches(true, i, localDest, 0, localDest.length())) return true; } - return false; + return false; + } + + // String regionMatches() + @Benchmark + public boolean regionMatches() { + return processRegionMatches(src, dest); } // Pattern CASE_INSENSITIVE with regexp