Skip to content

Commit

Permalink
Ordering instances for ResolvedReference, BuildRef, ProjectRef
Browse files Browse the repository at this point in the history
  • Loading branch information
harrah committed Feb 15, 2012
1 parent bda151c commit b96ceab
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions main/Reference.scala
Expand Up @@ -45,6 +45,25 @@ object RootProject
}
object Reference
{
implicit val resolvedReferenceOrdering: Ordering[ResolvedReference] = new Ordering[ResolvedReference] {
def compare(a: ResolvedReference, b: ResolvedReference): Int = (a, b) match {
case (ba: BuildRef, bb: BuildRef) => buildRefOrdering.compare(ba, bb)
case (pa: ProjectRef, pb: ProjectRef) => projectRefOrdering.compare(pa, pb)
case (_: BuildRef, _: ProjectRef) => -1
case (_: ProjectRef, _: BuildRef) => 1
}
}
implicit val buildRefOrdering: Ordering[BuildRef] = new Ordering[BuildRef] {
def compare(a: BuildRef, b: BuildRef): Int = a.build compareTo b.build
}

implicit val projectRefOrdering: Ordering[ProjectRef] = new Ordering[ProjectRef] {
def compare(a: ProjectRef, b: ProjectRef): Int = {
val bc = a.build compareTo b.build
if(bc == 0) a.project compareTo b.project else bc
}
}

def buildURI(ref: ResolvedReference): URI = ref match {
case BuildRef(b) => b
case ProjectRef(b, _) => b
Expand Down

0 comments on commit b96ceab

Please sign in to comment.