參考: 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;
* 選取連續性屬性列和因變量列的共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;
}