Example usage for org.apache.commons.collections MapIterator setValue

List of usage examples for org.apache.commons.collections MapIterator setValue

Introduction

In this page you can find the example usage for org.apache.commons.collections MapIterator setValue.

Prototype

Object setValue(Object value);

Source Link

Document

Sets the value associated with the current key (optional operation).

Usage

From source file:com.octo.captcha.engine.bufferedengine.manager.QuartzBufferedEngineManager.java

/**
 * @see com.octo.captcha.engine.bufferedengine.manager.BufferedEngineContainerManager#setLocaleRatio
 *//*from   w  w  w.j a v  a  2s.c o m*/
public synchronized void setLocaleRatio(String localeName, double ratio) {

    Locale locale = getLocaleFromName(localeName);

    MapIterator it = config.getLocaleRatio().mapIterator();
    boolean isSet = false;
    double coef = ratio;
    double oldValue = 0.0f;

    if (config.getLocaleRatio().containsKey(locale)) {
        oldValue = ((Double) config.getLocaleRatio().get(locale)).doubleValue();
        coef = ratio - oldValue;
    }

    while (it.hasNext()) {
        Locale tempLocale = (Locale) it.next();
        double value = ((Double) it.getValue()).doubleValue();
        if (locale.equals(tempLocale)) {
            it.setValue(new Double(coef + value));
            isSet = true;
        } else {
            if (coef < 0) {
                it.setValue(new Double(value - (coef * value / (1.0 - oldValue))));
            } else {
                it.setValue(new Double(value - (value * coef)));
            }
        }
    }

    //if Locale is not register yet
    if (!isSet) {
        config.getLocaleRatio().put(locale, new Double(ratio));
    }
}