All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala.meta.internal.trees.Version.scala Maven / Gradle / Ivy

Go to download

Bag of private and public helpers used in scala.meta's APIs and implementations

There is a newer version: 4.12.2
Show newest version
package scala.meta.internal.trees

import scala.util.Try

case class Version(major: Int, minor: Int, patch: Int) {
  def asString(delim: Char): String = s"$major$delim$minor$delim$patch"

  override def toString: String = asString('.')
}

object Version {

  final val zero = Version(0, 0, 0)

  implicit val ordering: Ordering[Version] = new Ordering[Version] {
    override def compare(x: Version, y: Version): Int = {
      val cmpMajor = x.major.compare(y.major)
      if (cmpMajor != 0) return cmpMajor
      val cmpMinor = x.minor.compare(y.minor)
      if (cmpMinor != 0) return cmpMinor
      x.patch.compare(y.patch)
    }
  }

  def parse(v: String, delim: Char = '.'): Try[Version] = Try {
    val versions = v.split(delim).map(_.toInt)
    Version(versions(0), versions(1), versions(2))
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy