use of com.googlecode.aviator.Options.Value in project aviatorscript by killme2008.
the class AviatorEvaluatorInstance method setOption.
/**
* Adds a evaluator option
*
* @since 2.3.4
* @see Options
* @param opt
* @param val
*/
public void setOption(final Options opt, final Object val) {
if (opt == null || val == null) {
throw new IllegalArgumentException("Option and value should not be null.");
}
if (!opt.isValidValue(val)) {
throw new IllegalArgumentException("Invalid value for option:" + opt.name());
}
Map<Options, Value> newOpts = new IdentityHashMap<>(this.options);
newOpts.put(opt, opt.intoValue(val));
if (opt == Options.FEATURE_SET) {
Set<Feature> oldSet = new HashSet<>(getFeatures());
@SuppressWarnings("unchecked") Set<Feature> newSet = (Set<Feature>) val;
if (oldSet.removeAll(newSet)) {
// removed functions that feature is disabled.
for (Feature feat : oldSet) {
for (AviatorFunction fn : feat.getFunctions()) {
this.removeFunction(fn);
}
}
}
}
this.options = newOpts;
if (opt == Options.FEATURE_SET) {
loadFeatureFunctions();
}
}
Aggregations