posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          源碼分析

          Posted on 2007-10-23 10:34 G_G 閱讀(546) 評論(0)  編輯  收藏 所屬分類: hibernate
          1.CollectionHelper 對List,Set,Map 包裝出不可修改的
          public?final?class?CollectionHelper?{
          ????
          public?static?final?List?EMPTY_LIST?=?Collections.unmodifiableList(?new?ArrayList(0)?);
          ????
          public?static?final?Collection?EMPTY_COLLECTION?=?Collections.unmodifiableCollection(?new?ArrayList(0)?);
          ????
          public?static?final?Map?EMPTY_MAP?=?Collections.unmodifiableMap(?new?HashMap(0)?);
          ????
          private?CollectionHelper()?{}
          }
          ??? 1.1 在Collections.unmodifiableList(...)是靜態內部類個構造方法
          ??? ?? 悟: 從上面看出是一個非常好的? 適配器 ?
          ???//1.Collections 中 new 出內部類
          ??? public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c) {
          ??? ??? return new UnmodifiableCollection<T>(c);
          ??? }



          ??? //2.
          內部類也繼承 Collection
          ??? static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
          ??? private?static?final?long?serialVersionUID?=?1820017752578914078L;

          ????
          final?Collection<??extends?E>?c;
          ??? //3.很好適配 Collection 通過他把 add remove 等功能 封裝
          ????UnmodifiableCollection(Collection
          <??extends?E>?c)?{
          ????????????
          if?(c==null)
          ????????????????
          throw?new?NullPointerException();
          ????????????
          this.c?=?c;
          ????????}
          ??? ...............

          2.大量使用內部類枚矩 ?如:
          Mappings.PropertyReference?upr?=?(Mappings.PropertyReference)?iter.next();
          ////////////////////////////////////////////////
          Mappings中
          ????
          static?final?class?PropertyReference?implements?Serializable?{
          ????????String?referencedClass;
          ????????String?propertyName;
          ????????
          boolean?unique;
          ????}

          //感覺是可以更好的代碼編寫




          主站蜘蛛池模板: 莱芜市| 隆回县| 辰溪县| 黎川县| 兰溪市| 东乡县| 毕节市| 资兴市| 格尔木市| 新巴尔虎左旗| 吴忠市| 潼南县| 梅州市| 卢湾区| 巨鹿县| 定陶县| 贵溪市| 巴楚县| 石阡县| 古田县| 邛崃市| 高雄县| 顺昌县| 台前县| 保山市| 苍山县| 桐柏县| 邵东县| 三穗县| 乐山市| 尉犁县| 思南县| 宁城县| 石河子市| 壶关县| 辛集市| 宝清县| 佛教| 疏附县| 商丘市| 清徐县|