StorageReaderFile passes record seq. number along with the record itself

This commit is contained in:
Maxmtg
2013-03-02 07:55:01 +00:00
parent bfeee22e12
commit 9286d5e943
7 changed files with 18 additions and 11 deletions

View File

@@ -180,7 +180,7 @@ public class BoosterData {
* @see forge.util.StorageReaderFile#read(java.lang.String)
*/
@Override
protected BoosterData read(String line) {
protected BoosterData read(String line, int i) {
final FileSection section = FileSection.parse(line, ":", "|");
int nC = section.getInt("Commons", 0);
int nU = section.getInt("Uncommons", 0);

View File

@@ -229,7 +229,7 @@ public final class CardBlock implements Comparable<CardBlock> {
* @see forge.util.StorageReaderFile#read(java.lang.String)
*/
@Override
protected CardBlock read(String line) {
protected CardBlock read(String line, int i) {
final String[] sParts = line.trim().split("\\|");
String name = null;

View File

@@ -208,9 +208,9 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
}
@Override
protected CardEdition read(String line) {
protected CardEdition read(String line, int i) {
FileSection section = FileSection.parse(line, ":", "|");
int index = section.getInt("index", -1);
int index = 1+i;
String code2 = section.get("code2");
String code = section.get("code3");
String type = section.get("type");

View File

@@ -57,7 +57,7 @@ public class FatPackData {
* @see forge.util.StorageReaderFile#read(java.lang.String)
*/
@Override
protected FatPackData read(String line) {
protected FatPackData read(String line, int i) {
final FileSection section = FileSection.parse(line, ":", "|");
int nBoosters = section.getInt("Boosters", 0);
int nLand = section.getInt("BasicLands", 0);

View File

@@ -93,7 +93,7 @@ public final class FormatCollection extends StorageView<GameFormat> {
* @see forge.util.StorageReaderFile#read(java.lang.String)
*/
@Override
protected GameFormat read(String line) {
protected GameFormat read(String line, int i) {
final List<String> sets = new ArrayList<String>(); // default: all sets allowed
final List<String> bannedCards = new ArrayList<String>(); // default:
// nothing
@@ -101,7 +101,7 @@ public final class FormatCollection extends StorageView<GameFormat> {
FileSection section = FileSection.parse(line, ":", "|");
String name = section.get("name");
int index = section.getInt("index", 0);
int index = 1 + i;
String strSets = section.get("sets");
if ( null != strSets ) {
sets.addAll(Arrays.asList(strSets.split(", ")));

View File

@@ -24,6 +24,7 @@ import java.util.List;
import com.google.common.base.Function;
import forge.quest.data.GameFormatQuest;
import forge.util.FileSection;
import forge.util.storage.StorageReaderFile;
/**
@@ -121,7 +122,7 @@ public class QuestWorld implements Comparable<QuestWorld>{
* @see forge.util.StorageReaderFile#read(java.lang.String)
*/
@Override
protected QuestWorld read(String line) {
protected QuestWorld read(String line, int i) {
String useName = null;
String useDir = null;
GameFormatQuest useFormat = null;
@@ -129,9 +130,13 @@ public class QuestWorld implements Comparable<QuestWorld>{
final List<String> sets = new ArrayList<String>();
final List<String> bannedCards = new ArrayList<String>(); // if both empty, no format
// This is what you need to use here =>
// FileSection.parse(line, ":", "|");
final String[] sParts = line.trim().split("\\|");
for (final String sPart : sParts) {
final String[] kv = sPart.split(":", 2);
final String key = kv[0].toLowerCase();
if ("name".equals(key)) {

View File

@@ -70,12 +70,13 @@ public abstract class StorageReaderFile<T> implements IItemReader<T> {
public Map<String, T> readAll() {
final Map<String, T> result = new TreeMap<String, T>();
int idx = 0;
for (final String s : FileUtil.readFile(this.file)) {
if (!this.lineContainsObject(s)) {
continue;
}
final T item = this.read(s);
final T item = this.read(s, idx);
if (null == item) {
final String msg = "An object stored in " + this.file.getPath()
+ " failed to load.\nPlease submit this as a bug with the mentioned file attached.";
@@ -83,6 +84,7 @@ public abstract class StorageReaderFile<T> implements IItemReader<T> {
continue;
}
idx++;
result.put(this.keySelector.apply(item), item);
}
@@ -95,8 +97,8 @@ public abstract class StorageReaderFile<T> implements IItemReader<T> {
* @param line
* the line
* @return the t
*/
protected abstract T read(String line);
*/
protected abstract T read(String line, int idx);
/**
* Line contains object.