I'm trying to implement a CircularSuffixArray class in Java (Suffix array Wikipedia). In my approach, I created an inner class that implements Comparator
to compare the first char of each suffix and, if they are equals, recursively call compare
for the next characters. Something like this:
public class CircularSuffixArray {
private String string;
private int[] sortSuffixes;
private class SuffixesOrder implements Comparator<Integer> {
public int compare(Integer i, Integer j) {
if ((length() - 1) < i) return 1;
else if ((length() - 1) < j) return -1;
if (string.charAt(i) != string.charAt(j))
return compare(string.charAt(i), string.charAt(j));
else
return compare(i+1, j+1);
}
private int compare(char a, char b) {
return b - a;
}
}
private Comparator<Integer> suffixesOrder() {
return new SuffixesOrder();
}
// circular suffix array of s
public CircularSuffixArray(String s) {
if (s == null) throw new NullPointerException("null argument");
string = s;
sortSuffixes = new int[length()];
for (int i = 0; i < length(); i++)
sortSuffixes[i] = (length() - 1) - i;
Arrays.sort(sortSuffixes, suffixesOrder());
}
}
But when I tried to compile it, I get this error:
CircularSuffixArray.java:35: error: no suitable method found for sort(int[],Comparator<Integer>) Arrays.sort(sortSuffixes, suffixesOrder());
Call you tell me:
- First of all, if the implementation is ok (I now that there are a lot of code releated but I want to try by myself)
- Regardless the "algorithm" is wrong, can you help me to figured out why I get this error?