Skip to content

Commit

Permalink
Annotate & test j.u.f.BiPredicate default methods.
Browse files Browse the repository at this point in the history
This PR builds upon merged PR scala-native#1937 by annotating the existing
j.u.f.BiPredicate.scala and porting its corresponding BiPredicateTest
from Scala.js.

The existing file was edited rather than porting the most current
Scala.js commit because the latter uses lambdas and those
do not play well when using Scala Native with Scala 2.11.

See Issue scala-native#1972 for background & discussion of JavaDefaultMethod
annotation.
  • Loading branch information
LeeTibbert committed Nov 28, 2020
1 parent 92811e2 commit 0fd4685
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions javalib/src/main/scala/java/util/function/BiPredicate.scala
@@ -1,23 +1,30 @@
// Influenced by Scala.js commit: 0c27b64 dated: 2020-09-06

package java.util.function

import scala.scalanative.annotation.JavaDefaultMethod

trait BiPredicate[T, U] { self =>
def test(t: T, u: U): Boolean

@JavaDefaultMethod
def and(other: BiPredicate[_ >: T, _ >: U]): BiPredicate[T, U] =
new BiPredicate[T, U] {
override def test(t: T, u: U): Boolean =
self.test(t, u) && other.test(t, u)
}

@JavaDefaultMethod
def negate(): BiPredicate[T, U] =
new BiPredicate[T, U] {
override def test(t: T, u: U): Boolean =
!self.test(t, u)
}

@JavaDefaultMethod
def or(other: BiPredicate[_ >: T, _ >: U]): BiPredicate[T, U] =
new BiPredicate[T, U] {
override def test(t: T, u: U): Boolean =
self.test(t, u) || other.test(t, u)
}

def test(t: T, u: U): Boolean
}

0 comments on commit 0fd4685

Please sign in to comment.