use of pcgen.core.system.MigrationRule in project pcgen by PCGen.
the class MigrationLoader method parseFirstToken.
/**
* Parse the leading token and value to produce a starting MigrationRule object.
*
* @param firstToken The first token and value.
* @param lstLine The full line it came form, for error reporting purposes only.
* @param sourceURI The source path, for error reporting purposes only.
* @return A new MigrationRule, or null if the token could nto be parsed.
*/
MigrationRule parseFirstToken(String firstToken, String lstLine, URI sourceURI) {
final int idxColon = firstToken.indexOf(':');
if (idxColon <= 0 || idxColon == firstToken.length() - 1) {
// Missing colon or missing key or value
Logging.errorPrint("Illegal migration rule '" + lstLine + "' in " + sourceURI.toString());
return null;
}
String objTypeKey = "";
try {
objTypeKey = firstToken.substring(0, idxColon);
} catch (StringIndexOutOfBoundsException e) {
throw new UnreachableError(e);
}
MigrationRule.ObjectType objType;
try {
objType = ObjectType.valueOf(objTypeKey);
} catch (IllegalArgumentException e) {
Logging.errorPrint("Unknown object type for migration rule '" + lstLine + "' in " + sourceURI.toString());
return null;
}
String key = "";
try {
key = firstToken.substring(idxColon + 1);
} catch (StringIndexOutOfBoundsException e) {
throw new UnreachableError(e);
}
MigrationRule rule;
if (objType.isCategorized()) {
if (key.endsWith("|")) {
// Extra |
Logging.errorPrint("Invalid category|key of '" + firstToken + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
return null;
}
String[] keyParts = key.split("\\|");
if (keyParts.length < 2) {
// No | so missing a category
Logging.errorPrint("Missing category in '" + firstToken + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
return null;
}
if (keyParts.length > 2) {
// Extra |
Logging.errorPrint("Invalid category|key of '" + firstToken + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
return null;
}
if (StringUtils.isBlank(keyParts[0]) || keyParts[0].matches(invalidKeyPattern)) {
Logging.errorPrint("Invalid category of '" + keyParts[0] + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
return null;
}
if (StringUtils.isBlank(keyParts[1]) || keyParts[1].matches(invalidKeyPattern)) {
Logging.errorPrint("Invalid key of '" + keyParts[1] + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
return null;
}
rule = new MigrationRule(objType, keyParts[0], keyParts[1]);
} else {
String invalidKeyPat = objType == ObjectType.SOURCE ? invalidSourceKeyPattern : invalidKeyPattern;
if (StringUtils.isBlank(key) || key.matches(invalidKeyPat)) {
Logging.errorPrint("Invalid key of '" + key + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
return null;
}
rule = new MigrationRule(objType, key);
}
return rule;
}
use of pcgen.core.system.MigrationRule in project pcgen by PCGen.
the class MigrationUtils method getChangeList.
/**
* Retrieve a list of migration rules which should be applied based on the supplied filters.
* @param pcgVer The PCGen version the character was saved in.
* @param gameModeName The character's game mode.
* @param objectType The type of object being migrated.
* @return A list of migration rules.
*/
protected static List<MigrationRule> getChangeList(int[] pcgVer, String gameModeName, ObjectType objectType) {
List<MigrationRule> sourceChangeList = new ArrayList<>();
List<MigrationRule> migrationRuleList = SystemCollections.getUnmodifiableMigrationRuleList(gameModeName);
for (MigrationRule migrationRule : migrationRuleList) {
if (migrationRule.getObjectType() == objectType && migrationRule.changeAppliesToVer(pcgVer)) {
sourceChangeList.add(migrationRule);
}
}
return sourceChangeList;
}
use of pcgen.core.system.MigrationRule in project pcgen by PCGen.
the class MaxDevVerTokenTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
migrationRule = new MigrationRule(ObjectType.SOURCE, "OldKey");
token = new MaxDevVerToken();
gameModeName = "Pathfinder";
}
use of pcgen.core.system.MigrationRule in project pcgen by PCGen.
the class MaxVerTokenTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
migrationRule = new MigrationRule(ObjectType.SOURCE, "OldKey");
token = new MaxVerToken();
gameModeName = "Pathfinder";
}
use of pcgen.core.system.MigrationRule in project pcgen by PCGen.
the class MinVerTokenTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
migrationRule = new MigrationRule(ObjectType.SOURCE, "OldKey");
token = new MinVerToken();
gameModeName = "Pathfinder";
}
Aggregations