目前,我正在將普通的Java代碼轉換爲MapReduce
結構Hadoop
。HashMap上的Hadoop序列化和浮點[]
我想修改下面的類Graph
,我仍然不知道如何序列化和反序列化HashMap
和float[]
類型。代碼的一部分在下面。
代碼:
public class Graph implements WritableComparable, Cloneable {
private static long serialVersionUID = 3L;
public static int MAX_FREQUENCY = 3;
public static float[] freqWeight = { 1.0F, 1.6F, 2.0F };
int nNodes;
int nEdges;
String strName;
HashMap<String, Node> nodes;
boolean isMCS;
String taxonomyName;
@Override
public void write(DataOutput out) throws IOException {
// TODO Auto-generated method stub
out.writeBoolean(isMCS);
out.writeInt(nEdges);
out.writeInt(nNodes);
out.writeLong(serialVersionUID);
out.writeInt(MAX_FREQUENCY);
out.writeBytes(strName);
out.writeBytes(taxonomyName);
//ArrayWritable a=new ArrayWritable(FloatWritable.class);
//HashMap
//float[]
}
@Override
public void readFields(DataInput in) throws IOException {
// TODO Auto-generated method stub
isMCS=in.readBoolean();
nEdges=in.readInt();
nNodes=in.readInt();
serialVersionUID=in.readLong();
MAX_FREQUENCY=in.readInt();
strName=in.readLine();
taxonomyName=in.readLine();
//HashMap
//float[]
}
@Override
public int compareTo(Graph graph) {
// TODO Auto-generated method stub
return 0;
}
.........
你可以縮進代碼,使其可讀嗎? –
對不起,這是我第一次使用Stackoverflow。我明白你的意思。我可以在我的電腦中閱讀,只有與變量相關的行不縮進。但代碼仍然可讀。 – Aaron