
org.etlunit.feature.RuntimeOption Maven / Gradle / Ivy
The newest version!
package org.etlunit.feature;
public class RuntimeOption
{
private String name;
private Boolean enabled;
private String stringValue;
private Integer integerValue;
private RuntimeOptionDescriptor descriptor;
private Feature feature;
private RuntimeOptionDescriptor.option_type type;
public RuntimeOption(String name)
{
this.name = name;
}
public RuntimeOption(String name, Boolean enabled)
{
this.name = name;
this.enabled = enabled;
validate();
}
public RuntimeOption(String name, String stringValue)
{
this.name = name;
this.stringValue = stringValue;
validate();
}
public RuntimeOption(String name, Integer integerValue)
{
this.name = name;
this.integerValue = integerValue;
validate();
}
public RuntimeOptionDescriptor getDescriptor()
{
return descriptor;
}
public void setDescriptor(RuntimeOptionDescriptor descriptor)
{
this.descriptor = descriptor;
if (type == null)
{
type = descriptor.getOptionType();
}
else if (type != descriptor.getOptionType())
{
throw new IllegalArgumentException("Option type mismatch - " + name + " - " + descriptor.getName());
}
}
public Feature getFeature()
{
return feature;
}
public void setFeature(Feature feature)
{
this.feature = feature;
}
public void setEnabled(Boolean enabled)
{
if (type != null && type != RuntimeOptionDescriptor.option_type.bool)
{
throw new IllegalArgumentException("Cannot assign boolean value to non-boolean option - " + name + " - " + type);
}
else
{
type = RuntimeOptionDescriptor.option_type.bool;
}
this.enabled = enabled;
}
public void setStringValue(String stringValue)
{
if (type != null && type != RuntimeOptionDescriptor.option_type.string)
{
throw new IllegalArgumentException("Cannot assign string value to non-string option - " + name + " - " + type);
}
else
{
type = RuntimeOptionDescriptor.option_type.string;
}
this.stringValue = stringValue;
}
public void setIntegerValue(Integer integerValue)
{
if (type != null && type != RuntimeOptionDescriptor.option_type.integer)
{
throw new IllegalArgumentException("Cannot assign integer value to non-integer option - " + name + " - " + type);
}
else
{
type = RuntimeOptionDescriptor.option_type.integer;
}
this.integerValue = integerValue;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public boolean isEnabled()
{
if (type != RuntimeOptionDescriptor.option_type.bool)
{
throw new UnsupportedOperationException();
}
return enabled.booleanValue();
}
public int getIntegerValue()
{
if (type != RuntimeOptionDescriptor.option_type.integer)
{
throw new UnsupportedOperationException();
}
return integerValue.intValue();
}
public String getStringValue()
{
if (type != RuntimeOptionDescriptor.option_type.string)
{
throw new UnsupportedOperationException();
}
return stringValue;
}
public void validate()
{
if (enabled != null)
{
type = RuntimeOptionDescriptor.option_type.bool;
}
else if (integerValue != null)
{
type = RuntimeOptionDescriptor.option_type.integer;
}
else if (stringValue != null)
{
type = RuntimeOptionDescriptor.option_type.string;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy