View Javadoc

1   /*
2    * $Id: MapIndexesModel.java,v 1.18 2011/06/16 09:29:41 jbmeslin Exp $
3    */
4   package org.rcfaces.core.model;
5   
6   import java.util.Map;
7   
8   /**
9    * @author Olivier Oeuillot (latest modification by $Author: jbmeslin $)
10   * @version $Revision: 1.18 $ $Date: 2011/06/16 09:29:41 $
11   */
12  public class MapIndexesModel extends CollectionIndexesModel {
13  
14      private static final String REVISION = "$Revision: 1.18 $";
15  
16      private static final long serialVersionUID = -6123923382601149193L;
17  
18      private static final Object DEFAULT_VALUE = Boolean.TRUE;
19  
20      private final Map map;
21  
22      private final Object defaultValue;
23  
24      public MapIndexesModel(Map map) {
25          this(map, DEFAULT_VALUE);
26      }
27  
28      public MapIndexesModel(Map map, Object defaultValue) {
29          super(map.keySet());
30  
31          this.map = map;
32          this.defaultValue = defaultValue;
33      }
34  
35      public boolean addIndex(int index) {
36          if (commited) {
37              throw new IllegalStateException("Already commited indexes model.");
38          }
39  
40          map.put(getKey(index), getSelectedValue(index));
41  
42          return true;
43      }
44  
45      protected Object getSelectedValue(int index) {
46          return defaultValue;
47      }
48  
49      public IIndexesModel copy() {
50          return new MapIndexesModel(map, defaultValue);
51      }
52  
53  }