定义一些类,这些类之间有父子关系,如下:

class Father{}
class Son1 extends Father{}
class Son2 extends Father{}

class Top{}
class Middle extends Top{}
class Bottom extends Middle{}

1、incl()方法

源代码如下:

/** Add type set to given type list, unless
 *  it is a subclass of some class  in the list.
 */
public List<Type> incl(Type t, List<Type> ts) {
    List<Type> result;
    // 如果t是ts列表中一些类的子类,则返回这个ts
    if(subset(t,ts)){
        result = ts;
    }else{
        // 如果ts列表中有些类是t的子类,则从ts列表中移除这些子类,
        // 然后追加t后将这个ts列表返回
        List<Type> temp = excl(t, ts);
        result = temp.prepend(t);
    }
    return result;
}

  

2、excl()方法  

源代码如下:

/** Remove type set from type set list.
 */
// 如果ts列表中有些类是t的子类,则从ts列表中移除这些子类后返回,
// 如果ts列表为空,表示没有可移除的或者说已经全部被移除完了,
// 直接返回ts空列表
public List<Type> excl(Type t, List<Type> ts) {
    if (ts.isEmpty()) {
        return ts;
    } else {
        // 需要清楚知道List<Type>这个类型的实现机制
        List<Type> ts1 = excl(t, ts.tail); // 递归
        // 当ts.head是t的子类时,移除这个ts.head,返回ts.tail
        // 处理后的结果
        if (types.isSubtypeCapture(ts.head, t)) {
            return ts1;
        }
        // 当ts.head没有成为t的子类时,则列表中不需要移除
        // 这个ts.head,直接返回ts
        else if (ts1 == ts.tail) {
            return ts;
        }
        // 当ts.head没有成为t的子类时且ts.tail处理结果也有变动,
        // 则追加ts.head到ts1后返回
        else {
            return ts1.prepend(ts.head);
        }
    }
}

  

3、并集union()方法

源代码如下:

/** Form the union of two type set lists.
 */
public List<Type> union(List<Type> ts1, List<Type> ts2) {
    List<Type> ts = ts1;
    for (List<Type> l = ts2; l.nonEmpty(); l = l.tail) {
        ts = incl(l.head, ts);
    }
    return ts;
}

  

4、差集diff()方法

源代码如下:

/** Form the difference of two type lists.
 */
// 如果ts1列表有些类是ts2列表中某些类的子类,则从ts1
// 列表中移除这些子类,最后返回ts1中剩余的类
public List<Type> diff(List<Type> ts1, List<Type> ts2) {
    List<Type> ts = ts1;
    for (List<Type> l = ts2; l.nonEmpty(); l = l.tail) {
        ts = excl(l.head, ts);
    }
    return ts;
}

  

5、交集intersect()方法

可能可以这样理解:找ts1与ts2中共同抛出的异常,那么对Father与Son1、Son2来说,可能抛出的共同异常就是Son1和Son2

对于Middle与Top、Bottom来说,

源代码如下:

/** Form the intersection of two type lists.
 */
// 如果有ts1列表中含有Father类型,而ts2中含有Father的
// 子类Sub1,Sub2 时,最终返回Sub1,Sub2,表示这个
// Father类型能够catch那两个子类型
public List<Type> intersect(List<Type> ts1, List<Type> ts2) { // todo
    List<Type> ts = List.nil();
    for (List<Type> l = ts1; l.nonEmpty(); l = l.tail) {
        if (subset(l.head, ts2)) {
            ts = incl(l.head, ts);
        }
    }
    for (List<Type> l = ts2; l.nonEmpty(); l = l.tail) {
        if (subset(l.head, ts1)) {
            ts = incl(l.head, ts);
        }
    }
    return ts;
}

  

Check类中的incl、union,excl,diff,intersect的更多相关文章

  1. Sql中的并(UNION)、交(INTERSECT)、差(minus)、除去(EXCEPT)详解

    UNION 查询选修了180101号或180102号课程或二者都选修了的学生学号.课程号和成绩. (SELECT  学号, 课程号, 成绩 FROM   学习 WHERE   课程号='180101' ...

  2. Check类之duplicate declaration checking/Class name generation/Type Checking

    1.duplicate declaration checking /** Check that variable does not hide variable with same name in * ...

  3. python---Django中模型类中Meta元对象了解

    Django中模型类中Meta元对象了解 1.使用python manage.py shell 进入编辑命令行模式,可以直接进入项目(为我们配置好了环境) python manage.py shell ...

  4. Tomcat是如何将请求一步步传递到我们编写的HttpServlet类中的

    我们平常编写好的HttpServlet类后,就可以处理请求了,但是服务器在接收到请求信息以后是如何将这些请求传递到我们编写的Servlet类中的???这个疑问在我心中的已经很久了,现在要来解决它. 我 ...

  5. 在JBPM的Handle类中调用Spring管理的类

    我们在使用JBPM定义流程的时候经常要在流程定义文件中加入一个继承xxxHandler的类来实现我们的业务逻辑判断或者其他的需求,在这个类中一般都是用Spring的Application来获取,而这种 ...

  6. 编写一个应用程序,在主类Test1类中,创建两个链表List<E>对象,分别存储通过键盘输入的字符串内容

    题目1:编写一个应用程序,在主类Test1类中,创建两个链表List<E>对象,分别存储通过键盘输入的字符串内容--"chen","wang",&q ...

  7. 揭开C++类中虚表的“神秘面纱”

    C++类中的虚表结构是C++对象模型中一个重要的知识点,这里咱们就来深入分析下虚表的在内存中的结构. C++一个类中有虚函数的话就会有一个虚表指针,其指向对应的虚表,一般一个类只会有一个虚表,每个虚表 ...

  8. Python类中super()和__init__()的关系

    Python类中super()和__init__()的关系 1.单继承时super()和__init__()实现的功能是类似的 class Base(object): def __init__(sel ...

  9. Hibernate jpa 在实体类中对于时间的注解

    在时间类型DATE 属性上添加一个 @Temporal(TemporalType.DATE)(精确到年月日)@Temporal(TemporalType.TIME)(精确到时分秒)@Temporal( ...

随机推荐

  1. Linux下配置Nginx(在root的/etc/rc.local里配置开机启动功能http://tengine.taobao.org/)

    上面是下载的包下载地址 http://tengine.taobao.org/download_cn.html nginx官网http://nginx.org/ 下一步 下一步 其中remote为重要属 ...

  2. hdu 5039 线段树+dfs序

    http://acm.hdu.edu.cn/showproblem.php?pid=5039 给定一棵树,边权为0/1.m个操作支持翻转一条边的权值或者询问树上有多少条路径的边权和为奇数. 用树形df ...

  3. 通过FactoryBean方式来配置bean

    1.实现FactoryBean接口的java类: 2.相应的.xml文件:

  4. 【加密算法】AES

    一.简介 AES(Advanced Encryption Standard):高级加密标准,是下一代的加密算法标准,速度快,安全级别高. 用AES加密2000年10月,NIST(美国国家标准和技术协会 ...

  5. HttpWebRequest 模拟浏览器访问网站

    最近抓网页时报错: 要么返回 The remote server returned an error: (442)要么返回: 非法访问,您的行为已被WAF系统记录! 想了想,就当是人家加了抓网页的东西 ...

  6. C#Winfrom Listview数据导入Excel

    需引用 public void ExportToExecl() { System.Windows.Forms.SaveFileDialog sfd = new SaveFileDialog(); sf ...

  7. Android学习之ViewPager

     1.定义 ViewPager是android扩展包v4包中的类,这个类可以让用户左右切换当前的view.其中,android.support.v4是谷歌公司为了解决当前版本碎片化的问题,从而提供的一 ...

  8. “全栈2019”Java多线程第十八章:同步代码块双重判断详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  9. python django 更改模型字段出错时的一个解决办法

    python/django 框架自带的 orm 无疑是django框架最拿得出手的一个亮点,orm无疑极大的方便了项目的开发,提高了开发的效率. 在实际的项目开发过程中,我们有时候需要修改模型的字段, ...

  10. 使用putty连接本地VirtualBox上的centos7 linux主机

    1. 查看linux主机默认ssh端口 因为是使用ssh连接虚拟机上的linux主机的,所以需要查看centos ssh默认端口,一般是22 打开终端 输入cd /etc/ssh/ 查看ssh_con ...