mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
Suggest flag name instead of value
This commit is contained in:
parent
050cf3edb3
commit
a5c43bb823
@ -202,7 +202,8 @@ public final class FlagCommand extends Command {
|
|||||||
final StringComparison<PlotFlag<?, ?>> stringComparison =
|
final StringComparison<PlotFlag<?, ?>> stringComparison =
|
||||||
new StringComparison<>(
|
new StringComparison<>(
|
||||||
arg,
|
arg,
|
||||||
GlobalFlagContainer.getInstance().getFlagMap().values()
|
GlobalFlagContainer.getInstance().getFlagMap().values(),
|
||||||
|
PlotFlag::getName
|
||||||
);
|
);
|
||||||
final String best = stringComparison.getBestMatch();
|
final String best = stringComparison.getBestMatch();
|
||||||
if (best != null) {
|
if (best != null) {
|
||||||
|
@ -28,6 +28,8 @@ package com.plotsquared.core.util;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String comparison library.
|
* String comparison library.
|
||||||
@ -37,6 +39,7 @@ public class StringComparison<T> {
|
|||||||
private T bestMatch;
|
private T bestMatch;
|
||||||
private double match = Integer.MAX_VALUE;
|
private double match = Integer.MAX_VALUE;
|
||||||
private T bestMatchObject;
|
private T bestMatchObject;
|
||||||
|
private final Function<T, String> toString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -45,17 +48,27 @@ public class StringComparison<T> {
|
|||||||
* @param objects Objects to compare
|
* @param objects Objects to compare
|
||||||
*/
|
*/
|
||||||
public StringComparison(String input, T[] objects) {
|
public StringComparison(String input, T[] objects) {
|
||||||
|
this(input, objects, Object::toString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringComparison(String input, T[] objects, Function<T, String> toString) {
|
||||||
|
this.toString = toString;
|
||||||
init(input, objects);
|
init(input, objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringComparison(String input, Collection<T> objects) {
|
public StringComparison(String input, Collection<T> objects) {
|
||||||
init(input, (T[]) objects.toArray());
|
this(input, objects, Object::toString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringComparison(String input, Collection<T> objects, Function<T, String> toString) {
|
||||||
|
this(input, (T[]) objects.toArray(), toString);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You should call init(...) when you are ready to get a String comparison value.
|
* You should call init(...) when you are ready to get a String comparison value.
|
||||||
*/
|
*/
|
||||||
public StringComparison() {
|
public StringComparison() {
|
||||||
|
this.toString = Object::toString;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,10 +135,7 @@ public class StringComparison<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getString(T o) {
|
public String getString(T o) {
|
||||||
if (o instanceof StringComparable) {
|
return this.toString.apply(o);
|
||||||
return ((StringComparable) o).getComparableString();
|
|
||||||
}
|
|
||||||
return o.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,12 +165,6 @@ public class StringComparison<T> {
|
|||||||
return new ComparisonResult(this.match, this.bestMatch);
|
return new ComparisonResult(this.match, this.bestMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface StringComparable {
|
|
||||||
|
|
||||||
String getComparableString();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The comparison result
|
* The comparison result
|
||||||
|
Loading…
Reference in New Issue
Block a user