View Javadoc
1   package us.codecraft.webmagic.utils;
2   
3   /**
4    * @author code4crafter@gmail.com
5    */
6   
7   import java.util.HashMap;
8   import java.util.Map;
9   
10  /**
11   * multi-key map, some basic objects *
12   *
13   * @author yihua.huang
14   */
15  public abstract class MultiKeyMapBase {
16  
17      protected static final Class<? extends Map> DEFAULT_CLAZZ = HashMap.class;
18      @SuppressWarnings("rawtypes")
19      private Class<? extends Map> protoMapClass = DEFAULT_CLAZZ;
20  
21      public MultiKeyMapBase() {
22      }
23  
24      @SuppressWarnings("rawtypes")
25      public MultiKeyMapBase(Class<? extends Map> protoMapClass) {
26          this.protoMapClass = protoMapClass;
27      }
28  
29      @SuppressWarnings("unchecked")
30      protected <K, V2> Map<K, V2> newMap() {
31          try {
32              return (Map<K, V2>) protoMapClass.newInstance();
33          } catch (InstantiationException e) {
34              throw new IllegalArgumentException("wrong proto type map "
35                      + protoMapClass);
36          } catch (IllegalAccessException e) {
37              throw new IllegalArgumentException("wrong proto type map "
38                      + protoMapClass);
39          }
40      }
41  }