Skip to content
This repository

Levenshtein distance in net.liftweb.util.LD - exception if first parameter is empty. #1225

Merged
merged 2 commits into from about 2 years ago

2 participants

Daniel Roziecki David Pollak
Daniel Roziecki

[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).

scala> import net.liftweb.util.LD
import net.liftweb.util.LD

scala> LD("aa", "bb")
res3: Int = 2

scala> LD("aa", "")
res4: Int = 2

scala> LD("", "bb")
java.util.NoSuchElementException
at scala.collection.LinearSeqOptimized$class.last(LinearSeqOptimized.scala:135)
at scala.collection.immutable.List.last(List.scala:45)
at net.liftweb.util.LD$.apply(LD.scala:94)
at .(:11)
at .()
at .(:11)
at .()
at $print()
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:914)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:546)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:577)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:543)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:694)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:745)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:651)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:542)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:550)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:851)
at xsbt.ConsoleInterface.run(ConsoleInterface.scala:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:57)
at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:48)
at sbt.Console.console0$1(Console.scala:23)
at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24)
at sbt.TrapExit$.executeMain$1(TrapExit.scala:33)
at sbt.TrapExit$$anon$1.run(TrapExit.scala:42)

David Pollak dpp closed this pull request from a commit February 27, 2012
David Pollak Closes #1225 648e52c
David Pollak dpp closed this in 648e52c February 27, 2012
David Pollak dpp reopened this February 27, 2012
David Pollak dpp merged commit d6215e6 into from March 01, 2012
David Pollak dpp closed this March 01, 2012
Diego Medina fmpwizard deleted the branch August 01, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
5  core/util/src/main/scala/net/liftweb/util/LD.scala
@@ -91,7 +91,10 @@ object LD {
91 91
                                       new ListBuffer))
92 92
       }
93 93
 
94  
-    matrix(y1, 0, (1 to x.length).toList).last
  94
+    matrix(y1, 0, (1 to x.length).toList) match {
  95
+      case Nil => 100000
  96
+      case xs => xs.last
  97
+    }
95 98
   }
96 99
 }
97 100
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.