aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/processing/test/Responses.java
blob: e1ac3446acfdf68e19c090db1bc5bffb991b47e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.processing.test;

import com.yahoo.processing.response.Data;
import com.yahoo.processing.response.DataList;

/**
 * Static utilities
 *
 * @author bratseth
 * @since 5.1.13
 */
public class Responses {

    /**
     * Returns a data item as a recursively indented string
     */
    public static String recursiveToString(Data data) {
        StringBuilder b = new StringBuilder();
        asString(data, b, "");
        return b.toString();
    }

    private static void asString(Data data, StringBuilder b, String indent) {
        b.append(indent).append(data).append("\n");
        if (!(data instanceof DataList)) return;
        for (Data childData : ((DataList<? extends Data>) data).asList()) {
            asString(childData, b, indent.concat("    "));
        }
    }

}