Skip to content

Commit

Permalink
Move ConstantFun to akka.util, akka#22813
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawstein authored and patriknw committed May 10, 2017
1 parent f064d13 commit b3d00af
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 67 deletions.
47 changes: 47 additions & 0 deletions akka-actor/src/main/scala/akka/util/ConstantFun.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package akka.util

import akka.annotation.InternalApi
import akka.japi.function.{ Function JFun, Function2 JFun2 }
import akka.japi.{ Pair JPair }

/**
* INTERNAL API
*/
@InternalApi private[akka] object ConstantFun {
private[this] val JavaIdentityFunction = new JFun[Any, Any] {
@throws(classOf[Exception]) override def apply(param: Any): Any = param
}

val JavaPairFunction = new JFun2[AnyRef, AnyRef, AnyRef JPair AnyRef] {
def apply(p1: AnyRef, p2: AnyRef): AnyRef JPair AnyRef = JPair(p1, p2)
}

def javaCreatePairFunction[A, B]: JFun2[A, B, JPair[A, B]] = JavaPairFunction.asInstanceOf[JFun2[A, B, JPair[A, B]]]

def javaIdentityFunction[T]: JFun[T, T] = JavaIdentityFunction.asInstanceOf[JFun[T, T]]

def scalaIdentityFunction[T]: T T = conforms.asInstanceOf[Function[T, T]]

def scalaAnyToNone[A, B]: A Option[B] = none
def scalaAnyTwoToNone[A, B, C]: (A, B) Option[C] = two2none
def javaAnyToNone[A, B]: A Option[B] = none
def nullFun[T] = _nullFun.asInstanceOf[Any T]

val zeroLong = (_: Any) 0L

val oneLong = (_: Any) 1L

val oneInt = (_: Any) 1

private val _nullFun = (_: Any) null

private val conforms = (a: Any) a

private val none = (_: Any) None

private val two2none = (_: Any, _: Any) None

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import java.util.concurrent.TimeUnit
import akka.NotUsed
import akka.actor.ActorSystem
import akka.stream.scaladsl._
import akka.util.ConstantFun
import org.openjdk.jmh.annotations._
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.Future
import akka.stream.impl.ConstantFun
import akka.Done

object MaterializationBenchmark {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/
package akka.stream.tck

import akka.stream.impl.ConstantFun
import akka.stream.scaladsl.Sink
import akka.stream.scaladsl.Source
import akka.util.ConstantFun
import org.reactivestreams.Publisher

class FlattenTest extends AkkaPublisherVerification[Int] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import akka.japi.Pair;
import akka.japi.function.*;
import akka.stream.*;
import akka.stream.impl.ConstantFun;
import akka.util.ConstantFun;
import akka.stream.javadsl.GraphDSL.Builder;
import akka.stream.stage.*;
import akka.testkit.AkkaSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import akka.japi.function.*;
import akka.japi.pf.PFBuilder;
import akka.stream.*;
import akka.stream.impl.ConstantFun;
import akka.util.ConstantFun;
import akka.stream.stage.*;
import akka.testkit.AkkaSpec;
import akka.stream.testkit.TestPublisher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

package akka.stream.impl.fusing

import akka.stream.impl.ConstantFun
import akka.stream.stage._
import akka.stream.testkit.StreamSpec
import akka.testkit.EventFilter
import akka.stream._
import akka.stream.impl.fusing.GraphStages.SimpleLinearGraphStage
import akka.util.ConstantFun

class InterpreterSpec extends StreamSpec with GraphInterpreterSpecKit {
import Supervision.stoppingDecider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

package akka.stream.impl.fusing

import akka.stream.impl.ConstantFun
import akka.stream.Supervision
import akka.stream.testkit.StreamSpec
import akka.testkit.LongRunningTest
import akka.util.ConstantFun

class InterpreterStressSpec extends StreamSpec with GraphInterpreterSpecKit {
import Supervision.stoppingDecider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package akka.stream.scaladsl

import akka.NotUsed
import akka.stream.impl.ConstantFun
import akka.util.ConstantFun

import scala.util.control.NoStackTrace
import akka.stream.ActorMaterializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import akka.japi.{ Pair ⇒ JPair }
/**
* INTERNAL API
*/
@deprecated("Use akka.util.ConstantFun instead", "2.5.0")
@InternalApi private[akka] object ConstantFun {
private[this] val JavaIdentityFunction = new JFun[Any, Any] {
@throws(classOf[Exception]) override def apply(param: Any): Any = param
Expand Down
3 changes: 2 additions & 1 deletion akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
*/
package akka.stream.javadsl

import akka.util.ConstantFun
import akka.{ Done, NotUsed }
import akka.event.LoggingAdapter
import akka.japi.{ Pair, function }
import akka.stream.impl.{ ConstantFun, StreamLayout }
import akka.stream.impl.StreamLayout
import akka.stream._
import org.reactivestreams.Processor

Expand Down
2 changes: 1 addition & 1 deletion akka-stream/src/main/scala/akka/stream/javadsl/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package akka.stream.javadsl
import akka.NotUsed
import akka.stream._
import akka.japi.{ Pair, function }
import akka.util.ConstantFun
import scala.annotation.unchecked.uncheckedVariance
import akka.stream.impl.ConstantFun

/**
* Merge several streams, taking elements as they arrive from input streams
Expand Down
3 changes: 2 additions & 1 deletion akka-stream/src/main/scala/akka/stream/javadsl/Source.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ package akka.stream.javadsl
import java.util
import java.util.Optional

import akka.util.ConstantFun
import akka.{ Done, NotUsed }
import akka.actor.{ ActorRef, Cancellable, Props }
import akka.event.LoggingAdapter
import akka.japi.{ Pair, Util, function }
import akka.stream._
import akka.stream.impl.{ ConstantFun, LinearTraversalBuilder, SourceQueueAdapter, StreamLayout }
import akka.stream.impl.{ LinearTraversalBuilder, SourceQueueAdapter, StreamLayout }
import org.reactivestreams.{ Publisher, Subscriber }

import scala.annotation.unchecked.uncheckedVariance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import akka.NotUsed
import akka.event.LoggingAdapter
import akka.japi.function
import akka.stream._
import akka.stream.impl.ConstantFun
import akka.util.ConstantFun

import scala.collection.JavaConverters._
import scala.annotation.unchecked.uncheckedVariance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import akka.NotUsed
import akka.event.LoggingAdapter
import akka.japi.function
import akka.stream._
import akka.stream.impl.ConstantFun
import akka.util.ConstantFun

import scala.collection.JavaConverters._
import scala.annotation.unchecked.uncheckedVariance
Expand Down
1 change: 1 addition & 0 deletions akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import akka.Done
import akka.stream.impl._
import akka.stream.impl.fusing._
import akka.stream.stage._
import akka.util.ConstantFun
import org.reactivestreams.{ Processor, Publisher, Subscriber, Subscription }

import scala.annotation.unchecked.uncheckedVariance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import akka.stream.impl.fusing.GraphStages
import akka.stream.impl.Stages.DefaultAttributes
import akka.stream.scaladsl.Partition.PartitionOutOfBoundsException
import akka.stream.stage.{ GraphStage, GraphStageLogic, InHandler, OutHandler }
import akka.util.ConstantFun

import scala.annotation.unchecked.uncheckedVariance
import scala.annotation.tailrec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package akka.stream.scaladsl

import akka.stream.impl.Stages.DefaultAttributes
import akka.util.ConstantFun
import akka.{ Done, NotUsed }
import akka.actor.{ ActorRef, Cancellable, Props }
import akka.stream.actor.ActorPublisher
Expand Down
Loading

0 comments on commit b3d00af

Please sign in to comment.