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

io.keen.client.java.RequestParameterCollection Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
package io.keen.client.java;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * A helper class for dealing with collections of jsonifiable parameters.
 * Constructs a jsonifiable collection of the jsonifiable parameters for each sub-parameter.
 * 
 * @author baumatron, masojus
 * @param  The type of RequestParameter
 */
class RequestParameterCollection>
    extends RequestParameter>
    implements Iterable {

    private final Collection parameters;

    RequestParameterCollection(Collection parameters) {
        if (null == parameters || parameters.isEmpty()) {
            throw new IllegalArgumentException("'parameters' is a required parameter and must not be empty.");
        }

        this.parameters = parameters;
    }

    @Override
    Collection constructParameterRequestArgs() {
        // Each of these contained Object instances is generally either another Collection or
        // a Map depending upon whether the corresponding JSON should be a nested
        // object or a JSON array of objects/values.
        Collection requestArgList = new LinkedList();

        for (RequestParameterT parameter : this.parameters) {
            requestArgList.add(parameter.constructParameterRequestArgs());
        }

        return requestArgList;
    }

    @Override
    public Iterator iterator() {
        Collection parametersIterable =
                Collections.unmodifiableCollection(this.parameters);

        return parametersIterable.iterator();
    }
}