Retrieve a beautiful resource event value representation
authorChristos KK Loverdos <loverdos@gmail.com>
Thu, 2 Feb 2012 16:42:09 +0000 (18:42 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Thu, 2 Feb 2012 16:42:09 +0000 (18:42 +0200)
src/main/scala/gr/grnet/aquarium/logic/events/ResourceEvent.scala

index a545a1b..c16b4c9 100644 (file)
@@ -72,6 +72,23 @@ case class ResourceEvent(
   def fullResourceInfo = (safeResource, safeInstanceId)
 
   /**
+   * Returns a beautiful string representation of the value.
+   *
+   * @param policy The policy to be asked for resources.
+   * @return A beautiful string representation of the value.
+   */
+  def beautifyValue(policy: DSLPolicy): String = {
+    policy.findResource(this.resource) match {
+      case Some(DSLComplexResource(_, _, OnOffCostPolicy, _)) ⇒
+        OnOffPolicyResourceState(this.value).state.toUpperCase
+      case Some(DSLSimpleResource(_, _, OnOffCostPolicy)) ⇒
+        OnOffPolicyResourceState(this.value).state.toUpperCase
+      case _ ⇒
+        value.toString
+    }
+  }
+
+  /**
    * Return `true` iff this is an event regarding a resource with an
    * [[gr.grnet.aquarium.logic.accounting.dsl.OnOffCostPolicy]].
    */