All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cloudbees.api.config.ParameterList Maven / Gradle / Ivy

There is a newer version: 1.5.9
Show newest version
package com.cloudbees.api.config;

import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.thoughtworks.xstream.converters.collections.CollectionConverter;

import java.lang.Override;import java.lang.String;import java.util.AbstractSet;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;

/**
 * {@code Map} that's actually stored as
 * List of {@link ParameterSettings}.
 *
 * In this way, we can get the desired XML format and the desired
 * user view.
 *
 * @param 
 *     This pointless parameterization is to work around a bug in XStream.
 *     Unless the collection type is explicitly parameterized, it will fail
 *     to compute the correct item type.
 *
 * @author Kohsuke Kawaguchi
 */
@XStreamConverter(CollectionConverter.class)
class ParameterList extends ArrayList {
    private final List listView = this;

    /**
     * Map view over a list of {@link ParameterSettings}.
     */
    private final ParameterMap mapView = new ParameterMap() {
        @Override
        public Set> entrySet() {
            return setView;
        }

        @Override
        public String put(String key, String value) {
            for (ParameterSettings p : listView) {
                if (p.getName().equals(key)) {
                    return p.setValue(value);
                }
            }
            listView.add(new ParameterSettings(key,value));
            return null;
        }
    };

    /**
     * Set view
     */
    private final AbstractSet> setView = new AbstractSet>() {
        @Override
        public Iterator> iterator() {
            return (Iterator) listView.iterator();
        }

        @Override
        public int size() {
            return listView.size();
        }
    };

    public ParameterMap asMap() {
        return mapView;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy