You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2014/07/24 12:41:34 UTC
[10/12] git commit: Keep stable order when selecting recursive in
ldpath
Keep stable order when selecting recursive in ldpath
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/1ee27b87
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/1ee27b87
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/1ee27b87
Branch: refs/heads/MARMOTTA-499
Commit: 1ee27b8780c8e1590a1578f1be8b262e22719293
Parents: 42f5db0
Author: Jakob Frank <ja...@apache.org>
Authored: Thu Jul 10 14:33:33 2014 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Thu Jul 10 14:35:24 2014 +0200
----------------------------------------------------------------------
.../model/selectors/RecursivePathSelector.java | 17 ++++++++++-------
.../marmotta/ldpath/parser/SelectorsTest.java | 10 ++++++++++
2 files changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1ee27b87/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/selectors/RecursivePathSelector.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/selectors/RecursivePathSelector.java b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/selectors/RecursivePathSelector.java
index e97b2e5..2f84c66 100644
--- a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/selectors/RecursivePathSelector.java
+++ b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/selectors/RecursivePathSelector.java
@@ -50,7 +50,7 @@ public class RecursivePathSelector<Node> implements NodeSelector<Node> {
*/
@Override
public Collection<Node> select(RDFBackend<Node> rdfBackend, Node context, List<Node> path, Map<Node, List<Node>> resultPaths) {
- Set<Node> result = new HashSet<Node>();
+ List<Node> result = new LinkedList<>();
if (minRecursions <= 0) {
result.add(context);
@@ -60,19 +60,19 @@ public class RecursivePathSelector<Node> implements NodeSelector<Node> {
return result;
}
- private void subSelect(Node currentContext, int depth, RDFBackend<Node> rdfBackend, Set<Node> resultSet, List<Node> path, Map<Node, List<Node>> resultPaths) {
+ private void subSelect(Node currentContext, int depth, RDFBackend<Node> rdfBackend, List<Node> resultList, List<Node> path, Map<Node, List<Node>> resultPaths) {
Collection<Node> nextNodes = delegate.select(rdfBackend, currentContext,path,resultPaths);
depth++;
for (Node n : nextNodes) {
- if (!resultSet.contains(n)) {
+ if (!resultList.contains(n)) {
if (depth >= minRecursions){
- resultSet.add(n);
+ resultList.add(n);
}
if (depth < maxRecursions) {
if(path != null && resultPaths != null) {
- subSelect(n, depth, rdfBackend, resultSet, new ImmutableList.Builder<Node>().addAll(path).add(currentContext).build(),resultPaths);
+ subSelect(n, depth, rdfBackend, resultList, new ImmutableList.Builder<Node>().addAll(path).add(currentContext).build(),resultPaths);
} else {
- subSelect(n, depth, rdfBackend, resultSet, null,resultPaths);
+ subSelect(n, depth, rdfBackend, resultList, null,resultPaths);
}
}
}
@@ -168,12 +168,15 @@ public class RecursivePathSelector<Node> implements NodeSelector<Node> {
RecursivePathSelector<Node> that = (RecursivePathSelector<Node>) o;
if (delegate != null ? !delegate.equals(that.delegate) : that.delegate != null) return false;
+ if (minRecursions != that.minRecursions || maxRecursions != that.maxRecursions) return false;
return true;
}
@Override
public int hashCode() {
- return delegate != null ? delegate.hashCode() : 0;
+ int hash = delegate != null ? delegate.hashCode() : 0;
+ hash = hash * 31 * 31 + minRecursions * 31 + maxRecursions;
+ return hash;
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1ee27b87/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java b/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java
index f2a0327..fa46454 100644
--- a/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java
+++ b/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java
@@ -50,6 +50,16 @@ public class SelectorsTest {
{"(<http://www.example.com/>[@en])", "Grouped"},
{"(<http://www.example.com/>)*", "RecursivePath"},
{"(<http://www.example.com/>)+", "RecursivePath"},
+/* TODO - these should also work in the future...
+ {"(<http://www.example.com/>){5,}", "RecursivePath"},
+ {"(<http://www.example.com/>){5,7}", "RecursivePath"},
+ {"(<http://www.example.com/>){,7}", "RecursivePath"},
+ {"<http://www.example.com/>*", "RecursivePath"},
+ {"<http://www.example.com/>+", "RecursivePath"},
+ {"<http://www.example.com/>{5,}", "RecursivePath"},
+ {"<http://www.example.com/>{5,7}", "RecursivePath"},
+ {"<http://www.example.com/>{,7}", "RecursivePath"},
+*/
{"^<http://www.example.com/>", "ReverseProperty"},
{"fn:count(\"foo\")", "Function"},
// Not implemented yet: {"^*", "ReverseProperty"},