Search in sources :

Example 11 with StringBuilder

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();
}
Also used : StringBuilder(java.lang.StringBuilder)

Example 12 with StringBuilder

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);
    }
}
Also used : StringBuilder(java.lang.StringBuilder)

Example 13 with StringBuilder

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;
}
Also used : StringBuilder(java.lang.StringBuilder) NumberFormatException(java.lang.NumberFormatException) Object(java.lang.Object) String(java.lang.String)

Example 14 with StringBuilder

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);
    }
}
Also used : StringBuilder(java.lang.StringBuilder)

Example 15 with StringBuilder

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();
}
Also used : StringBuilder(java.lang.StringBuilder) Map(java.util.Map)

Aggregations

StringBuilder (java.lang.StringBuilder)40 Override (java.lang.Override)9 String (java.lang.String)6 IOException (java.io.IOException)5 BufferedReader (java.io.BufferedReader)4 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 NumberFormatException (java.lang.NumberFormatException)2 Object (java.lang.Object)2 ArrayList (java.util.ArrayList)2 Chromosome (PedigreeSim.Chromosome)1 Individual (PedigreeSim.Individual)1 Locus (PedigreeSim.Locus)1 Rational (android.util.Rational)1 Digest (cz1.gbs.core.Digest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 RuntimeException (java.lang.RuntimeException)1