You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by bb...@apache.org on 2011/06/23 21:56:22 UTC
svn commit: r1139049 -
/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
Author: bblfish
Date: Thu Jun 23 19:56:21 2011
New Revision: 1139049
URL: http://svn.apache.org/viewvc?rev=1139049&view=rev
Log:
CLEREZZA-510 replaced recursive call on toTriples method with loop as it was not tail recursive. Also removed @deprectated on EasyGraph class.
Modified:
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
Modified: incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala?rev=1139049&r1=1139048&r2=1139049&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala (original)
+++ incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala Thu Jun 23 19:56:21 2011
@@ -24,11 +24,11 @@ import java.lang.Boolean
import java.net.{URL, URI}
import org.apache.clerezza.rdf.utils.UnionMGraph
import org.apache.clerezza.rdf.utils.GraphNode
-import scala.collection.mutable.HashMap
import org.apache.clerezza.rdf.ontologies.{XSD, RDF}
import org.apache.clerezza.rdf.core._
import impl._
import java.util.{HashSet, Date}
+import collection.mutable.{ListBuffer, HashMap}
object EasyGraph {
@@ -108,8 +108,6 @@ class EzLiteral(lexicalForm: String) ext
* @created: 20/04/2011
*/
-@deprecated("Don't use yet other than for trying out this class as it may be merged with another class or changed dramatically." +
- " Send feedback to CLEREZZA-510. ")
class EasyGraph(val graph: HashSet[Triple]) extends SimpleMGraph(graph) {
val namedBnodes = new HashMap[String,EasyGraphNode]
@@ -320,19 +318,28 @@ class EasyGraphNode(val ref: NonLiteral,
graph.add(new TripleImpl(ref, rel, obj))
}
- private def toTriples[T <: Resource](headRef: NonLiteral, list: List[T]): List[Triple] = {
- list match {
- case head :: next :: rest => {
- val nextRef = new BNode
- new TripleImpl(headRef, RDF.first, head) ::
- new TripleImpl(headRef, RDF.rest, nextRef) ::
- toTriples(nextRef, next :: rest)
+ private def toTriples[T <: Resource](head: NonLiteral,list : List[T]): List[Triple] = {
+ val answer = new ListBuffer[Triple]
+ var varList = list
+ var headRef = head
+ while (varList != Nil) {
+ varList = varList match {
+ case head :: next :: rest => {
+ val nextRef = new BNode
+ answer.append(new TripleImpl(headRef, RDF.first, head))
+ answer.append(new TripleImpl(headRef, RDF.rest, nextRef))
+ headRef = nextRef
+ next :: rest
+ }
+ case head :: Nil => {
+ answer.append(new TripleImpl(headRef, RDF.first, head))
+ answer.append(new TripleImpl(headRef, RDF.rest, RDF.nil))
+ Nil
+ }
+ case Nil => Nil
}
- case head :: nil => {
- new TripleImpl(headRef, RDF.first, head) :: new TripleImpl(headRef, RDF.rest, RDF.nil) :: Nil
- }
- case nil => Nil
}
+ answer.toList
}