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

com.deevvi.device.detector.engine.loader.MapLoader Maven / Gradle / Ivy

Go to download

The aim of this library is to fetch as much as possible information from a user-agent string.

There is a newer version: 1.14.0
Show newest version
package com.deevvi.device.detector.engine.loader;

import com.deevvi.device.detector.model.exceptions.DeviceDetectorException;
import com.google.common.collect.Lists;

import java.util.List;
import java.util.Map;

public interface MapLoader extends Loader {

    /**
     * Converts the YAML file content into a list of objects
     *
     * @return list of {@link T} objects.
     */
    default List streamToList() {

        Object rawObject = loadFromFile();
        List list = Lists.newArrayList();
        if (!(rawObject instanceof Map)) {
            throw new DeviceDetectorException("Unable to convert input to list.");
        }
        ((Map) rawObject).forEach((key, val) -> list.add(toObject((key instanceof String ? (String) key : String.valueOf(key)), val)));
        return list;
    }

    /**
     * Converts the raw object to a T
     *
     * @param key   key of map entry read from file.
     * @param value plain value of object read from file.
     * @return raw object converted to T
     */
    T toObject(String key, Object value);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy