View Javadoc

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