All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.realcomp.prime.record.io.IOContextBuilder Maven / Gradle / Ivy

There is a newer version: 0.5.8
Show newest version
package com.realcomp.prime.record.io;

import com.realcomp.prime.schema.Schema;
import com.realcomp.prime.validation.Severity;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;


public class IOContextBuilder{

    protected Schema schema;
    protected InputStream in;
    protected OutputStream out;
    protected Map attributes;
    protected Severity validationExceptionThreshold = Severity.HIGH;

    public IOContextBuilder(){
        attributes = new HashMap<>();
    }

    public IOContextBuilder(IOContext context){
        attributes = new HashMap<>();
        attributes.putAll(context.attributes);
        if (context.schema != null){
            schema = new Schema(context.schema);
        }
        in = context.in;
        out = context.out;
        validationExceptionThreshold = context.validationExeptionThreshold;
    }

    public IOContextBuilder schema(Schema schema){
        if (schema != null){
            this.schema = new Schema(schema);
        }
        return this;
    }

    public IOContextBuilder in(InputStream in){
        this.in = in;
        return this;
    }

    public IOContextBuilder out(OutputStream out){
        this.out = out;
        return this;
    }

    public IOContextBuilder attributes(Map attributes){
        if (attributes != null){
            this.attributes.putAll(attributes);
        }
        return this;
    }

    public IOContextBuilder attribute(String name, String value){
        attributes.put(name, value);
        return this;
    }

    public IOContextBuilder validationExceptionThreshold(Severity severity){
        if (severity == null){
            throw new IllegalArgumentException("severity is null");
        }
        validationExceptionThreshold = severity;
        return this;
    }

    public IOContext build() throws IOException {
        return new IOContext(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy