Skip to content

Instantly share code, notes, and snippets.

@akehoyayoi
Created September 27, 2014 04:45
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 akehoyayoi/8765f32f6b2e95faa201 to your computer and use it in GitHub Desktop.
Save akehoyayoi/8765f32f6b2e95faa201 to your computer and use it in GitHub Desktop.
汎用Versionクラス
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