From 6cada88fb3890e69e73f8a8782ab8ab6bcc40a4a Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Tue, 10 Aug 2010 08:39:30 -0400 Subject: [PATCH] split out read-only RMap from PMap --- util/collection/PMap.scala | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/util/collection/PMap.scala b/util/collection/PMap.scala index bc5e092af..e6b002995 100644 --- a/util/collection/PMap.scala +++ b/util/collection/PMap.scala @@ -5,12 +5,15 @@ package sbt import Types._ -trait PMap[K[_], V[_]] extends (K ~> V) +trait RMap[K[_], V[_]] { def apply[T](k: K[T]): V[T] def get[T](k: K[T]): Option[V[T]] - def update[T](k: K[T], v: V[T]): Unit def contains[T](k: K[T]): Boolean +} +trait PMap[K[_], V[_]] extends (K ~> V) with RMap[K,V] +{ + def update[T](k: K[T], v: V[T]): Unit def remove[T](k: K[T]): Option[V[T]] def getOrUpdate[T](k: K[T], make: => V[T]): V[T] } @@ -27,8 +30,11 @@ abstract class AbstractPMap[K[_], V[_]] extends PMap[K,V] import collection.mutable.Map -/** Only suitable for K that is invariant in its parameter. -* Option and List keys are not, for example, because None <:< Option[String] and None <: Option[Int].*/ +/** +* Only suitable for K that is invariant in its type parameter. +* Option and List keys are not suitable, for example, +* because None <:< Option[String] and None <: Option[Int]. +*/ class DelegatingPMap[K[_], V[_]](backing: Map[K[_], V[_]]) extends AbstractPMap[K,V] { def get[T](k: K[T]): Option[V[T]] = cast[T]( backing.get(k) )