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

com.firefly.server.http2.router.impl.AbstractPreciseMatcher Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.server.http2.router.impl;

import com.firefly.server.http2.router.Matcher;
import com.firefly.server.http2.router.Router;

import java.util.*;

/**
 * @author Pengtao Qiu
 */
abstract public class AbstractPreciseMatcher implements Matcher {

    protected Map> map;

    private Map> map() {
        if (map == null) {
            map = new HashMap<>();
        }
        return map;
    }

    @Override
    public void add(String rule, Router router) {
        map().computeIfAbsent(rule, k -> new HashSet<>()).add(router);
    }

    @Override
    public MatchResult match(String value) {
        if (map == null) {
            return null;
        }

        Set routers = map.get(value);
        if (routers != null && !routers.isEmpty()) {
            return new MatchResult(routers, Collections.emptyMap(), getMatchType());
        } else {
            return null;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy