-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*error fix, suggested commands (similar commands and command not foun…
…d) added and bump to 4.2.2
- Loading branch information
Showing
13 changed files
with
183 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package me.koply.kcommando; | ||
|
||
import java.util.Arrays; | ||
|
||
class Util { | ||
/** | ||
* JaroWinklerDistance | ||
* Copied from https://commons.apache.org/sandbox/commons-text/jacoco/org.apache.commons.text.similarity/JaroWinklerDistance.java.html | ||
* apply method changed to similarity | ||
*/ | ||
static double similarity(final CharSequence left, final CharSequence right) { | ||
final double defaultScalingFactor = 0.1; | ||
final double percentageRoundValue = 100.0; | ||
|
||
if (left == null || right == null) { | ||
throw new IllegalArgumentException("Strings must not be null"); | ||
} | ||
|
||
int[] mtp = matches(left, right); | ||
double m = mtp[0]; | ||
if (m == 0) { | ||
return 0D; | ||
} | ||
double j = ((m / left.length() + m / right.length() + (m - mtp[1]) / m)) / 3; | ||
double jw = j < 0.7D ? j : j + Math.min(defaultScalingFactor, 1D / mtp[3]) * mtp[2] * (1D - j); | ||
return Math.round(jw * percentageRoundValue) / percentageRoundValue; | ||
} | ||
|
||
private static int[] matches(final CharSequence first, final CharSequence second) { | ||
CharSequence max, min; | ||
if (first.length() > second.length()) { | ||
max = first; | ||
min = second; | ||
} else { | ||
max = second; | ||
min = first; | ||
} | ||
int range = Math.max(max.length() / 2 - 1, 0); | ||
int[] matchIndexes = new int[min.length()]; | ||
Arrays.fill(matchIndexes, -1); | ||
boolean[] matchFlags = new boolean[max.length()]; | ||
int matches = 0; | ||
for (int mi = 0; mi < min.length(); mi++) { | ||
char c1 = min.charAt(mi); | ||
for (int xi = Math.max(mi - range, 0), xn = Math.min(mi + range + 1, max.length()); xi < xn; xi++) { | ||
if (!matchFlags[xi] && c1 == max.charAt(xi)) { | ||
matchIndexes[mi] = xi; | ||
matchFlags[xi] = true; | ||
matches++; | ||
break; | ||
} | ||
} | ||
} | ||
char[] ms1 = new char[matches]; | ||
char[] ms2 = new char[matches]; | ||
for (int i = 0, si = 0; i < min.length(); i++) { | ||
if (matchIndexes[i] != -1) { | ||
ms1[si] = min.charAt(i); | ||
si++; | ||
} | ||
} | ||
for (int i = 0, si = 0; i < max.length(); i++) { | ||
if (matchFlags[i]) { | ||
ms2[si] = max.charAt(i); | ||
si++; | ||
} | ||
} | ||
int transpositions = 0; | ||
for (int mi = 0; mi < ms1.length; mi++) { | ||
if (ms1[mi] != ms2[mi]) { | ||
transpositions++; | ||
} | ||
} | ||
int prefix = 0; | ||
for (int mi = 0; mi < min.length(); mi++) { | ||
if (first.charAt(mi) == second.charAt(mi)) { | ||
prefix++; | ||
} else { | ||
break; | ||
} | ||
} | ||
return new int[] { matches, transpositions / 2, prefix, max.length() }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/src/main/java/me/koply/kcommando/internal/SuggestionsCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.koply.kcommando.internal; | ||
|
||
import me.koply.kcommando.CommandInfo; | ||
|
||
import java.util.HashSet; | ||
|
||
public interface SuggestionsCallback<E> { | ||
void run(E e, HashSet<CommandInfo> similarCommands); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters