write()方法中的空值:hadoop mapreduce中的自定义数据类型

3bygqnnd  于 2021-06-03  发布在  Hadoop
关注(0)|答案(0)|浏览(168)

我发出两个二维双数组作为键和值。我正在建造 WritableComparable 班级。

public class MF implements WritableComparable<MF>{

/**
 * @param args
 */
private double[][] value;

public MF() {
    // TODO Auto-generated constructor stub
}

public MF(double[][] value) {
    // TODO Auto-generated constructor stub

      this.value = new double[value.length][value[0].length];
    // System.out.println("in matrix");
}

public void set(double[][] value) {
      this.value = value;
}

public double[][] getValue() {
        return value;
}

@Override
public void write(DataOutput out) throws IOException {
    System.out.println("write");
    int row=0;
    int column=0;
    for(int i=0; i<value.length;i++) {
        row = value.length;
        for(int j=0; j<value[i].length; j++) {
            column = value[i].length;
        }
    }
    out.writeInt(row);
    out.writeInt(column);

    for(int i=0;i<row ; i++) {
        for(int j= 0 ; j< col;j++) {
            out.writeDouble(value[i][j]);
        }
    }

    for(int i =0;i< value.length ;i ++) {
        for(int j = 0;j <value[0].length;j++) {
            System.out.print(value[i][j]+ "\t");
        }
        System.out.println("");
    }
}

@Override
public void readFields(DataInput in) throws IOException {
    int row = in.readInt();
    int col = in.readInt();

    double[][] value = new double[row][col];
    for(int i=0;i<row ; i++) {
        for(int j= 0 ; j< col;j++) {
            value[i][j] = in.readDouble();
        }
    }
}

@Override
public int hashCode() {

}

@Override
public boolean equals(Object o) {

}

@Override
public int compareTo(MF o) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public String toString() {
    System.out.println(Arrays.toString(value));
    return Arrays.toString(value);
}
}

中途,当我试图用write方法打印我的矩阵时,矩阵没有值

write
    0.0 0.0 0.0 
    0.0 0.0 0.0 
    0.0 0.0 0.0 
write
    0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
    0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
    0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

我做错了什么。我越来越不喜欢吵架了。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题