bsloane1650 commented on a change in pull request #264: WIP - DAFFODIL-2169
URL: https://github.com/apache/incubator-daffodil/pull/264#discussion_r307046106
##########
File path: daffodil-lib/src/main/scala/org/apache/daffodil/util/DataValue.scala
##########
@@ -0,0 +1,91 @@
+package org.apache.daffodil.infoset
+
+import java.lang.{ Boolean => JBoolean, Number => JNumber, Long => JLong,
Double => JDouble, String => JString, Float => JFloat, Byte => JByte, Integer
=> JInt, Short => JShort }
+import java.math.{ BigDecimal => JBigDecimal, BigInteger => JBigInt }
+import org.apache.daffodil.calendar.DFDLCalendar
+
+/*
+ * DINode is not visible to Daffodil-lib, so we cannot actually reference this
here.
+ * We are trusting the rest of the codebase to only apply DataValueDINode to
the DINode
+ * class.
+ * The DINode class itself defines an implicit DataValueDINode -> DINode
conversion
+ */
+trait DataValueDINodeTrait extends NonNullable;
+
+trait NonNullable;
+trait Nullable extends NonNullable;
+sealed trait DataValuePrimitiveType
+
+final class DataValue[+T <: AnyRef, +X<:AnyRef] private (val v: T) extends
AnyVal {
+ def isEmpty = DataValue.NoValue.v eq v
+ def isDefined = !isEmpty
+ def value = v
+ override def toString = if (isEmpty) "NoValue" else "DataValue("+ v.toString
+")"
+
+ def getAnyRef = v.asInstanceOf[AnyRef]
Review comment:
Technically, v is of type T, so I would have to explicitly add the type
annotation of getAnyRef, otherwise getAnyRef would return type T. That would
probably be fine, since Scala can upcast at the callpoint just as easily. This
asInstanceOf is mostly just to be consistent with the rest. The only downside I
can see is that it might invoke an extra type-check at runtime, but I would
hope Scala knows not to bother actually checking that an object is an AnyRef
(and even if it wasn't, as you point out, the type constraint explicitly
guarantees that this is just an upcast, so Scala has a second way of knowing to
omit it at runtime).
----------------------------------------------------------------
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