use of java.lang.StringBuilder in project Java by TheAlgorithms.
the class Graphs method toString.
/**
* this gives a list of verticies in the graph and their adjacencies
*
* @return returns a string describing this graph
*/
public String toString() {
StringBuilder sb = new StringBuilder();
for (Vertex v : verticies) {
sb.append("Vertex: ");
sb.append(v.data);
sb.append("\n");
sb.append("Adjacent verticies: ");
for (Vertex v2 : v.adjacentVerticies) {
sb.append(v2.data);
sb.append(" ");
}
sb.append("\n");
}
return sb.toString();
}
use of java.lang.StringBuilder in project clojure by clojure.
the class LispReader method readToken.
private static String readToken(PushbackReader r, char initch) {
StringBuilder sb = new StringBuilder();
sb.append(initch);
for (; ; ) {
int ch = read1(r);
if (ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch)) {
unread(r, ch);
return sb.toString();
}
sb.append((char) ch);
}
}
use of java.lang.StringBuilder in project clojure by clojure.
the class LispReader method readNumber.
private static Object readNumber(PushbackReader r, char initch) {
StringBuilder sb = new StringBuilder();
sb.append(initch);
for (; ; ) {
int ch = read1(r);
if (ch == -1 || isWhitespace(ch) || isMacro(ch)) {
unread(r, ch);
break;
}
sb.append((char) ch);
}
String s = sb.toString();
Object n = matchNumber(s);
if (n == null)
throw new NumberFormatException("Invalid number: " + s);
return n;
}
use of java.lang.StringBuilder in project clochure by videlalvaro.
the class LispReader method readToken.
private static String readToken(PushbackReader r, char initch) {
StringBuilder sb = new StringBuilder();
sb.append(initch);
for (; ; ) {
int ch = read1(r);
if (ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch)) {
unread(r, ch);
return sb.toString();
}
sb.append((char) ch);
}
}
use of java.lang.StringBuilder in project aerosolve by airbnb.
the class DecisionTreeModel method toDot.
/*
* Returns a debuggable single tree in graphviz DOT format
*/
public String toDot() {
StringBuilder sb = new StringBuilder();
sb.append("digraph g {\n");
sb.append("graph [ rankdir = \"LR\" ]\n");
for (int i = 0; i < stumps.size(); i++) {
ModelRecord stump = stumps.get(i);
if (stump.isSetLeftChild()) {
sb.append(String.format("\"node%d\" [\n", i));
double thresh = stump.threshold;
sb.append(String.format("label = \"<f0> %s:%s | <f1> less than %f | <f2> greater than or equal%f\";\n", stump.featureFamily, stump.featureName, thresh, thresh));
sb.append("shape = \"record\";\n");
sb.append("];\n");
} else {
sb.append(String.format("\"node%d\" [\n", i));
if (stump.labelDistribution != null) {
sb.append(String.format("label = \"<f0> "));
for (Map.Entry<String, Double> entry : stump.labelDistribution.entrySet()) {
sb.append(String.format("%s : %f ", entry.getKey(), entry.getValue()));
}
sb.append(" \";\n");
} else {
sb.append(String.format("label = \"<f0> Weight %f\";\n", stump.featureWeight));
}
sb.append("shape = \"record\";\n");
sb.append("];\n");
}
}
int count = 0;
for (int i = 0; i < stumps.size(); i++) {
ModelRecord stump = stumps.get(i);
if (stump.isSetLeftChild()) {
sb.append(String.format("\"node%d\":f1 -> \"node%d\":f0 [ id = %d ];\n", i, stump.leftChild, count));
count = count + 1;
sb.append(String.format("\"node%d\":f2 -> \"node%d\":f0 [id = %d];\n", i, stump.rightChild, count));
count = count + 1;
}
}
sb.append("}\n");
return sb.toString();
}
Aggregations