Clover Coverage Report - KS Common UI 1.3.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
14   115   9   2.33
6   46   0.64   6
6     1.5  
1    
 
  CollectionModel       Line # 37 14 0% 9 26 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.common.ui.client.mvc;
17   
18    import java.util.ArrayList;
19    import java.util.Collection;
20    import java.util.Collections;
21    import java.util.HashMap;
22    import java.util.Map;
23   
24    import org.kuali.student.common.dto.Idable;
25    import org.kuali.student.common.ui.client.mvc.ModelChangeEvent.Action;
26   
27    import com.google.gwt.event.shared.HandlerManager;
28    import com.google.gwt.event.shared.HandlerRegistration;
29   
30    /**
31    * Model object used as a container for the model state. Sources ModelChangeEvents used for tracking the model state.
32    *
33    * @author Kuali Student Team
34    * @param <T>
35    * the type of model object to be contained within the model
36    */
 
37    public class CollectionModel<T> implements Model {
38    private Map<String, T> data = new HashMap<String, T>();
39    private HandlerManager handlers = new HandlerManager(this);
40   
41    private T value = null;
42    /**
43    * Adds an object to the model, and fires a ModelChangeEvent
44    * @param object
45    */
 
46  0 toggle public void add(T object) {
47  0 if (object instanceof Idable){
48  0 data.put(((Idable)object).getId(), object);
49  0 handlers.fireEvent(new CollectionModelChangeEvent<T>(Action.ADD, this, object));
50    }
51    }
52   
53    /**
54    * Removes the specified model object from the model
55    *
56    * @param object
57    * @return the object that was removed, or null if not found
58    * @deprecated should use new Data structures instead, accessed via getValue, setValue
59    */
 
60  0 toggle public T remove(T object) {
61  0 if (object instanceof Idable){
62  0 T result = data.remove(((Idable)object).getId());
63  0 if (result != null) {
64  0 handlers.fireEvent(new CollectionModelChangeEvent<T>(Action.REMOVE, this, result));
65    }
66  0 return result;
67    } else {
68  0 return null;
69    }
70    }
71   
72    /**
73    * Adds a ModelChangeHandler that will be invoked for ModelChangeEvents
74    *
75    * @param handler
76    * the handler to add
77    * @return HandlerRegistration that can be used to unregister the handler later
78    */
 
79  0 toggle @Override
80    public HandlerRegistration addModelChangeHandler(ModelChangeHandler handler) {
81  0 return handlers.addHandler(ModelChangeEvent.TYPE, handler);
82    }
83   
84    /**
85    * Returns an unsorted, umodifiable collection of the values contained within the model.
86    *
87    * @return an unsorted, umodifiable collection of the values contained within the model.
88    */
 
89  0 toggle public Collection<T> getValues() {
90  0 return Collections.unmodifiableList(new ArrayList<T>(data.values()));
91    }
92   
93   
94    /**
95    * Returns the Model's value
96    * Going forward, the Model class should primarily be used with a single DataModel instance for use with the configurable UI framework.
97    * @return the Model's value
98    */
 
99  0 toggle public T getValue() {
100  0 return value;
101    }
102   
103    /**
104    * Sets the Model's value
105    * Going forward, the Model class should primarily be used with a single DataModel instance for use with the configurable UI framework.
106    * @param value the new value
107    */
 
108  0 toggle public void setValue(T value) {
109  0 this.value = value;
110  0 handlers.fireEvent(new CollectionModelChangeEvent<T>(Action.RELOAD, this, value));
111    }
112   
113   
114   
115    }