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

com.lmax.simpledsl.RepeatingGroup Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.lmax.simpledsl;

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

public class RepeatingGroup extends DslValues
{
    private final Map> valuesByName = new HashMap<>();

    public void addValue(final String name, final String value)
    {
        List values = getValues(name);
        if (values == null)
        {
            values = new ArrayList<>();
            valuesByName.put(name.toLowerCase(), values);
        }
        values.add(value);
    }

    @Override
    public boolean hasValue(final String name)
    {
        return valuesByName.containsKey(name.toLowerCase());
    }

    @Override
    public String value(final String name)
    {
        final String[] strings = values(name);
        return strings.length > 0 ? strings[0] : null;
    }

    @Override
    public String[] values(final String name)
    {
        final List values = getValues(name);
        return values != null ? values.toArray(new String[values.size()]) : new String[0];
    }

    private List getValues(final String name)
    {
        return name != null ? valuesByName.get(name.toLowerCase()) : null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy