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;  

    } 

转载于:https://www.cnblogs.com/whaozl/p/4059274.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值