mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Create MetaPreprocessor abstract class
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.dfsek.terra.config.preprocessor;
|
||||
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.preprocessor.ValuePreprocessor;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class MetaPreprocessor<A extends Annotation> implements ValuePreprocessor<A> {
|
||||
private final Map<String, Configuration> configs;
|
||||
|
||||
public MetaPreprocessor(Map<String, Configuration> configs) {
|
||||
this.configs = configs;
|
||||
}
|
||||
|
||||
protected Object getMetaValue(String meta) {
|
||||
int sep = meta.indexOf(':');
|
||||
String file = meta.substring(0, sep);
|
||||
String key = meta.substring(sep + 1);
|
||||
|
||||
if(!configs.containsKey(file)) throw new LoadException("Cannot fetch metavalue: No such config: " + file);
|
||||
|
||||
Configuration config = configs.get(file);
|
||||
|
||||
if(!config.contains(key)) {
|
||||
throw new LoadException("Cannot fetch metavalue: No such key " + key + " in configuration " + config.getName());
|
||||
}
|
||||
|
||||
return config.get(key);
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MetaValuePreprocessor implements ValuePreprocessor<Meta> {
|
||||
private final Map<String, Configuration> configs;
|
||||
public class MetaValuePreprocessor extends MetaPreprocessor<Meta> {
|
||||
|
||||
public MetaValuePreprocessor(Map<String, Configuration> configs) {
|
||||
this.configs = configs;
|
||||
super(configs);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -68,20 +67,4 @@ public class MetaValuePreprocessor implements ValuePreprocessor<Meta> {
|
||||
|
||||
return Result.noOp();
|
||||
}
|
||||
|
||||
private Object getMetaValue(String meta) {
|
||||
int sep = meta.indexOf(':');
|
||||
String file = meta.substring(0, sep);
|
||||
String key = meta.substring(sep + 1);
|
||||
|
||||
if(!configs.containsKey(file)) throw new LoadException("Cannot fetch metavalue: No such config: " + file);
|
||||
|
||||
Configuration config = configs.get(file);
|
||||
|
||||
if(!config.contains(key)) {
|
||||
throw new LoadException("Cannot fetch metavalue: No such key " + key + " in configuration " + config.getName());
|
||||
}
|
||||
|
||||
return config.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user