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

com.jparams.object.builder.provider.SortedMapProvider Maven / Gradle / Ivy

There is a newer version: 2.3.1
Show newest version
package com.jparams.object.builder.provider;

import java.util.SortedMap;
import java.util.TreeMap;

import com.jparams.object.builder.Context;
import com.jparams.object.builder.type.Type;

public class SortedMapProvider implements Provider
{
    @Override
    public boolean supports(final Type type)
    {
        return type.getJavaType().isAssignableFrom(SortedMap.class);
    }

    @Override
    public SortedMap provide(final Context context)
    {
        final TreeMap map = new TreeMap<>();

        if (context.getPath().getType().getGenerics().size() < 2)
        {
            context.logWarning("No generics found. Could not populate Map");
            return map;
        }

        final Type keyType = context.getPath().getType().getGenerics().get(0);
        final Type valueType = context.getPath().getType().getGenerics().get(1);
        final Object key = context.createChild("[0.key]", keyType);
        final Object value = context.createChild("[0.value]", valueType);
        map.put(key, value);
        return map;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy