org.mvel2.integration.impl.SimpleVariableResolverFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-realer Show documentation
Show all versions of virtdata-lib-realer Show documentation
With inspiration from other libraries
package org.mvel2.integration.impl;
import org.mvel2.integration.VariableResolver;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class SimpleVariableResolverFactory extends BaseVariableResolverFactory {
public SimpleVariableResolverFactory(Map variables) {
for (Map.Entry entry : variables.entrySet()) {
createVariable(entry.getKey(), entry.getValue());
}
}
public VariableResolver createVariable(String name, Object value) {
if (variableResolvers == null) variableResolvers = new HashMap(5, 0.6f);
SimpleValueResolver svr = new SimpleValueResolver(value);
variableResolvers.put(name, svr);
return svr;
}
public VariableResolver createIndexedVariable(int index, String name, Object value) {
return null;
}
public VariableResolver createVariable(String name, Object value, Class> type) {
if (variableResolvers == null) variableResolvers = new HashMap(5, 0.6f);
SimpleSTValueResolver svr = new SimpleSTValueResolver(value, type);
variableResolvers.put(name, svr);
return svr;
}
public VariableResolver createIndexedVariable(int index, String name, Object value, Class> typee) {
return null;
}
public VariableResolver setIndexedVariableResolver(int index, VariableResolver variableResolver) {
return null;
}
public boolean isTarget(String name) {
return variableResolvers.containsKey(name);
}
public boolean isResolveable(String name) {
return variableResolvers.containsKey(name) || (nextFactory != null && nextFactory.isResolveable(name));
}
@Override
public VariableResolver getVariableResolver(String name) {
VariableResolver vr = variableResolvers.get(name);
return vr != null ? vr : (nextFactory == null ? null : nextFactory.getVariableResolver(name));
}
public Set getKnownVariables() {
return variableResolvers.keySet();
}
public int variableIndexOf(String name) {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean isIndexedFactory() {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
}