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

com.github.davidmoten.rx.jdbc.Parameter Maven / Gradle / Ivy

There is a newer version: 0.7.19
Show newest version
package com.github.davidmoten.rx.jdbc;

import rx.functions.Func1;

/**
 * Encapsulates a query parameter.
 */
final class Parameter {

    private final String name;
    /**
     * Actual query parameter value to be encapsulated.
     */
    private final Object value;

    /**
     * Constructor.
     * 
     * @param parameter
     */
    Parameter(Object value) {
        this(null, value);
    }

    Parameter(String name, Object value) {
        this.name = name;
        this.value = value;
    }

    /**
     * Returns the parameter value.
     * 
     * @return
     */
    Object value() {
        return value;
    }

    boolean hasName() {
        return name != null;
    }

    String name() {
        return name;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        if (value instanceof String)
            builder.append("'");
        builder.append(value);
        if (value instanceof String)
            builder.append("'");
        return builder.toString();
    }

    /**
     * A conversion function for use in Observable.map().
     */
    static final Func1 TO_PARAMETER = new Func1() {

        @Override
        public Parameter call(Object parameter) {
            Conditions.checkFalse(parameter instanceof Parameter);
            return new Parameter(parameter);
        }
    };

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy