Search in sources :

Example 1 with Start

use of net.sourceforge.processdash.util.glob.node.Start in project processdash by dtuma.

the class GlobEngine method test.

public static boolean test(String expression, Object value) {
    if (expression == null || expression.trim().length() == 0 || value == null)
        return false;
    Collection words = asCollection(value);
    if (words == null || words.isEmpty())
        return false;
    Start s = compile(expression);
    if (s == null)
        return false;
    GlobTestEvaluator eval = new GlobTestEvaluator(words);
    eval.caseStart(s);
    return eval.getResult();
}
Also used : Start(net.sourceforge.processdash.util.glob.node.Start) Collection(java.util.Collection)

Example 2 with Start

use of net.sourceforge.processdash.util.glob.node.Start in project processdash by dtuma.

the class GlobEngine method compile.

private static Start compile(String expression) {
    Start result = (Start) COMPILED_EXPRESSIONS.get(expression);
    if (result == null) {
        try {
            Parser p = new Parser(new Lexer(new PushbackReader(new StringReader(expression), 1024)));
            // Parse the input
            result = p.parse();
        } catch (Exception e) {
            logger.warning("Invalid glob expression: " + expression);
            e.printStackTrace();
        }
    }
    return result;
}
Also used : Lexer(net.sourceforge.processdash.util.glob.lexer.Lexer) Start(net.sourceforge.processdash.util.glob.node.Start) StringReader(java.io.StringReader) Parser(net.sourceforge.processdash.util.glob.parser.Parser) PushbackReader(java.io.PushbackReader)

Example 3 with Start

use of net.sourceforge.processdash.util.glob.node.Start in project processdash by dtuma.

the class GlobEngine method search.

public static Set search(String expression, Map taggedData, TaggedDataMapSource deferredDataSource) {
    if (expression == null || expression.trim().length() == 0)
        return Collections.EMPTY_SET;
    Start s = compile(expression);
    if (s == null)
        return Collections.EMPTY_SET;
    GlobSearchEvaluator eval = new GlobSearchEvaluator(taggedData, deferredDataSource);
    eval.caseStart(s);
    Set matches = eval.getResult();
    if (matches == null || matches.isEmpty())
        return Collections.EMPTY_SET;
    else
        return matches;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Start(net.sourceforge.processdash.util.glob.node.Start)

Aggregations

Start (net.sourceforge.processdash.util.glob.node.Start)3 PushbackReader (java.io.PushbackReader)1 StringReader (java.io.StringReader)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Lexer (net.sourceforge.processdash.util.glob.lexer.Lexer)1 Parser (net.sourceforge.processdash.util.glob.parser.Parser)1