title: Groovy MultivaluedHash Map
body: <p>Can someone help me to solve the problem</p>
  
  <p><strong>Problem Description</strong>
  Create a class Asset with the following member variables.
  def <code>name</code>
  def <code>assetNumber</code>
  def <code>model</code>
  def <code>lastAssignedDate</code>
  def <code>price</code>
  Input Format:
  The first input corresponds to string asset name.
  The second input corresponds to an integer asset number.
  The third input corresponds to string asset model.
  The fourth input corresponds to the date last assigned the date.
  The fifth input corresponds to double asset price.
  Next input is a string denotes when there is one more asset detail or not. (Yes/No)</p>
  
  <p>Output Format:
  If the <code>assetNumber</code> is found print <code>Asset with _assetNumber_ found.</code> or <code>Asset with _assetNumber_ not found.</code>
  Refer sample input and output. [All bold text corresponds to input and rest are the output.]</p>
  
  <p>Asset <code>name:name1</code>
  Asset <code>number:1</code>
  Asset <code>model:mod1</code>
  Assigned <code>date:01/01/2015</code>
  Price: <code>100.24</code>
  Do you want to continue? (Yes/No): Yes
  Asset <code>name:name2</code>
  Asset <code>number:2</code>
  Asset <code>model:mod2</code>
  Assigned <code>date:01/01/2016</code>
  Price: <code>200.24</code>
  Do you want to continue? (Yes/No): No
  1
  2
  Enter the number to search:
  The asset with 2 found.</p>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>def class Asset
  {
    def name;
    def assetNumber
    def model
    def lastAssignedDate
    def price
  
    def constructAsset(Map classMap)
    {
      this.name=classMap['name'];
      this.assetNumber=classMap['assetNumber'];
      this.model=classMap['model'];
      this.lastAssignedDate=classMap['lastAssignedDate'];
      this.price=classMap['price']
      return classMap; 
    }
    def findNumber(Map classMap,int num) 
    {
      //println classMap
      for ( e in classMap )
      {
        if ("${e.key}" == "assetNumber")
        {    
          println ("${e.value}")  
        }  
      }
      def myKey = classMap.find{ it.value == num }?.key;
      if(myKey)
      {println("Asset with " + num + " found.")}
      else
      {println("Asset with " + num + " not found.")}
  
     }
  
  
  }
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  
  def name;
  def assetNumber;
  def model
  def lastAssignedDate
  def price
  def cont="Yes"
  Asset a=new Asset();
  def list=[:]
  while(cont=="Yes")
  {
    println("Asset name:");
    name=br.readLine();
  
    println("Asset number:");
    assetNumber=br.readLine().toInteger();
  
    println("Asset model:")
    model=br.readLine()  
  
    println("Assigned date:")
    lastAssignedDate=br.readLine();
    lastAssignedDate=Date.parse("dd/mm/yyyy", lastAssignedDate).format("dd-mm-yyyy")
  
    println("Price:")
    price=br.readLine().toDouble()
    list &lt;&lt; a.constructAsset(name:"$name",assetNumber:"$assetNumber",model:"$model",lastAssignedDate:"$lastAssignedDate",price:"$price");
  
    println("Do you want to continue?(Yes/No)");
    cont=br.readLine();
  
  
  }
  println("Enter the number to search:")
  def num=br.readLine().toInteger();
  a.findNumber(list,num)
  </code></pre>
  
  <p><strong>Expected Output</strong>
  Asset name:name1
  Asset number:1
  Asset model:mod1
  Assigned date:01/01/2015
  Price:100.24
  Do you want to continue? (Yes/No): Yes
  Asset name:name2
  Asset number:2
  Asset model:mod2
  Assigned date:01/01/2016
  Price:200.24
  Do you want to continue? (Yes/No): No
  1
  2
  Enter the number to search:
  The asset with 2 found.</p>
  
  <p><strong>Actual Output</strong>
  Asset name:name1
  Asset number:1
  Asset model:mod1
  Assigned date:01/01/2015
  Price:100.24
  Do you want to continue? (Yes/No): Yes
  Asset name:name2
  Asset number:2
  Asset model:mod2
  Assigned date:01/01/2016
  Price:200.24
  Do you want to continue? (Yes/No): No
  1
  2
  Enter the number to search:
  The asset with 2 found.</p>
  
  <p><strong>Issue</strong>
  When adding key values, map always holds the recently entered value.
  So when I am printing asset number value, it's printing the recent value. But not printing the first value entered. In this example expecting Asset Numbers 1 and 2. But printing only 2. (Next to Do you want to continue? (Yes/No))</p>