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

co.spraybot.messagerunner.builders.DataStoreParcelBuilder Maven / Gradle / Ivy

package co.spraybot.messagerunner.builders;

import co.spraybot.messagerunner.DataStoreParcelProcessor;
import co.spraybot.messagerunner.DataStoreParcel;

public class DataStoreParcelBuilder {

    private String key;
    private DataStoreParcelProcessor.Operation operation;
    private Object value;
    private Class valueType;

    public DataStoreParcelBuilder key(String key) {
        this.key = key;
        return this;
    }

    public DataStoreParcelBuilder operation(DataStoreParcelProcessor.Operation operation) {
        this.operation = operation;
        return this;
    }

    public DataStoreParcelBuilder value(Object value) {
        this.value = value;
        valueType = value.getClass();
        return this;
    }

    public  DataStoreParcel build() {
        DataStoreParcel parcel = new DataStoreParcel() {
            private String key;
            private DataStoreParcelProcessor.Operation operation;
            private T value;
            private Class valueType;

            private DataStoreParcel init(DataStoreParcelProcessor.Operation operation, String key, T value, Class valueType) {
                this.key = key;
                this.operation = operation;
                this.value = value;
                this.valueType = valueType;
                return this;
            }

            @Override
            public DataStoreParcelProcessor.Operation getDataStoreOperation() {
                return operation;
            }

            @Override
            public String getKey() {
                return key;
            }

            @Override
            public T getValue() {
                return value;
            }

            @Override
            public Class getValueType() { return valueType; }
        }.init(operation, key, (T) value, valueType);

        operation = null;
        key = null;
        value = null;

        return parcel;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy