
com.nthportal.versions.ExtendedVersionBase.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of versions_2.11 Show documentation
Show all versions of versions_2.11 Show documentation
A Scala library for representing versions as objects.
The newest version!
package com.nthportal.versions
import scala.language.higherKinds
/**
* Base trait for an extended version.
*
* @tparam V the type of the version component of this extended version
* @tparam E the type of the extension component of this extended version
* @tparam EV the type of this extended version
*/
private[versions] trait ExtendedVersionBase[V <: VersionBase[V, EV], E, EV[X] <: ExtendedVersionBase[V, X, EV]]
extends Ordered[EV[E]] {
/**
* The version component of this extended version.
*/
val version: V
/**
* The extension component of this extended version.
*/
val extension: E
/**
* The [[ExtensionDef extension definition]] for this version's extension.
*/
protected val extensionDef: ExtensionDef[E]
private implicit def eOrd = extensionDef.ordering
/**
* Compares two extended versions. Adheres to the general contract
* of `compare` as defined in [[scala.math.Ordered.compare]].
*
* `that` MUST have the same extension definition as `this`.
*
* @param that the extended version to compare to this
* @throws IllegalArgumentException if `that` does not have the same
* extension definition as this
* @return the result of comparing `this` with `that`
*/
@throws[IllegalArgumentException]
override def compare(that: EV[E]): Int = {
require(extensionDef == that.extensionDef, "cannot compare extended versions with different extension definitions")
implicitly[Ordering[(V, E)]].compare((this.version, this.extension), (that.version, that.extension))
}
override def toString = s"$version${extensionDef.extToString(extension)}"
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy