X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fstore%2FPathPattern.java;fp=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fstore%2FPathPattern.java;h=347b42b8058423de5ea3102aeaab4888bdefcf4d;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/store/PathPattern.java b/bundles/org.simantics.graph/src/org/simantics/graph/store/PathPattern.java new file mode 100644 index 000000000..347b42b80 --- /dev/null +++ b/bundles/org.simantics.graph/src/org/simantics/graph/store/PathPattern.java @@ -0,0 +1,117 @@ +package org.simantics.graph.store; + +import gnu.trove.set.hash.THashSet; + +import java.util.regex.Pattern; + +import org.simantics.graph.query.Path; +import org.simantics.graph.query.PathChild; +import org.simantics.graph.query.Paths; + +public class PathPattern { + + private static PathPattern EMPTY_PATTERN = new PathPattern(null, null); + + Path prefix; + Pattern suffix; + + private PathPattern(Path prefix, Pattern suffix) { + this.prefix = prefix; + this.suffix = suffix; + } + + public static PathPattern compile(String pattern) { + pattern = stripPatternPrefix(pattern); + if(pattern == null) + return EMPTY_PATTERN; + String[] parts = pattern.split("/"); + + Path path = Paths.Root; + for(int i=0;i result) { + int id = store.pathToId(prefix); + if(id == -1) + return; + store.findChildren(id, prefix, "", suffix, result); + } + + public static void main(String[] args) { + System.out.println(compile("http://www.simantics.org/*/foo")); + } +}