changeset 6:4ace3eb848d4

~ improve the implementation a bit
author Alexandre Bertails <alexandre@bertails.org>
date Thu, 27 May 2010 21:47:03 -0400
parents d9a609047270
children 609bbd9a2dce
files src/main/scala/Main.scala
diffstat 1 files changed, 4 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/Main.scala	Thu May 27 21:45:29 2010 -0400
+++ b/src/main/scala/Main.scala	Thu May 27 21:47:03 2010 -0400
@@ -1,5 +1,7 @@
 package w3c.sw.StemGraph
 
+import scala.collection.Set
+
 object Transformer {
   // Transformation argument:
   type StemURI = IRI
@@ -33,7 +35,7 @@
 
   // Accessor functions:
   def pk (h:Header) : AttrName  // Assume: one primary key.
-  = h.filter(x => x._2._1 == Pk()).keysIterator.toList(0)
+  = h.find(x => x._2._1 == Pk()).get._1
   def header (r:Relation) : Header = r.header
   def body (r:Relation) : Body = r.body
 
@@ -51,7 +53,7 @@
     val h = header(r)
     val k = pk(h)
     val s = nodemap(u, r, k, lexvalue(h, t, k).asInstanceOf[LexicalValue]) // Assume: no NULLs in primary key
-    h.keysIterator.toList.flatMap(a => cellmap(u, r, a, s, t)).toSet
+    h.keySet.flatMap(a => cellmap(u, r, a, s, t))
   }
 
   def cellmap (u:StemURI, r:Relation, a:AttrName, s:IRI, t:Tuple) : Option[RDFTriple] = {
@@ -80,16 +82,6 @@
     }
   def literalmap (l:LexicalValue, d:SQLDatatype) : RDFLiteral
   = "\"" + l.s + "\"^^" + XSD(d)
-
-  // Utilities:
-  def toSet[T](list: List[T]) = {
-    def traverse(list: List[T])(set: Set[T]): Set[T] = list match {
-      case hd :: tail => traverse(tail)(set + hd)
-      case Nil => set
-    }
-    
-    traverse(list)(Set[T]())
-  }
   
 }
 
Set up and maintained by W3C Systems Team, please report bugs to sysreq@w3.org.

W3C would like to thank Microsoft who donated the server that allows us to run this service.