View Javadoc

1   /*
2    * Copyright 2007-2010 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.testclient1;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.concurrent.ConcurrentHashMap;
22  import java.util.concurrent.atomic.AtomicInteger;
23  
24  import org.kuali.rice.ksb.messaging.remotedservices.BaseballCard;
25  import org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService;
26  
27  /**
28   * Implementation for {@link BaseballCardCollectionService}
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   *
32   */
33  public class BaseballCardCollectionServiceImpl implements BaseballCardCollectionService {
34      
35      private Map<Integer, BaseballCard> cards = new ConcurrentHashMap<Integer, BaseballCard>();
36      private AtomicInteger nextId = new AtomicInteger(1);
37      
38      /**
39       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#add(org.kuali.rice.ksb.messaging.remotedservices.BaseballCard)
40       */
41      public Integer add(BaseballCard card) {
42          Integer result = null;
43          if (card != null) {
44              int id = nextId.addAndGet(1);
45              cards.put(id, card);
46              result = id;
47          }
48          return result;
49      }
50  
51      /**
52       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#delete(java.lang.Integer)
53       */
54      public void delete(Integer id) {
55          cards.remove(id);
56      }
57  
58      /**
59       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#get(java.lang.Integer)
60       */
61      public BaseballCard get(Integer id) {
62          return cards.get(id);
63      }
64  
65      /**
66       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#get(java.lang.String)
67       */
68      public List<BaseballCard> get(String playerName) {
69          List<BaseballCard> results = new ArrayList<BaseballCard>();
70          for (BaseballCard card : cards.values()) {
71              if (playerName.equals(card.getPlayerName())) results.add(card);
72          }
73          return results;
74      }
75  
76      /**
77       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#getAll()
78       */
79      public List<BaseballCard> getAll() {
80          return new ArrayList<BaseballCard>(cards.values());
81      }
82  
83      /**
84       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#update(java.lang.Integer, org.kuali.rice.ksb.messaging.remotedservices.BaseballCard)
85       */
86      public void update(Integer id, BaseballCard card) {
87          cards.put(id, card);
88      }
89      
90      /**
91       * This method lacks JAX-RS annotations in the {@link BaseballCardCollectionService} interface
92       * 
93       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#unannotatedMethod()
94       */
95      public void unannotatedMethod() {
96          // do nothing
97      }
98  
99  }