Remove FQCN for StringUtils and let private functions when possible
This commit is contained in:
parent
5badedf7e3
commit
63d9335b09
|
@ -3,6 +3,7 @@ package com.baeldung.trim;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
|
@ -34,7 +35,7 @@ public class LTrimRTrim {
|
|||
}
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
private void setup() {
|
||||
src = " White spaces left and right ";
|
||||
ltrimResult = "White spaces left and right ";
|
||||
rtrimResult = " White spaces left and right";
|
||||
|
@ -67,7 +68,7 @@ public class LTrimRTrim {
|
|||
|
||||
// Going through the String detecting Whitespaces
|
||||
@Benchmark
|
||||
public boolean whileCharacters() {
|
||||
private boolean whileCharacters() {
|
||||
String ltrim = whileLtrim(src);
|
||||
String rtrim = whileRtrim(src);
|
||||
|
||||
|
@ -76,7 +77,7 @@ public class LTrimRTrim {
|
|||
|
||||
// replaceAll() and Regular Expressions
|
||||
@Benchmark
|
||||
public boolean replaceAllRegularExpression() {
|
||||
private boolean replaceAllRegularExpression() {
|
||||
String ltrim = src.replaceAll("^\\s+", "");
|
||||
String rtrim = src.replaceAll("\\s+$", "");
|
||||
|
||||
|
@ -95,7 +96,7 @@ public class LTrimRTrim {
|
|||
|
||||
// Pattern matches() with replaceAll
|
||||
@Benchmark
|
||||
public boolean patternMatchesLTtrimRTrim() {
|
||||
private boolean patternMatchesLTtrimRTrim() {
|
||||
String ltrim = patternLtrim(src);
|
||||
String rtrim = patternRtrim(src);
|
||||
|
||||
|
@ -104,7 +105,7 @@ public class LTrimRTrim {
|
|||
|
||||
// Guava CharMatcher trimLeadingFrom / trimTrailingFrom
|
||||
@Benchmark
|
||||
public boolean guavaCharMatcher() {
|
||||
private boolean guavaCharMatcher() {
|
||||
String ltrim = CharMatcher.whitespace().trimLeadingFrom(src);
|
||||
String rtrim = CharMatcher.whitespace().trimTrailingFrom(src);
|
||||
|
||||
|
@ -113,9 +114,9 @@ public class LTrimRTrim {
|
|||
|
||||
// Apache Commons StringUtils containsIgnoreCase
|
||||
@Benchmark
|
||||
public boolean apacheCommonsStringUtils() {
|
||||
String ltrim = org.apache.commons.lang3.StringUtils.stripStart(src, null);
|
||||
String rtrim = org.apache.commons.lang3.StringUtils.stripEnd(src, null);
|
||||
private boolean apacheCommonsStringUtils() {
|
||||
String ltrim = StringUtils.stripStart(src, null);
|
||||
String rtrim = StringUtils.stripEnd(src, null);
|
||||
|
||||
return checkStrings(ltrim, rtrim);
|
||||
}
|
||||
|
|
|
@ -67,8 +67,8 @@ public class LTrimRTrimUnitTest {
|
|||
@Test
|
||||
public void givenString_whenCallingStringUtilsStripStartEnd_thenReturnsTrue() {
|
||||
// Use StringUtils containsIgnoreCase to avoid case insensitive issues
|
||||
String ltrim = org.apache.commons.lang3.StringUtils.stripStart(src, null);
|
||||
String rtrim = org.apache.commons.lang3.StringUtils.stripEnd(src, null);
|
||||
String ltrim = StringUtils.stripStart(src, null);
|
||||
String rtrim = StringUtils.stripEnd(src, null);
|
||||
|
||||
// Compare the Strings obtained and the expected
|
||||
Assert.assertTrue(ltrimResult.equalsIgnoreCase(ltrim));
|
||||
|
|
Loading…
Reference in New Issue