View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.tck.testmodels.fruit;
8   
9   import java.util.Map;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.ArrayList;
14  
15  /**
16   * TODO
17   */
18  public class FruitBasket
19  {
20      private final Map basket = Collections.synchronizedMap(new HashMap());
21  
22      public boolean hasApple()
23      {
24          return basket.get(Apple.class) != null;
25      }
26  
27      public boolean hasBanana()
28      {
29          return basket.get(Banana.class) != null;
30      }
31  
32      public void setFruit(Fruit[] fruit)
33      {
34          for (int i = 0; i < fruit.length; i++)
35          {
36              basket.put(fruit[i].getClass(), fruit[i]);
37          }
38      }
39  
40      public void setFruit(List fruit)
41      {
42          this.setFruit((Fruit[]) fruit.toArray(new Fruit[fruit.size()]));
43      }
44  
45      public List getFruit()
46      {
47          return new ArrayList(basket.values());
48      }
49  
50      public Apple getApple()
51      {
52          return (Apple) basket.get(Apple.class);
53      }
54  
55      public Banana getBanana()
56      {
57          return (Banana) basket.get(Banana.class);
58      }
59  }