zoukankan      html  css  js  c++  java
  • Java Entry使用

     参考: http://blog.csdn.net/sunmenggmail/article/details/8952712 

         http://www.cnblogs.com/fstang/archive/2013/04/20/3032097.html

    我希望要一个ArrayList<Entry>,类似C++中的pair对象,但是Map.Entry是个接口,不能实例化,可以像下面这样写

        /**
         * 选取连续性属性列和因变量列的共2列的数据————根据连续型属性的列索引——要提示因变量只能有1列
         *比如temperature是第三列,找到temperature和decisionIndex的这2列数据
         * 
    @param index                                                              连续型属性的列索引
         * 
    @return ArrayList<Entry<MetaCell, MetaCell>> 返回连续性属性列和因变量列数据——会出现2个都是热,对应因变量取值为no的相同情况——不能用Map,可用ArrayList<Entry<MetaCell, MetaCell>>
         
    */
        public ArrayList<Entry<MetaCell, MetaCell>> getDecisionValue(int index) {
            if(this.decisionIndex.length!=1){
                System.out.println("错误!模型要求因变量为单因变量");
                System.exit(-1);//退出
                return null;
            }
            //1.以下实现了key可以相同的ArrayList类型的Map功能(key可重复)
            ArrayList<Entry<MetaCell, MetaCell>> list = new ArrayList<Entry<MetaCell, MetaCell>>(this.cellData.m);//初始化——Entry参考http://blog.csdn.net/sunmenggmail/article/details/8952712 和 http://www.cnblogs.com/fstang/archive/2013/04/20/3032097.html
            for (int i = 0; i < this.cellData.m; i++) {
                list.add(new AbstractMap.SimpleEntry<MetaCell, MetaCell>(this.cellData.data.get(i).get(index), this.cellData.data.get(i).get(this.decisionIndex[0].getValue())));
            }
            //2.排序
            Collections.sort(list, new Comparator<Entry<MetaCell, MetaCell>>(){
                @Override
                public int compare(Entry<MetaCell, MetaCell> o1, Entry<MetaCell, MetaCell> o2) {
                    return o1.getKey().compareTo(o2.getKey());//key比较——大于0则表示升序——这里key肯定是DoubleCell,自动调用DoubleCell中的compareTo(重写)
                }
                
            });
            return list; 

        } 

  • 相关阅读:
    Splashtop :符合 HIPAA 标准的远程桌面软件
    学生如何在家中访问学校许可的软件
    Splashtop用于远程实验室的功能得到增强
    docker环境安装,镜像和容器常用命令
    vue-cli入门
    webpack快速入门
    Vue路由vue-router
    Vue组件化
    Vue指令
    Vue实例
  • 原文地址:https://www.cnblogs.com/whaozl/p/4059274.html
Copyright © 2011-2022 走看看