Created
April 18, 2017 20:42
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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