in src/main/java/com/twitter/sbf/graph/Graph.java [501:544]
public Iterable<String> iterableStringRepresentation(DecimalFormat weightFormatter) {
return new Iterable<String>() {
// Not thread-safe for now
@Override
public Iterator<String> iterator() {
return new Iterator<String>() {
private int index = -1;
public boolean hasNext() {
return index < numVertices;
}
public String next() {
if (!hasNext()) {
return null;
}
if (index == -1) {
index++;
return "" + numVertices + " " + numEdges + (isWeighted() ? " 1" : "");
}
StringBuilder sb = new StringBuilder();
Iterator<WeightedId> wni = getWeightedNeighborsIterator(index);
boolean isFirst = true;
while (wni.hasNext()) {
WeightedId wn = wni.next();
if (!isFirst) {
sb.append(" ");
}
sb.append(wn.neighborId + 1); // go from 0-indexing to 1-indexing
if (isWeighted()) {
sb.append(" ").append(weightFormatter.format(wn.weight));
}
isFirst = false;
}
index++;
return sb.toString();
}
};
}
};
}