mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
lint: DeckValidator
This commit is contained in:
parent
e851e04906
commit
9f917472fc
1 changed files with 23 additions and 28 deletions
|
|
@ -11,7 +11,7 @@ import java.util.stream.Collectors;
|
||||||
*/
|
*/
|
||||||
public abstract class DeckValidator implements Serializable {
|
public abstract class DeckValidator implements Serializable {
|
||||||
|
|
||||||
public static final HashSet<String> MAIN_BASIC_LAND_NAMES = new HashSet<>(Arrays.asList(
|
public static final Set<String> MAIN_BASIC_LAND_NAMES = new HashSet<>(Arrays.asList(
|
||||||
"Plains",
|
"Plains",
|
||||||
"Island",
|
"Island",
|
||||||
"Swamp",
|
"Swamp",
|
||||||
|
|
@ -19,7 +19,7 @@ public abstract class DeckValidator implements Serializable {
|
||||||
"Forest"
|
"Forest"
|
||||||
));
|
));
|
||||||
|
|
||||||
public static final HashSet<String> ADDITIONAL_BASIC_LAND_NAMES = new HashSet<>(Arrays.asList(
|
public static final Set<String> ADDITIONAL_BASIC_LAND_NAMES = new HashSet<>(Arrays.asList(
|
||||||
"Wastes",
|
"Wastes",
|
||||||
"Snow-Covered Plains",
|
"Snow-Covered Plains",
|
||||||
"Snow-Covered Island",
|
"Snow-Covered Island",
|
||||||
|
|
@ -29,9 +29,9 @@ public abstract class DeckValidator implements Serializable {
|
||||||
"Snow-Covered Wastes"
|
"Snow-Covered Wastes"
|
||||||
));
|
));
|
||||||
|
|
||||||
public static final HashSet<String> ALL_BASIC_LAND_NAMES = new HashSet<>();
|
public static final Set<String> ALL_BASIC_LAND_NAMES = new HashSet<>();
|
||||||
|
|
||||||
{
|
static {
|
||||||
ALL_BASIC_LAND_NAMES.addAll(MAIN_BASIC_LAND_NAMES);
|
ALL_BASIC_LAND_NAMES.addAll(MAIN_BASIC_LAND_NAMES);
|
||||||
ALL_BASIC_LAND_NAMES.addAll(ADDITIONAL_BASIC_LAND_NAMES);
|
ALL_BASIC_LAND_NAMES.addAll(ADDITIONAL_BASIC_LAND_NAMES);
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +57,7 @@ public abstract class DeckValidator implements Serializable {
|
||||||
protected String shortName;
|
protected String shortName;
|
||||||
protected List<DeckValidatorError> errorsList = new ArrayList<>();
|
protected List<DeckValidatorError> errorsList = new ArrayList<>();
|
||||||
|
|
||||||
public DeckValidator(String name, String shortName) {
|
protected DeckValidator(String name, String shortName) {
|
||||||
setName(name, shortName);
|
setName(name, shortName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,15 +94,11 @@ public abstract class DeckValidator implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get errors list sorted by error type and texts
|
* Get errors list sorted by error type and texts
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public List<DeckValidatorError> getErrorsListSorted(int maxErrors) {
|
public List<DeckValidatorError> getErrorsListSorted(int maxErrors) {
|
||||||
List<DeckValidatorError> list = new ArrayList<>(this.getErrorsList());
|
List<DeckValidatorError> list = new ArrayList<>(this.getErrorsList());
|
||||||
|
|
||||||
list.sort(new Comparator<DeckValidatorError>() {
|
list.sort((e1, e2) -> {
|
||||||
@Override
|
|
||||||
public int compare(DeckValidatorError e1, DeckValidatorError e2) {
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
// sort by error type
|
// sort by error type
|
||||||
|
|
@ -121,7 +117,6 @@ public abstract class DeckValidator implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (list.size() <= maxErrors) {
|
if (list.size() <= maxErrors) {
|
||||||
|
|
@ -163,7 +158,7 @@ public abstract class DeckValidator implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPartlyValid() {
|
public boolean isPartlyValid() {
|
||||||
return errorsList.size() == 0 || !errorsList.stream().anyMatch(e -> !e.getErrorType().isPartlyLegal());
|
return errorsList.isEmpty() || errorsList.stream().allMatch(e -> e.getErrorType().isPartlyLegal());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void countCards(Map<String, Integer> counts, Collection<Card> cards) {
|
protected void countCards(Map<String, Integer> counts, Collection<Card> cards) {
|
||||||
|
|
@ -184,7 +179,7 @@ public abstract class DeckValidator implements Serializable {
|
||||||
|
|
||||||
public abstract int getSideboardMinSize();
|
public abstract int getSideboardMinSize();
|
||||||
|
|
||||||
protected static final int getMaxCopies(String name, int defaultAmount) {
|
protected static int getMaxCopies(String name, int defaultAmount) {
|
||||||
return maxCopiesMap.getOrDefault(name, defaultAmount);
|
return maxCopiesMap.getOrDefault(name, defaultAmount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue