Posted on 2007-10-23 10:34
G_G 阅读(539)
评论(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;
}
//感觉是可以更好的代码编写