View Javadoc
1   package com.github.davidmoten.rx.jdbc;
2   
3   import rx.functions.Func1;
4   
5   /**
6    * Encapsulates a query parameter.
7    */
8   final class Parameter {
9   
10      private final String name;
11      /**
12       * Actual query parameter value to be encapsulated.
13       */
14      private final Object value;
15  
16      /**
17       * Constructor.
18       * 
19       * @param parameter
20       */
21      Parameter(Object value) {
22          this(null, value);
23      }
24  
25      Parameter(String name, Object value) {
26          this.name = name;
27          this.value = value;
28      }
29  
30      /**
31       * Returns the parameter value.
32       * 
33       * @return
34       */
35      Object value() {
36          return value;
37      }
38  
39      boolean hasName() {
40          return name != null;
41      }
42  
43      String name() {
44          return name;
45      }
46  
47      @Override
48      public String toString() {
49          StringBuilder builder = new StringBuilder();
50          builder.append("Parameter [value=");
51          builder.append(value);
52          builder.append("]");
53          return builder.toString();
54      }
55  
56      /**
57       * A conversion function for use in Observable.map().
58       */
59      static final Func1<Object, Parameter> TO_PARAMETER = new Func1<Object, Parameter>() {
60  
61          @Override
62          public Parameter call(Object parameter) {
63              Conditions.checkFalse(parameter instanceof Parameter);
64              return new Parameter(parameter);
65          }
66      };
67  
68  }