diff --git a/core/src/main/java/com/riiablo/table/schema/MonStats.java b/core/src/main/java/com/riiablo/table/schema/MonStats.java index 309f29db..2e5791ce 100644 --- a/core/src/main/java/com/riiablo/table/schema/MonStats.java +++ b/core/src/main/java/com/riiablo/table/schema/MonStats.java @@ -1,5 +1,6 @@ package com.riiablo.table.schema; +import com.riiablo.table.annotation.ForeignKey; import com.riiablo.table.annotation.Format; import com.riiablo.table.annotation.PrimaryKey; import com.riiablo.table.annotation.Schema; @@ -12,6 +13,9 @@ public class MonStats { return NameStr; } + @ForeignKey("MonStatsEx") + public MonStats2 monstats2; + @PrimaryKey public String Id; public int hcIdx; diff --git a/core/src/test/java/com/riiablo/table/TablesTest.java b/core/src/test/java/com/riiablo/table/TablesTest.java index e90764f5..64f3b110 100644 --- a/core/src/test/java/com/riiablo/table/TablesTest.java +++ b/core/src/test/java/com/riiablo/table/TablesTest.java @@ -23,7 +23,7 @@ public class TablesTest extends RiiabloTest { public void monstats() { FileHandle handle = Gdx.files.internal("test/monstats.txt"); TsvParser parser = TsvParser.parse(handle.readBytes()); - MonStatsTable table = Tables.loadTsv(new MonStatsTable(), parser); + MonStatsTable table = Tables.loadTsv(TableManifest.monstats, parser); MonStats record = table.get(0); System.out.println(record.Id); System.out.println(record.hcIdx); @@ -34,7 +34,8 @@ public class TablesTest extends RiiabloTest { public void monstats_random_access() { FileHandle handle = Gdx.files.internal("test/monstats.txt"); TsvParser parser = TsvParser.parse(handle.readBytes()); - MonStatsTable table = Tables.loadTsv(new MonStatsTable(), parser); + TableManifest.monstats.parser = null; + MonStatsTable table = Tables.loadTsv(TableManifest.monstats, parser); MonStats record; record = table.get(54); System.out.println(record); diff --git a/core/src/test/java/com/riiablo/table/TsvParserTest.java b/core/src/test/java/com/riiablo/table/TsvParserTest.java index fa946dfc..5b2c4642 100644 --- a/core/src/test/java/com/riiablo/table/TsvParserTest.java +++ b/core/src/test/java/com/riiablo/table/TsvParserTest.java @@ -1,10 +1,15 @@ package com.riiablo.table; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; import org.junit.BeforeClass; import org.junit.Test; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.utils.ObjectIntMap; import com.riiablo.RiiabloTest; import com.riiablo.logger.Level; @@ -23,6 +28,27 @@ public class TsvParserTest extends RiiabloTest { System.out.println(parser.fieldNames()); } + @Test + public void monstats_field_indexes() { + FileHandle handle = Gdx.files.internal("test/monstats.txt"); + TsvParser parser = TsvParser.parse(handle.readBytes()); + List> fieldIds = new ArrayList<>(); + for (final ObjectIntMap.Entry entry : parser.fieldIds) { + // ObjectIntMap iterator reuses entry -- create new instances and copy data + fieldIds.add(new ObjectIntMap.Entry() {{ + key = entry.key; + value = entry.value; + }}); + } + Collections.sort(fieldIds, new Comparator>() { + @Override + public int compare(ObjectIntMap.Entry o1, ObjectIntMap.Entry o2) { + return Integer.compare(o1.value, o2.value); + } + }); + System.out.println(fieldIds); + } + @Test public void monstats_record_indexes() { FileHandle handle = Gdx.files.internal("test/monstats.txt"); diff --git a/table/annotation-processor/src/main/java/com/riiablo/table/annotation/ParserCodeGenerator.java b/table/annotation-processor/src/main/java/com/riiablo/table/annotation/ParserCodeGenerator.java index fd475730..fe5c40e1 100644 --- a/table/annotation-processor/src/main/java/com/riiablo/table/annotation/ParserCodeGenerator.java +++ b/table/annotation-processor/src/main/java/com/riiablo/table/annotation/ParserCodeGenerator.java @@ -67,6 +67,7 @@ final class ParserCodeGenerator extends CodeGenerator { int i = 0; final ParameterSpec parser = method.parameters.get(0); for (FieldElement field : schemaElement.fields) { + if (field.isForeignKey()) continue; for (String fieldName : field.fieldNames) { method.addStatement("$N[$L] = $N.$N($S)", fieldIds, i++, parser, "fieldId", fieldName); } diff --git a/table/annotation-processor/src/main/java/com/riiablo/table/annotation/SchemaProcessor.java b/table/annotation-processor/src/main/java/com/riiablo/table/annotation/SchemaProcessor.java index 279f8605..86951f44 100644 --- a/table/annotation-processor/src/main/java/com/riiablo/table/annotation/SchemaProcessor.java +++ b/table/annotation-processor/src/main/java/com/riiablo/table/annotation/SchemaProcessor.java @@ -202,7 +202,7 @@ finder: .builder( schema.tableClassName, schemaName.simpleName().toLowerCase(), - Modifier.PUBLIC, Modifier.FINAL) + Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) .initializer("new $T()", schema.tableClassName) .build(); tableManifest.addField(tableFieldSpec);