zoukankan      html  css  js  c++  java
  • java它们的定义ArrayList序列, 大神跳跃

    一个list有两种类型的对象,今天有需求必须责令不同的约会对象,这里是代码

    /**
    *@author xh1991101@163.com
    */

    List<Message> messages=messageSrv.getList(u.getUserId());

    List<Object> messageList=new ArrayList<Object>();
    for(Object o:messages){
    messageList.add(o);
    }
    for(Object o:checks){
    messageList.add(o);
    }
    Collections.sort(messageList,  new Comparator(){
    public int compare(Object o1, Object o2) {
    if(o1 instanceof Message && o2 instanceof Message){
    Message m=(Message) o1;
    Message m2=(Message) o2;
    if(m.getMessageDate().after(m2.getMessageDate()))
    return 1;
    if(m.getMessageDate().equals(m2.getMessageDate()))
    return 0;
    if(m.getMessageDate().before(m2.getMessageDate()))
    return -1;
    }else if(o1 instanceof CheckRecord && o2 instanceof Message){
    CheckRecord m=(CheckRecord) o1;
    Message m2=(Message) o2;
    if(m.getCdate().after(m2.getMessageDate()))
    return 1;
    if(m.getCdate().equals(m2.getMessageDate()))
    return 0;
    if(m.getCdate().before(m2.getMessageDate()))
    return -1;
    }else if(o1 instanceof CheckRecord && o2 instanceof CheckRecord){
    CheckRecord m=(CheckRecord) o1;
    CheckRecord m2=(CheckRecord) o2;
    if(m.getCdate().after(m2.getCdate()))
    return 1;
    if(m.getCdate().equals(m2.getCdate()))
    return 0;
    if(m.getCdate().before(m2.getCdate()))
    return -1;

    }else if(o1 instanceof Message && o2 instanceof CheckRecord){
    Message m=(Message) o1;
    CheckRecord m2=(CheckRecord) o2;
    if(m.getMessageDate().after(m2.getCdate()))
    return 1;
    if(m.getMessageDate().equals(m2.getCdate()))
    return 0;
    if(m.getMessageDate().before(m2.getCdate()))
    return -1;
    }
    return 0;

    }


    写个日志不easy。转载请注明资源:http://blog.csdn.net/xh199110  谢谢

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    windows下编译及使用libevent
    安装和使用memcached
    BroadcastReceiver插件化解决方案
    Service插件化解决方案
    Activity插件化解决方案
    换肤-插件化
    资源的插件化
    startActivity进行Hook
    代理模式
    对反射的封装
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4661151.html
Copyright © 2011-2022 走看看