Created
September 27, 2014 04:45
-
-
Save akehoyayoi/8765f32f6b2e95faa201 to your computer and use it in GitHub Desktop.
汎用Versionクラス
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
case class Version(v: Int *) extends Ordered[Version] { | |
def compare(other: Version) = { | |
c(v,other.v) | |
} | |
def c(v1: Seq[Int], v2: Seq[Int]): Int = { | |
val diff = v1.headOption.getOrElse(0) compare v2.headOption.getOrElse(0) | |
if(diff == 0) c(v1.tail,v2.tail) else diff | |
} | |
} | |
object Version { | |
def apply(s: String): Version = { | |
val a = s.split('.').map(_.toInt).toSeq | |
Version(a: _*) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment