mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-27 16:10:36 +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;
|
package com.riiablo.table.schema;
|
||||||
|
|
||||||
|
import com.riiablo.table.annotation.ForeignKey;
|
||||||
import com.riiablo.table.annotation.Format;
|
import com.riiablo.table.annotation.Format;
|
||||||
import com.riiablo.table.annotation.PrimaryKey;
|
import com.riiablo.table.annotation.PrimaryKey;
|
||||||
import com.riiablo.table.annotation.Schema;
|
import com.riiablo.table.annotation.Schema;
|
||||||
@ -12,6 +13,9 @@ public class MonStats {
|
|||||||
return NameStr;
|
return NameStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ForeignKey("MonStatsEx")
|
||||||
|
public MonStats2 monstats2;
|
||||||
|
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
public String Id;
|
public String Id;
|
||||||
public int hcIdx;
|
public int hcIdx;
|
||||||
|
@ -23,7 +23,7 @@ public class TablesTest extends RiiabloTest {
|
|||||||
public void monstats() {
|
public void monstats() {
|
||||||
FileHandle handle = Gdx.files.internal("test/monstats.txt");
|
FileHandle handle = Gdx.files.internal("test/monstats.txt");
|
||||||
TsvParser parser = TsvParser.parse(handle.readBytes());
|
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);
|
MonStats record = table.get(0);
|
||||||
System.out.println(record.Id);
|
System.out.println(record.Id);
|
||||||
System.out.println(record.hcIdx);
|
System.out.println(record.hcIdx);
|
||||||
@ -34,7 +34,8 @@ public class TablesTest extends RiiabloTest {
|
|||||||
public void monstats_random_access() {
|
public void monstats_random_access() {
|
||||||
FileHandle handle = Gdx.files.internal("test/monstats.txt");
|
FileHandle handle = Gdx.files.internal("test/monstats.txt");
|
||||||
TsvParser parser = TsvParser.parse(handle.readBytes());
|
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;
|
MonStats record;
|
||||||
record = table.get(54);
|
record = table.get(54);
|
||||||
System.out.println(record);
|
System.out.println(record);
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
package com.riiablo.table;
|
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.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
|
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||||
|
|
||||||
import com.riiablo.RiiabloTest;
|
import com.riiablo.RiiabloTest;
|
||||||
import com.riiablo.logger.Level;
|
import com.riiablo.logger.Level;
|
||||||
@ -23,6 +28,27 @@ public class TsvParserTest extends RiiabloTest {
|
|||||||
System.out.println(parser.fieldNames());
|
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
|
@Test
|
||||||
public void monstats_record_indexes() {
|
public void monstats_record_indexes() {
|
||||||
FileHandle handle = Gdx.files.internal("test/monstats.txt");
|
FileHandle handle = Gdx.files.internal("test/monstats.txt");
|
||||||
|
@ -67,6 +67,7 @@ final class ParserCodeGenerator extends CodeGenerator {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
final ParameterSpec parser = method.parameters.get(0);
|
final ParameterSpec parser = method.parameters.get(0);
|
||||||
for (FieldElement field : schemaElement.fields) {
|
for (FieldElement field : schemaElement.fields) {
|
||||||
|
if (field.isForeignKey()) continue;
|
||||||
for (String fieldName : field.fieldNames) {
|
for (String fieldName : field.fieldNames) {
|
||||||
method.addStatement("$N[$L] = $N.$N($S)", fieldIds, i++, parser, "fieldId", fieldName);
|
method.addStatement("$N[$L] = $N.$N($S)", fieldIds, i++, parser, "fieldId", fieldName);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ finder:
|
|||||||
.builder(
|
.builder(
|
||||||
schema.tableClassName,
|
schema.tableClassName,
|
||||||
schemaName.simpleName().toLowerCase(),
|
schemaName.simpleName().toLowerCase(),
|
||||||
Modifier.PUBLIC, Modifier.FINAL)
|
Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
|
||||||
.initializer("new $T()", schema.tableClassName)
|
.initializer("new $T()", schema.tableClassName)
|
||||||
.build();
|
.build();
|
||||||
tableManifest.addField(tableFieldSpec);
|
tableManifest.addField(tableFieldSpec);
|
||||||
|
Loading…
Reference in New Issue
Block a user