Skip to content

Commit 8234644

Browse files
author
Russell Aronson
committed
Add safeCopy to Fact
1 parent 93ece6f commit 8234644

File tree

1 file changed

+16
-6
lines changed
  • ivory-core/src/main/scala/com/ambiata/ivory/core

1 file changed

+16
-6
lines changed

ivory-core/src/main/scala/com/ambiata/ivory/core/Fact.scala

+16-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ trait Fact {
1818

1919
def toNamespacedThrift: NamespacedThriftFact with NamespacedThriftFactDerived
2020

21+
def safeCopy: Fact =
22+
FatThriftFact.factWith(entity, namespace, feature, date, time, value match {
23+
case BooleanValue(b) => ThriftFactValue.b(b)
24+
case IntValue(i) => ThriftFactValue.i(i)
25+
case LongValue(l) => ThriftFactValue.l(l)
26+
case DoubleValue(d) => ThriftFactValue.d(d)
27+
case StringValue(s) => ThriftFactValue.s(s)
28+
case TombstoneValue() => ThriftFactValue.t(new ThriftTombstone())
29+
})
30+
2131
lazy val stringValue: Option[String] =
2232
value.stringValue
2333

@@ -60,19 +70,19 @@ object Fact {
6070
}
6171

6272
trait NamespacedThriftFactDerived extends Fact { self: NamespacedThriftFact =>
63-
def namespace =
73+
def namespace: String =
6474
nspace
6575

66-
def feature =
76+
def feature: String =
6777
fact.attribute
6878

69-
def date =
79+
def date: Date =
7080
Date.unsafeFromInt(yyyyMMdd)
7181

72-
def time =
82+
def time: Time =
7383
Time.unsafe(seconds)
7484

75-
def datetime =
85+
def datetime: DateTime =
7686
date.addTime(time)
7787

7888
def entity: String =
@@ -94,7 +104,7 @@ trait NamespacedThriftFactDerived extends Fact { self: NamespacedThriftFact =>
94104
case _ => sys.error(s"You have hit a code generation issue. This is a BUG. Do not continue, code needs to be updated to handle new thrift structure. [${fact.toString}].'")
95105
}
96106

97-
def toThrift = fact
107+
def toThrift: ThriftFact = fact
98108

99109
def toNamespacedThrift = this
100110
}

0 commit comments

Comments
 (0)