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

com.payneteasy.superfly.client.MergingActionDescriptionCollector Maven / Gradle / Ivy

There is a newer version: 1.7-32
Show newest version
package com.payneteasy.superfly.client;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.payneteasy.superfly.api.ActionDescription;
import com.payneteasy.superfly.client.exception.CollectionException;

/**
 * ActionDescriptionCollector implementation which takes outputs from several
 * collectors and merges them. First collector in the list has the highest
 * priority.
 * 
 * @author Roman Puchkovskiy
 */
public class MergingActionDescriptionCollector implements
        ActionDescriptionCollector {

    private ActionDescriptionCollector[] collectors;

    public void setCollectors(ActionDescriptionCollector[] collectors) {
        this.collectors = collectors;
    }

    public List collect() throws CollectionException {
        Map descriptionsMap = new HashMap();
        for (ActionDescriptionCollector collector : collectors) {
            List descriptions = collector.collect();
            for (ActionDescription description : descriptions) {
                if (!descriptionsMap.containsKey(description.getName())) {
                    descriptionsMap.put(description.getName(), description);
                }
            }
        }

        return new ArrayList(descriptionsMap.values());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy