Package com.mapr.synth.samplers

Source Code of com.mapr.synth.samplers.JoinSampler

package com.mapr.synth.samplers;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.TextNode;

/**
* Glue together elements of a list as strings.  Should normally only be done with a list of strings.
*
* Thread safe for sampling
*/
public class JoinSampler extends FieldSampler {
    private FieldSampler delegate;
    private String separator = ",";

    @JsonCreator
    public JoinSampler(@JsonProperty("value") FieldSampler delegate) {
        this.delegate = delegate;
    }

    @SuppressWarnings("UnusedDeclaration")
    public void setSeparator(String separator) {
        this.separator = separator;
    }

    @Override
    public JsonNode sample() {
        JsonNode value = delegate.sample();
        StringBuilder r = new StringBuilder();

        String separator="";
        for (JsonNode component : value) {
            r.append(separator);
            r.append(component.asText());
            separator = this.separator;
        }
        return new TextNode(r.toString());
    }
}
TOP

Related Classes of com.mapr.synth.samplers.JoinSampler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.