Refactor to allow items to be added after first load

This commit is contained in:
md678685 2018-08-25 18:38:50 +01:00
parent 303aa77901
commit 05fcb7b1aa
3 changed files with 31 additions and 5 deletions

View File

@ -98,8 +98,13 @@ public class FlatItemDbProvider extends ItemDbProvider {
return null;
}
private void resetDb() {
primaryNames.clear();
names.clear();
}
@Override
public void rebuild(List<String> lines) {
public void addFrom(List<String> lines) {
String json = lines.stream()
.filter(line -> !line.startsWith("#"))
.collect(Collectors.joining("\n"));
@ -124,6 +129,12 @@ public class FlatItemDbProvider extends ItemDbProvider {
}
}
@Override
public void rebuild(List<String> lines) {
resetDb();
addFrom(lines);
}
private void addAlias(String primaryName, String alias) {
List<String> aliasList;

View File

@ -174,13 +174,15 @@ public class LegacyItemDbProvider extends ItemDbProvider {
return nameList;
}
@Override
public void rebuild(List<String> lines) {
private void resetDb() {
durabilities.clear();
items.clear();
names.clear();
primaryNames.clear();
}
@Override
public void addFrom(List<String> lines) {
lines.stream()
.filter(line -> line.length() > 0 && !(line.charAt(0) == '#'))
.map(this::parseLine)
@ -192,6 +194,12 @@ public class LegacyItemDbProvider extends ItemDbProvider {
}
}
@Override
public void rebuild(List<String> lines) {
resetDb();
addFrom(lines);
}
private ItemData parseLine(String line) {
String itemName = null;
int numeric = -1;

View File

@ -20,9 +20,16 @@ public abstract class ItemDbProvider implements Provider {
private PotionMetaProvider potionMetaProvider;
/**
* Rebuild the item database, using the given lines of a file.
* Populate the item database using the given lines of data.
*
* @param lines The lines of the file from which the database should be built.
* @param lines The lines of data from which the database should be populated
*/
public abstract void addFrom(List<String> lines);
/**
* Reset the database and rebuild it from the given lines of data.
*
* @param lines The lines of the file from which the database should be built
*/
public abstract void rebuild(List<String> lines);