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

com.ajjpj.asysmon.servlet.environment.PathMatcher Maven / Gradle / Ivy

There is a newer version: 1.0-pre28
Show newest version
package com.ajjpj.asysmon.servlet.environment;

import com.ajjpj.abase.collection.immutable.AList;

import java.util.ArrayList;
import java.util.List;


/**
 * @author arno
 */
class PathMatcher {
    private static final String WILDCARD_SINGLE_SEGMENT = "$ASYSMON$?";
    private static final String WILDCARD_SUFFIX = "$ASYSMON$*";

    static List create(String raw) {
        final List result = new ArrayList();

        for(String pathRaw: raw.split("\\|\\|")) {
            final String path = pathRaw.trim();

            final String[] segments = path.split("\\.");
            for(int i=0; i path) {
        AList remaining = path;

        for(String seg: segments) {
            if(WILDCARD_SUFFIX.equals(seg)) {
                return true;
            }

            if(remaining.isEmpty()) {
                // path is shorter than pattern
                return false;
            }

            if(! WILDCARD_SINGLE_SEGMENT.equals(seg)) {
                if(! seg.equals(remaining.head())) {
                    return false;
                }
            }

            remaining = remaining.tail();
        }

        // path is longer than pattern, and pattern has no '*' wildcard
        return false;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy