Skip to content

Commit

Permalink
errorprone :: search UngroupedOverloads & MixedMutabilityReturnType (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb authored Oct 29, 2024
1 parent 4aa1ff8 commit d75786b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 63 deletions.
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

0 comments on commit d75786b

Please sign in to comment.