stevedlawrence commented on a change in pull request #326: Daffodil 2280 
cleanup - removes backpointers and factory patterns no longer needed
URL: https://github.com/apache/incubator-daffodil/pull/326#discussion_r393702026
 
 

 ##########
 File path: 
daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/ChoiceAndOtherVariousUnparsers.scala
 ##########
 @@ -17,26 +17,59 @@
 
 package org.apache.daffodil.processors.unparsers
 
+import org.apache.daffodil.processors._
 import org.apache.daffodil.infoset._
 import org.apache.daffodil.processors.RuntimeData
-import org.apache.daffodil.processors._
 import org.apache.daffodil.processors.dfa.DFADelimiter
 import org.apache.daffodil.schema.annotation.props.gen.ChoiceLengthKind
-import org.apache.daffodil.util.Maybe
 import org.apache.daffodil.util.Maybe._
+import org.apache.daffodil.util.Maybe
 import org.apache.daffodil.util.MaybeInt
+import org.apache.daffodil.util.Maybe._
+import org.apache.daffodil.exceptions.Assert
+import org.apache.daffodil.util.PreSerialization
+
+case class ChoiceBranchMap(
+  lookupTable: Map[ChoiceBranchEvent, Unparser],
+  unmappedDefault: Option[Unparser])
+  extends PreSerialization {
+
+  @throws(classOf[java.io.IOException])
+  private def writeObject(out: java.io.ObjectOutputStream): Unit = 
serializeObject(out)
+
+  def get(cbe: ChoiceBranchEvent): Maybe[Unparser] = {
+    val fromTable = lookupTable.get(cbe)
+    val res =
+      if (fromTable.isDefined) One(fromTable.get)
+      else {
+        //
+        // There must be an unmapped default in this case
+        // because otherwise the map is incomplete.
+        //
+        if (unmappedDefault.isDefined)
+          One(unmappedDefault.get)
+        else
+          Nope
+      }
+    res
+  }
+
+  def childProcessors = lookupTable.map { case (k, v) => v }.toSeq ++ 
unmappedDefault
 
 Review comment:
   Instead of the map, I think we can do loopupTable.values.toSeq, a little 
easier to read.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to