Skip to content

Instantly share code, notes, and snippets.

@JavierCane
Created April 18, 2017 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JavierCane/b1933d88c98aa8e4ee70ebfaecf3b2c0 to your computer and use it in GitHub Desktop.
Save JavierCane/b1933d88c98aa8e4ee70ebfaecf3b2c0 to your computer and use it in GitHub Desktop.
Initial code for the Finder Refactoring Kata. More info: http://codely.tv/screencasts/finder-kata-scala/
// Post: http://codely.tv/screencasts/finder-kata-scala/
// Repo: https://github.com/CodelyTV/incomprehensible-finder-refactoring-kata-scala
package tv.codely.finderKata.algorithm
import java.util
import java.util.ArrayList
import scala.collection.JavaConverters._
import tv.codely.finderKata.algorithm.FT.FT
class Finder(private val _p: util.List[Thing]) {
def Find(ft: FT): F = {
val tr = new ArrayList[F]()
for (i <- 0 until _p.size - 1; j <- i + 1 until _p.size) {
val r: F = new F()
if (_p.get(i).birthDate.getMillis < _p.get(j).birthDate.getMillis) {
r.P1 = _p.get(i)
r.P2 = _p.get(j)
} else {
r.P1 = _p.get(j)
r.P2 = _p.get(i)
}
r.D = r.P2.birthDate.getMillis - r.P1.birthDate.getMillis
tr.add(r)
}
if (tr.size < 1) {
return new F()
}
var answer: F = tr.get(0)
for (result: F <- tr.asScala) ft match {
case FT.One => if (result.D < answer.D) {
answer = result
}
case FT.Two => if (result.D > answer.D) {
answer = result
}
}
answer
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment