Added some default date handling for gameformats

This commit is contained in:
austinio7116
2018-04-14 20:48:57 +01:00
committed by maustin
parent 71647e5bc9
commit a36b2ed13e

View File

@@ -61,6 +61,7 @@ public class GameFormat implements Comparable<GameFormat> {
protected boolean restrictedLegendary = false; protected boolean restrictedLegendary = false;
private Date effectiveDate; private Date effectiveDate;
private final static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); private final static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
private final static String DEFAULTDATE = "1990-01-01";
protected final transient List<String> allowedSetCodes_ro; protected final transient List<String> allowedSetCodes_ro;
protected final transient List<String> bannedCardNames_ro; protected final transient List<String> bannedCardNames_ro;
@@ -73,10 +74,10 @@ public class GameFormat implements Comparable<GameFormat> {
private final int index; private final int index;
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) { public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) {
this(fName, parseDate("1990-01-01"), sets, bannedCards, null, false, null, null, 0, FormatType.Custom, FormatSubType.Custom); this(fName, parseDate(DEFAULTDATE), sets, bannedCards, null, false, null, null, 0, FormatType.Custom, FormatSubType.Custom);
} }
public static final GameFormat NoFormat = new GameFormat("(none)", parseDate("1990-01-01") , null, null, null, false public static final GameFormat NoFormat = new GameFormat("(none)", parseDate(DEFAULTDATE) , null, null, null, false
, null, null, Integer.MAX_VALUE, FormatType.Custom, FormatSubType.Custom); , null, null, Integer.MAX_VALUE, FormatType.Custom, FormatSubType.Custom);
public GameFormat(final String fName, final Date effectiveDate, final Iterable<String> sets, final List<String> bannedCards, public GameFormat(final String fName, final Date effectiveDate, final Iterable<String> sets, final List<String> bannedCards,
@@ -271,7 +272,9 @@ public class GameFormat implements Comparable<GameFormat> {
} }
} }
if (formatType.equals(FormatType.Historic)){ if (formatType.equals(FormatType.Historic)){
return effectiveDate.compareTo(other.effectiveDate); if(effectiveDate!=other.effectiveDate) {//for matching dates or default dates default to name sorting
return effectiveDate.compareTo(other.effectiveDate);
}
} }
return name.compareTo(other.name); return name.compareTo(other.name);
//return index - other.index; //return index - other.index;
@@ -313,6 +316,9 @@ public class GameFormat implements Comparable<GameFormat> {
} }
Integer idx = section.getInt("order"); Integer idx = section.getInt("order");
Date date = parseDate(section.get("effectivedate")); Date date = parseDate(section.get("effectivedate"));
if (date == null){
date = parseDate(DEFAULTDATE);
}
String strSets = section.get("sets"); String strSets = section.get("sets");
if ( null != strSets ) { if ( null != strSets ) {
sets = Arrays.asList(strSets.split(", ")); sets = Arrays.asList(strSets.split(", "));