Created
July 21, 2014 21:55
-
-
Save saltzm/692fba1d3aade035ce9c to your computer and use it in GitHub Desktop.
A very simple custom vertex class in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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