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

com.urbanairship.api.common.parse.MapFieldParserRegistry Maven / Gradle / Ivy

There is a newer version: 9.4.2
Show newest version
/*
 * Copyright (c) 2013-2016.  Urban Airship and Contributors
 */

package com.urbanairship.api.common.parse;

import java.util.Map;
import java.util.Optional;

public class MapFieldParserRegistry> implements FieldParserRegistry {

    private final Map> registryMap;
    private final Optional> defaultParser;

    public MapFieldParserRegistry(Map> registryMap) {
        this(registryMap, null);
    }

    public MapFieldParserRegistry(Map> registryMap, FieldParser defaultParser) {
        this.registryMap = registryMap;
        this.defaultParser = Optional.ofNullable(defaultParser);
    }

    @Override
    public Optional> getFieldParser(String fieldName) {
        FieldParser parser = registryMap.get(fieldName);
        if (parser == null && defaultParser.isPresent()) {
            return defaultParser;
        }

        return Optional.ofNullable(registryMap.get(fieldName));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy