Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove symbolic multiple param methods #10229

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/play/src/main/java/play/libs/typedmap/TypedMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public TypedMap putAll(TypedEntry<?> e1) {
* @return A new instance of the map with the new entries added.
*/
public TypedMap putAll(TypedEntry<?> e1, TypedEntry<?> e2) {
return new TypedMap(underlying.$plus(e1.asScala(), e2.asScala()));
return new TypedMap(underlying.$plus(e1.asScala()).$plus(e2.asScala()));
}

/**
Expand All @@ -111,7 +111,7 @@ public TypedMap putAll(TypedEntry<?> e1, TypedEntry<?> e2) {
* @return A new instance of the map with the new entries added.
*/
public TypedMap putAll(TypedEntry<?> e1, TypedEntry<?> e2, TypedEntry<?> e3) {
return new TypedMap(underlying.$plus(e1.asScala(), e2.asScala(), e3.asScala()));
return new TypedMap(underlying.$plus(e1.asScala()).$plus(e2.asScala()).$plus(e3.asScala()));
}

/**
Expand Down Expand Up @@ -156,7 +156,7 @@ public TypedMap remove(TypedKey<?> k1) {
* @return A new instance of the map with the entries removed.
*/
public TypedMap remove(TypedKey<?> k1, TypedKey<?> k2) {
return new TypedMap(underlying.$minus(k1.asScala(), k2.asScala()));
return new TypedMap(underlying.$minus(k1.asScala()).$minus(k2.asScala()));
}

/**
Expand All @@ -168,7 +168,7 @@ public TypedMap remove(TypedKey<?> k1, TypedKey<?> k2) {
* @return A new instance of the map with the entries removed.
*/
public TypedMap remove(TypedKey<?> k1, TypedKey<?> k2, TypedKey<?> k3) {
return new TypedMap(underlying.$minus(k1.asScala(), k2.asScala(), k3.asScala()));
return new TypedMap(underlying.$minus(k1.asScala()).$minus(k2.asScala()).$minus(k3.asScala()));
}

/**
Expand Down
50 changes: 3 additions & 47 deletions core/play/src/main/scala/play/api/libs/typedmap/TypedMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,6 @@ trait TypedMap {
*/
def +(e1: TypedEntry[_]): TypedMap

/**
* Update the map with two entries, returning a new instance of the map.
*
* @param e1 The first new entry to add to the map.
* @param e2 The second new entry to add to the map.
* @return A new instance of the map with the new entries added.
*/
def +(e1: TypedEntry[_], e2: TypedEntry[_]): TypedMap

/**
* Update the map with three entries, returning a new instance of the map.
*
* @param e1 The first new entry to add to the map.
* @param e2 The second new entry to add to the map.
* @param e3 The third new entry to add to the map.
* @return A new instance of the map with the new entries added.
*/
def +(e1: TypedEntry[_], e2: TypedEntry[_], e3: TypedEntry[_]): TypedMap

/**
* Update the map with several entries, returning a new instance of the map.
*
Expand All @@ -101,25 +82,6 @@ trait TypedMap {
*/
def -(e1: TypedKey[_]): TypedMap

/**
* Removes two keys from the map, returning a new instance of the map.
*
* @param e1 The first key to remove.
* @param e2 The second key to remove.
* @return A new instance of the map with the entries removed.
*/
def -(e1: TypedKey[_], e2: TypedKey[_]): TypedMap

/**
* Removes three keys from the map, returning a new instance of the map.
*
* @param e1 The first key to remove.
* @param e2 The second key to remove.
* @param e3 The third key to remove.
* @return A new instance of the map with the entries removed.
*/
def -(e1: TypedKey[_], e2: TypedKey[_], e3: TypedKey[_]): TypedMap

/**
* Removes keys from the map, returning a new instance of the map.
*
Expand Down Expand Up @@ -149,12 +111,12 @@ object TypedMap {
/**
* Builds a [[TypedMap]] from two entries of keys and values.
*/
def apply(e1: TypedEntry[_], e2: TypedEntry[_]): TypedMap = TypedMap.empty + (e1, e2)
def apply(e1: TypedEntry[_], e2: TypedEntry[_]): TypedMap = TypedMap.empty + e1 + e2

/**
* Builds a [[TypedMap]] from three entries of keys and values.
*/
def apply(e1: TypedEntry[_], e2: TypedEntry[_], e3: TypedEntry[_]): TypedMap = TypedMap.empty + (e1, e2, e3)
def apply(e1: TypedEntry[_], e2: TypedEntry[_], e3: TypedEntry[_]): TypedMap = TypedMap.empty + e1 + e2 + e3

/**
* Builds a [[TypedMap]] from a list of keys and values.
Expand All @@ -173,19 +135,13 @@ private[typedmap] final class DefaultTypedMap private[typedmap] (m: immutable.Ma
override def contains(key: TypedKey[_]): Boolean = m.contains(key)
override def updated[A](key: TypedKey[A], value: A): TypedMap = new DefaultTypedMap(m.updated(key, value))
override def +(e1: TypedEntry[_]): TypedMap = new DefaultTypedMap(m.updated(e1.key, e1.value))
override def +(e1: TypedEntry[_], e2: TypedEntry[_]): TypedMap =
new DefaultTypedMap(m + (e1.key -> e1.value) + (e2.key -> e2.value))
override def +(e1: TypedEntry[_], e2: TypedEntry[_], e3: TypedEntry[_]): TypedMap =
new DefaultTypedMap(m + (e1.key -> e1.value) + (e2.key -> e2.value) + (e3.key -> e3.value))
override def +(entries: TypedEntry[_]*): TypedMap = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also shouldn't have this varargs method. instead, it should take a single arg such as an IterableOnce, and it is general practice to name it ++. the same for - with varargs (should take a collection and and be called --)

val m2 = entries.foldLeft(m) {
case (m1, e) => m1.updated(e.key, e.value)
}
new DefaultTypedMap(m2)
}
override def -(k1: TypedKey[_]): TypedMap = new DefaultTypedMap(m - k1)
override def -(k1: TypedKey[_], k2: TypedKey[_]): TypedMap = new DefaultTypedMap(m - k1 - k2)
override def -(k1: TypedKey[_], k2: TypedKey[_], k3: TypedKey[_]): TypedMap = new DefaultTypedMap(m - k1 - k2 - k3)
override def -(k1: TypedKey[_]): TypedMap = new DefaultTypedMap(m - k1)
override def -(keys: TypedKey[_]*): TypedMap = {
val m2 = keys.foldLeft(m) {
case (m1, k) => m1 - k
Expand Down
4 changes: 2 additions & 2 deletions core/play/src/main/scala/play/api/mvc/Request.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ trait Request[+A] extends RequestHeader {
override def addAttr[B](key: TypedKey[B], value: B): Request[A] =
withAttrs(attrs.updated(key, value))
override def addAttrs(e1: TypedEntry[_]): Request[A] = withAttrs(attrs + e1)
override def addAttrs(e1: TypedEntry[_], e2: TypedEntry[_]): Request[A] = withAttrs(attrs + (e1, e2))
override def addAttrs(e1: TypedEntry[_], e2: TypedEntry[_]): Request[A] = withAttrs(attrs + e1 + e2)
override def addAttrs(e1: TypedEntry[_], e2: TypedEntry[_], e3: TypedEntry[_]): Request[A] =
withAttrs(attrs + (e1, e2, e3))
withAttrs(attrs + e1 + e2 + e3)
override def addAttrs(entries: TypedEntry[_]*): Request[A] =
withAttrs(attrs + (entries: _*))
override def removeAttr(key: TypedKey[_]): Request[A] =
Expand Down
4 changes: 2 additions & 2 deletions core/play/src/main/scala/play/api/mvc/RequestHeader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ trait RequestHeader {
* @param e2 The second new attribute.
* @return The new version of this object with the new attributes.
*/
def addAttrs(e1: TypedEntry[_], e2: TypedEntry[_]): RequestHeader = withAttrs(attrs + (e1, e2))
def addAttrs(e1: TypedEntry[_], e2: TypedEntry[_]): RequestHeader = withAttrs(attrs + e1 + e2)

/**
* Create a new versions of this object with the given attributes attached to it.
Expand All @@ -177,7 +177,7 @@ trait RequestHeader {
* @param e3 The third new attribute.
* @return The new version of this object with the new attributes.
*/
def addAttrs(e1: TypedEntry[_], e2: TypedEntry[_], e3: TypedEntry[_]): RequestHeader = withAttrs(attrs + (e1, e2, e3))
def addAttrs(e1: TypedEntry[_], e2: TypedEntry[_], e3: TypedEntry[_]): RequestHeader = withAttrs(attrs + e1 + e2 + e3)

/**
* Create a new versions of this object with the given attributes attached to it.
Expand Down