Skip to content

Instantly share code, notes, and snippets.

@saltzm
Created July 21, 2014 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saltzm/692fba1d3aade035ce9c to your computer and use it in GitHub Desktop.
Save saltzm/692fba1d3aade035ce9c to your computer and use it in GitHub Desktop.
A very simple custom vertex class in java
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.Writable;
public class SampleVertexData implements Writable {
/**
* Some integer
*/
private int a;
/**
* Some boolean flag
*/
private boolean flag;
// From what I understand the empty constructor is required by hadoop
public SampleVertexData () {}
public SampleVertexData(int a, boolean flag) {
this.a = a;
this.flag = flag;
}
public int getA() { return a; }
public int getFlag() { return flag; }
public void setA(int newA) {
this.a = newA;
}
public void setFlag(int newFlag) {
this.flag = newFlag;
}
@Override
public void readFields(DataInput input) throws IOException {
// One of these for each of your class variables
// See for more detail: http://docs.oracle.com/javase/7/docs/api/java/io/DataInput.html
a = input.readInt();
flag = input.readBoolean();
}
@Override
public void write(DataOutput output) throws IOException {
output.writeInt(a);
output.writeBoolean(flag);
}
@Override
public String toString() {
return "(a = " + a + ", flag = " + flag + ")";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment