| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 866 人关注过本帖
标题:hibernate中一个抽象类MatchMode,源码记录
只看楼主 加入收藏
西鄙人
Rank: 2
等 级:论坛游民
帖 子:36
专家分:12
注 册:2009-12-2
结帖率:100%
收藏
 问题点数:0 回复次数:0 
hibernate中一个抽象类MatchMode,源码记录
该类给大家借鉴的地方,如果某个方法不能实现,而且又不想把继承类和继承层次搞得很复杂,可以使用类似MatchMode的实现方法。

public abstract class MatchMode implements Serializable {
    private final String name;
    private static final Map INSTANCES = new HashMap();

    protected MatchMode(String name) {
        this.name=name;
    }
    public String toString() {
        return name;
    }

    /**
     * Match the entire string to the pattern
     */
    public static final MatchMode EXACT = new MatchMode("EXACT") {
        public String toMatchString(String pattern) {
            return pattern;
        }
    };

    /**
     * Match the start of the string to the pattern
     */
    public static final MatchMode START = new MatchMode("START") {
        public String toMatchString(String pattern) {
            return pattern + '%';
        }
    };

    /**
     * Match the end of the string to the pattern
     */
    public static final MatchMode END = new MatchMode("END") {
        public String toMatchString(String pattern) {
            return '%' + pattern;
        }
    };

    /**
     * Match the pattern anywhere in the string
     */
    public static final MatchMode ANYWHERE = new MatchMode("ANYWHERE") {
        public String toMatchString(String pattern) {
            return '%' + pattern + '%';
        }
    };

    static {
        INSTANCES.put( EXACT.name, EXACT );
        INSTANCES.put( END.name, END );
        INSTANCES.put( START.name, START );
        INSTANCES.put( ANYWHERE.name, ANYWHERE );
    }

    private Object readResolve() {
        return INSTANCES.get(name);
    }

    /**
     * convert the pattern, by appending/prepending "%"
     */
    public abstract String toMatchString(String pattern);

}



[ 本帖最后由 西鄙人 于 2011-4-14 10:54 编辑 ]
搜索更多相关主题的帖子: return 
2011-04-14 10:50
快速回复:hibernate中一个抽象类MatchMode,源码记录
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020702 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved