From d75786b28caf6eb618495b41210b9aede48672e0 Mon Sep 17 00:00:00 2001 From: dev-mlb <19797865+dev-mlb@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:54:15 -0400 Subject: [PATCH] errorprone :: search UngroupedOverloads & MixedMutabilityReturnType (#1002) --- .../emissary/util/search/ByteMatcher.java | 122 +++++++++--------- .../emissary/util/search/KeywordScanner.java | 3 +- 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/src/main/java/emissary/util/search/ByteMatcher.java b/src/main/java/emissary/util/search/ByteMatcher.java index 8e5deb3f0a..5cf172f365 100755 --- a/src/main/java/emissary/util/search/ByteMatcher.java +++ b/src/main/java/emissary/util/search/ByteMatcher.java @@ -71,6 +71,24 @@ public int length() { return mydata.length; } + /** + * Match pattern in the text + */ + public int indexOf(byte[] pattern) { + + return indexOf(pattern, 0); + + } + + /** + * Match pattern in the text + */ + public int indexOf(String pattern) { + + return indexOf(pattern.getBytes(), 0); + + } + /** * This method finds a pattern in the text and returns the offset * @@ -87,6 +105,15 @@ public int indexOf(byte[] pattern, int startOfs) { } + /** + * Match pattern in the text beginning at startOfs + */ + public int indexOf(String pattern, int startOfs) { + + return indexOf(pattern.getBytes(), startOfs); + + } + /** * This method finds a pattern in the text from {@code beginIndex} to {@code endIndex} and returns the offset * @@ -109,34 +136,41 @@ public int indexOf(byte[] pattern, int beginIndex, int endIndex) { } /** - * Match pattern in the text + * Match pattern in the text from {@code beginIndex} to {@code endIndex} and returns the offset + * + * @param pattern bytes to find + * @param beginIndex start index + * @param endIndex the index to stop searching at, exclusive + * + * @return position */ - public int indexOf(byte[] pattern) { + public int indexOf(String pattern, int beginIndex, int endIndex) { - return indexOf(pattern, 0); + return indexOf(pattern.getBytes(), beginIndex, endIndex); } /** - * This method finds a pattern in the text from {@code beginIndex} to {@code endIndex} and returns the offset list + * Match pattern in the text * * @param pattern bytes to find - * @param beginIndex start index - * @param endIndex the index to stop searching at, exclusive - * * @return list of positions */ - public List listIndexOf(byte[] pattern, int beginIndex, int endIndex) { + public List listIndexOf(byte[] pattern) { + return listIndexOf(pattern, 0); + } - // Impossible to find under these conditions - if (mydata == null || beginIndex > (mydata.length - pattern.length) || endIndex > mydata.length) { - return Collections.emptyList(); - } + /** + * Match pattern in the text + * + * @param pattern bytes to find + * @return list of positions + */ + public List listIndexOf(String pattern) { - return scanner.listIndexOf(pattern, beginIndex, endIndex); + return listIndexOf(pattern.getBytes(), 0); } - /** * This method finds a pattern in the text from {@code startOfs} and returns a list of offsets * @@ -153,47 +187,36 @@ public List listIndexOf(byte[] pattern, int startOfs) { } /** - * Match pattern in the text + * Match pattern in the text beginning at {@code startOfs} * * @param pattern bytes to find + * @param startOfs start index * @return list of positions */ - public List listIndexOf(byte[] pattern) { - return listIndexOf(pattern, 0); + public List listIndexOf(String pattern, int startOfs) { + + return listIndexOf(pattern.getBytes(), startOfs); } /** - * Match pattern in the text from {@code beginIndex} to {@code endIndex} and returns the offset + * This method finds a pattern in the text from {@code beginIndex} to {@code endIndex} and returns the offset list * * @param pattern bytes to find * @param beginIndex start index * @param endIndex the index to stop searching at, exclusive * - * @return position + * @return list of positions */ - public int indexOf(String pattern, int beginIndex, int endIndex) { + public List listIndexOf(byte[] pattern, int beginIndex, int endIndex) { - return indexOf(pattern.getBytes(), beginIndex, endIndex); + // Impossible to find under these conditions + if (mydata == null || beginIndex > (mydata.length - pattern.length) || endIndex > mydata.length) { + return Collections.emptyList(); + } + return scanner.listIndexOf(pattern, beginIndex, endIndex); } - /** - * Match pattern in the text beginning at startOfs - */ - public int indexOf(String pattern, int startOfs) { - - return indexOf(pattern.getBytes(), startOfs); - - } - - /** - * Match pattern in the text - */ - public int indexOf(String pattern) { - - return indexOf(pattern.getBytes(), 0); - - } /** * Match pattern in the text from {@code beginIndex} to {@code endIndex} and returns the offset list @@ -209,29 +232,6 @@ public List listIndexOf(String pattern, int beginIndex, int endIndex) { return listIndexOf(pattern.getBytes(), beginIndex, endIndex); } - /** - * Match pattern in the text beginning at {@code startOfs} - * - * @param pattern bytes to find - * @param startOfs start index - * @return list of positions - */ - public List listIndexOf(String pattern, int startOfs) { - - return listIndexOf(pattern.getBytes(), startOfs); - } - - /** - * Match pattern in the text - * - * @param pattern bytes to find - * @return list of positions - */ - public List listIndexOf(String pattern) { - - return listIndexOf(pattern.getBytes(), 0); - } - /** * Sort of like libc's strcmp, find if pattern matches this at offset */ diff --git a/src/main/java/emissary/util/search/KeywordScanner.java b/src/main/java/emissary/util/search/KeywordScanner.java index dab4e97159..32f0a7d416 100755 --- a/src/main/java/emissary/util/search/KeywordScanner.java +++ b/src/main/java/emissary/util/search/KeywordScanner.java @@ -3,7 +3,6 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.annotation.Nullable; @@ -158,7 +157,7 @@ public List listIndexOf(final byte[] patternArg, final int start) { public List listIndexOf(@Nullable final byte[] patternArg, final int start, final int stop) { List matches = new ArrayList<>(); if ((start >= this.dataLength) || (stop > this.dataLength) || (patternArg == null)) { - return Collections.emptyList(); + return List.of(); } int newStart = 0; int actualStart;