Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errorprone :: search UngroupedOverloads & MixedMutabilityReturnType #1002

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 61 additions & 61 deletions src/main/java/emissary/util/search/ByteMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand All @@ -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<Integer> listIndexOf(byte[] pattern, int beginIndex, int endIndex) {
public List<Integer> 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<Integer> 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
*
Expand All @@ -153,47 +187,36 @@ public List<Integer> 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<Integer> listIndexOf(byte[] pattern) {
return listIndexOf(pattern, 0);
public List<Integer> 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<Integer> 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
Expand All @@ -209,29 +232,6 @@ public List<Integer> 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<Integer> 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<Integer> listIndexOf(String pattern) {

return listIndexOf(pattern.getBytes(), 0);
}

/**
* Sort of like libc's strcmp, find if pattern matches this at offset
*/
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/emissary/util/search/KeywordScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -158,7 +157,7 @@ public List<Integer> listIndexOf(final byte[] patternArg, final int start) {
public List<Integer> listIndexOf(@Nullable final byte[] patternArg, final int start, final int stop) {
List<Integer> matches = new ArrayList<>();
if ((start >= this.dataLength) || (stop > this.dataLength) || (patternArg == null)) {
return Collections.emptyList();
return List.of();
}
int newStart = 0;
int actualStart;
Expand Down