Search in sources :

Example 1 with Value

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();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IdentityHashMap(java.util.IdentityHashMap) Value(com.googlecode.aviator.Options.Value) AviatorFunction(com.googlecode.aviator.runtime.type.AviatorFunction) HashSet(java.util.HashSet)

Aggregations

Value (com.googlecode.aviator.Options.Value)1 AviatorFunction (com.googlecode.aviator.runtime.type.AviatorFunction)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 Set (java.util.Set)1