Permalink
Browse files

CLEREZZA-725: reverted to previous revision except the new test Query…

…ParserSerializerCombinationTest.java, and used LinkedHashSet instead of HashSet to preserve ordering of sparql query pattern

git-svn-id: https://svn.apache.org/repos/asf/incubator/clerezza/trunk@1418759 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 034bdbd commit 68ed700be477f45cc85efc581ac8c4160a324fd4 Hasan Hasan committed Dec 8, 2012
@@ -18,7 +18,6 @@
*/
package org.apache.clerezza.rdf.core.sparql.query;
-import java.util.List;
import java.util.Set;
/**
@@ -31,15 +30,9 @@
public interface BasicGraphPattern extends GraphPattern {
/**
- * @deprecated use getTriplePatternList instead and convert the result to a Set if needed
+ *
* @return a set of all triple patterns to match.
*/
public Set<TriplePattern> getTriplePatterns();
- /**
- *
- * @return a list of all triple patterns to match.
- */
- public List<TriplePattern> getTriplePatternList();
-
}
@@ -18,7 +18,6 @@
*/
package org.apache.clerezza.rdf.core.sparql.query;
-import java.util.List;
import java.util.Set;
/**
@@ -32,22 +31,11 @@
public interface ConstructQuery extends QueryWithSolutionModifier {
/**
- * @deprecated use getTemplate instead and convert the result to a Set if needed
- *
* <p>Gets the template for constructing triples in a CONSTRUCT query.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#construct">
* SPARQL Query Language: 10.2 CONSTRUCT</a>
* @return a template as a set of triple patterns for constructing
* new triples.
*/
public Set<TriplePattern> getConstructTemplate();
-
- /**
- * <p>Gets the template for constructing triples in a CONSTRUCT query.</p>
- * @see <a href="http://www.w3.org/TR/rdf-sparql-query/#construct">
- * SPARQL Query Language: 10.2 CONSTRUCT</a>
- * @return a template as a list of triple patterns for constructing
- * new triples.
- */
- public List<TriplePattern> getTemplate();
}
@@ -31,19 +31,12 @@
public interface GroupGraphPattern extends GraphPattern {
/**
- * @deprecated use getGraphPatternList instead and convert the result to a Set if needed
*
* @return a set of all patterns, ANDed together.
*/
public Set<GraphPattern> getGraphPatterns();
/**
- *
- * @return a list of all patterns, ANDed together.
- */
- public List<GraphPattern> getGraphPatternList();
-
- /**
* @return
* a list of filter expressions for all patterns in the group if any,
* otherwise an empty list is returned.
@@ -18,9 +18,7 @@
*/
package org.apache.clerezza.rdf.core.sparql.query.impl;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
+import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.clerezza.rdf.core.sparql.query.BasicGraphPattern;
import org.apache.clerezza.rdf.core.sparql.query.TriplePattern;
@@ -31,36 +29,20 @@
*/
public class SimpleBasicGraphPattern implements BasicGraphPattern {
- private List<TriplePattern> triplePatterns = new ArrayList<TriplePattern>();
+ private Set<TriplePattern> triplePatterns;
public SimpleBasicGraphPattern(Set<TriplePattern> triplePatterns) {
- if (triplePatterns != null) {
- this.triplePatterns.addAll(triplePatterns);
- }
- }
-
- public SimpleBasicGraphPattern(List<TriplePattern> triplePatterns) {
- if (triplePatterns != null) {
- this.triplePatterns = triplePatterns;
- }
+ this.triplePatterns = (triplePatterns == null)
+ ? new LinkedHashSet<TriplePattern>()
+ : triplePatterns;
}
@Override
- @Deprecated
public Set<TriplePattern> getTriplePatterns() {
- return new HashSet(triplePatterns);
- }
-
- @Override
- public List<TriplePattern> getTriplePatternList() {
return triplePatterns;
}
public void addTriplePatterns(Set<TriplePattern> triplePatterns) {
this.triplePatterns.addAll(triplePatterns);
}
-
- public void addTriplePatterns(List<TriplePattern> triplePatterns) {
- this.triplePatterns.addAll(triplePatterns);
- }
}
@@ -18,9 +18,7 @@
*/
package org.apache.clerezza.rdf.core.sparql.query.impl;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
+import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.clerezza.rdf.core.sparql.query.ConstructQuery;
import org.apache.clerezza.rdf.core.sparql.query.TriplePattern;
@@ -32,28 +30,16 @@
public class SimpleConstructQuery extends SimpleQueryWithSolutionModifier
implements ConstructQuery {
- private List<TriplePattern> triplePatterns = new ArrayList<TriplePattern>();
+ private Set<TriplePattern> triplePatterns;
public SimpleConstructQuery(Set<TriplePattern> triplePatterns) {
- if (triplePatterns != null) {
- this.triplePatterns.addAll(triplePatterns);
- }
- }
-
- public SimpleConstructQuery(List<TriplePattern> triplePatterns) {
- if (triplePatterns != null) {
- this.triplePatterns = triplePatterns;
- }
+ this.triplePatterns = (triplePatterns == null)
+ ? new LinkedHashSet<TriplePattern>()
+ : triplePatterns;
}
@Override
- @Deprecated
public Set<TriplePattern> getConstructTemplate() {
- return new HashSet(triplePatterns);
- }
-
- @Override
- public List<TriplePattern> getTemplate() {
return triplePatterns;
}
@@ -19,7 +19,7 @@
package org.apache.clerezza.rdf.core.sparql.query.impl;
import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.clerezza.rdf.core.sparql.query.Expression;
@@ -39,14 +39,8 @@
private List<GraphPattern> graphPatterns = new ArrayList<GraphPattern>();
@Override
- @Deprecated
public Set<GraphPattern> getGraphPatterns() {
- return new HashSet(graphPatterns);
- }
-
- @Override
- public List<GraphPattern> getGraphPatternList() {
- return graphPatterns;
+ return new LinkedHashSet(graphPatterns);
}
@Override
@@ -86,21 +80,6 @@ public void addConstraint(Expression constraint) {
* {@link SimpleBasicGraphPattern} of the group.
*/
public void addTriplePatterns(Set<TriplePattern> triplePatterns) {
- addTriplePatterns(new ArrayList(triplePatterns));
- }
-
- /**
- * If the last {@link GraphPattern} added to the group is not a
- * {@link SimpleBasicGraphPattern}, then creates one containing the
- * specified {@link TriplePattern}s and adds it to the group.
- * Otherwise, adds the specified {@link TriplePattern}s to the last
- * added {@link SimpleBasicGraphPattern} in the group.
- *
- * @param triplePatterns
- * a list of {@link TriplePattern}s to be added into a
- * {@link SimpleBasicGraphPattern} of the group.
- */
- public void addTriplePatterns(List<TriplePattern> triplePatterns) {
GraphPattern prevGraphPattern;
int size = graphPatterns.size();
if (size > 0) {
@@ -19,6 +19,7 @@
package org.apache.clerezza.rdf.core.sparql.query.impl;
import java.util.List;
+import java.util.Set;
import org.apache.clerezza.rdf.core.BNode;
import org.apache.clerezza.rdf.core.Resource;
import org.apache.clerezza.rdf.core.UriRef;
@@ -113,7 +114,7 @@ private void appendGroupGraphPattern(StringBuffer s,
GroupGraphPattern groupGraphPattern) {
s.append("{ ");
- for (GraphPattern graphPattern : groupGraphPattern.getGraphPatternList()) {
+ for (GraphPattern graphPattern : groupGraphPattern.getGraphPatterns()) {
appendGraphPattern(s, graphPattern);
}
for (Expression e : groupGraphPattern.getFilter()) {
@@ -135,7 +136,7 @@ private void appendGroupGraphPattern(StringBuffer s,
private void appendGraphPattern(StringBuffer s, GraphPattern graphPattern) {
if (graphPattern instanceof BasicGraphPattern) {
appendTriplePatterns(s,
- ((BasicGraphPattern) graphPattern).getTriplePatternList());
+ ((BasicGraphPattern) graphPattern).getTriplePatterns());
} else if (graphPattern instanceof GroupGraphPattern) {
appendGroupGraphPattern(s, (GroupGraphPattern) graphPattern);
} else if (graphPattern instanceof OptionalGraphPattern) {
@@ -169,7 +170,7 @@ private void appendGraphPattern(StringBuffer s, GraphPattern graphPattern) {
}
private void appendTriplePatterns(StringBuffer s,
- List<TriplePattern> triplePatterns) {
+ Set<TriplePattern> triplePatterns) {
for (TriplePattern p : triplePatterns) {
appendResourceOrVariable(s, p.getSubject());
@@ -270,7 +271,7 @@ private void appendOrderCondition(StringBuffer s, OrderCondition oc) {
@Override
public String serialize(ConstructQuery constructQuery) {
StringBuffer s = new StringBuffer("CONSTRUCT\n");
- List<TriplePattern> triplePatterns = constructQuery.getTemplate();
+ Set<TriplePattern> triplePatterns = constructQuery.getConstructTemplate();
s.append("{ ");
if (triplePatterns != null && !triplePatterns.isEmpty()) {
appendTriplePatterns(s, triplePatterns);
Oops, something went wrong.

0 comments on commit 68ed700

Please sign in to comment.