SmallSense__UnionType.st
changeset 91 920e30d788dc
parent 67 020b7461b15e
child 103 2d478ebc2456
--- a/SmallSense__UnionType.st	Wed Sep 18 00:59:55 2013 +0100
+++ b/SmallSense__UnionType.st	Wed Sep 18 01:29:45 2013 +0100
@@ -16,7 +16,12 @@
     "Return an integer value in <1..100>, higher value
      means the object is more likely of that type."
 
-    ^ self shouldImplement
+    trustfullness isNil ifTrue:[
+        self updateTrustfullness
+    ].
+    ^ trustfullness
+
+    "Modified: / 18-09-2013 / 01:16:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 trustfullness: anInteger
@@ -83,13 +88,19 @@
         self basicAddTypes: type types.
     ] ifFalse:[
         type isUnknownType ifFalse:[
-            (types includes: type) ifFalse:[
+            | existing |
+
+            existing := types detect:[:each | each = type ] ifNone:[nil].
+            existing isNil ifTrue:[
                 types add: type.
+            ] ifFalse:[
+                existing trustfullness: (existing trustfullness max: type trustfullness)
             ]
         ]
     ].
 
     "Created: / 17-05-2012 / 19:27:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 18-09-2013 / 01:14:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 basicAddTypes: someTypes
@@ -193,16 +204,18 @@
 
 updateTrustfullness
     "Recompute the trustfullness, This is subject to tuning"
-
-                    "Average if individual types"
-    types isEmpty ifTrue:[
+    "Average if individual types"
+    
+    types isEmpty ifTrue: [
         trustfullness := 1
-    ] ifFalse:[
-        trustfullness := (types inject:0 into:[:a :type|a + type trustfullness]) / types size.
+    ] ifFalse: [
+        trustfullness := (types inject: 0
+                into: [:a :type | a + type trustfullness ]) / types size.
         trustfullness := trustfullness + (trustfullnessBonus ? 0).
     ].
 
     "Created: / 17-05-2012 / 19:22:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 18-09-2013 / 01:08:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !UnionType methodsFor:'testing'!