mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-26 23:50:23 +07:00
Implemented foreign key into :core test case
Fixed issue where parser was generating code for foreign keys Added additional test case to output tsv field names and ids map Added MonStats2 foreign key to MonStats schema Generated TableManifest fields are now statically instanced
This commit is contained in:
parent
e0b4904efe
commit
7e7dfa0213
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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<ObjectIntMap.Entry<String>> fieldIds = new ArrayList<>();
|
||||
for (final ObjectIntMap.Entry<String> entry : parser.fieldIds) {
|
||||
// ObjectIntMap iterator reuses entry -- create new instances and copy data
|
||||
fieldIds.add(new ObjectIntMap.Entry<String>() {{
|
||||
key = entry.key;
|
||||
value = entry.value;
|
||||
}});
|
||||
}
|
||||
Collections.sort(fieldIds, new Comparator<ObjectIntMap.Entry<String>>() {
|
||||
@Override
|
||||
public int compare(ObjectIntMap.Entry<String> o1, ObjectIntMap.Entry<String> 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");
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user