diff --git a/akka-stream/src/main/scala/akka/stream/Attributes.scala b/akka-stream/src/main/scala/akka/stream/Attributes.scala index 0863a2b2cd..a6815c12db 100644 --- a/akka-stream/src/main/scala/akka/stream/Attributes.scala +++ b/akka-stream/src/main/scala/akka/stream/Attributes.scala @@ -5,9 +5,7 @@ package akka.stream import akka.event.Logging import scala.annotation.tailrec -import scala.collection.immutable import scala.reflect.{ classTag, ClassTag } -import akka.stream.impl.Stages.SymbolicStage import akka.japi.function /** @@ -53,12 +51,28 @@ final case class Attributes(attributeList: List[Attributes.Attribute] = Nil) { case None ⇒ default } + /** + * Java API: Get the first (least specific) attribute of a given `Class` or subclass thereof. + * If no such attribute exists the `default` value is returned. + */ + def getFirstAttribute[T <: Attribute](c: Class[T], default: T): T = + getFirstAttribute(c) match { + case Some(a) ⇒ a + case None ⇒ default + } + /** * Java API: Get the last (most specific) attribute of a given `Class` or subclass thereof. */ def getAttribute[T <: Attribute](c: Class[T]): Option[T] = Option(attributeList.foldLeft(null.asInstanceOf[T])((acc, attr) ⇒ if (c.isInstance(attr)) c.cast(attr) else acc)) + /** + * Java API: Get the first (least specific) attribute of a given `Class` or subclass thereof. + */ + def getFirstAttribute[T <: Attribute](c: Class[T]): Option[T] = + attributeList.find(c isInstance _).map(c cast _) + /** * Get the last (most specific) attribute of a given type parameter T `Class` or subclass thereof. * If no such attribute exists the `default` value is returned. @@ -66,12 +80,25 @@ final case class Attributes(attributeList: List[Attributes.Attribute] = Nil) { def get[T <: Attribute: ClassTag](default: T) = getAttribute(classTag[T].runtimeClass.asInstanceOf[Class[T]], default) + /** + * Get the first (least specific) attribute of a given type parameter T `Class` or subclass thereof. + * If no such attribute exists the `default` value is returned. + */ + def getFirst[T <: Attribute: ClassTag](default: T) = + getAttribute(classTag[T].runtimeClass.asInstanceOf[Class[T]], default) + /** * Get the last (most specific) attribute of a given type parameter T `Class` or subclass thereof. */ def get[T <: Attribute: ClassTag] = getAttribute(classTag[T].runtimeClass.asInstanceOf[Class[T]]) + /** + * Get the first (least specific) attribute of a given type parameter T `Class` or subclass thereof. + */ + def getFirst[T <: Attribute: ClassTag] = + getFirstAttribute(classTag[T].runtimeClass.asInstanceOf[Class[T]]) + /** * Adds given attributes to the end of these attributes. */ diff --git a/akka-stream/src/main/scala/akka/stream/impl/ActorMaterializerImpl.scala b/akka-stream/src/main/scala/akka/stream/impl/ActorMaterializerImpl.scala index 84a977cfbd..e8ff274c24 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/ActorMaterializerImpl.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/ActorMaterializerImpl.scala @@ -55,8 +55,7 @@ private[akka] case class ActorMaterializerImpl(system: ActorSystem, case InputBuffer(initial, max) ⇒ s.withInputBuffer(initial, max) case Dispatcher(dispatcher) ⇒ s.withDispatcher(dispatcher) case SupervisionStrategy(decider) ⇒ s.withSupervisionStrategy(decider) - case l: LogLevels ⇒ s - case Name(_) ⇒ s + case _ ⇒ s } } }