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

net.apexes.wsonrpc.server.PathAcceptors Maven / Gradle / Ivy

There is a newer version: 3.3.0
Show newest version
/*
 * Copyright (c) 2018, apexes.net. All rights reserved.
 *
 *         http://www.apexes.net
 *
 */
package net.apexes.wsonrpc.server;

/**
 * @author HeDYn
 */
public final class PathAcceptors {

    /**
     * 允许接受以root开头的路径连接
     * @param root
     * @return
     */
    public static PathAcceptor startWithPath(String root) {
        final String rootPath = path(root);
        return new PathAcceptor() {

            @Override
            public boolean accept(String path) {
                return path.startsWith(rootPath);
            }

        };
    }

    public static PathAcceptor equalsPath(String ref) {
        final String refPath = path(ref);
        return new PathAcceptor() {

            @Override
            public boolean accept(String path) {
                return path.equals(refPath);
            }

        };
    }

    public static PathAcceptor rootPath() {
        return equalsPath("/");
    }

    private static String path(String ref) {
        final String path;
        if (ref.startsWith("/")) {
            path = ref;
        } else {
            path = "/" + ref;
        }
        return path;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy