View Javadoc
1   /**
2    * Copyright (C) 2010-14 pvmanager developers. See COPYRIGHT.TXT
3    * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4    */
5   package org.epics.pvmanager;
6   
7   /**
8    * Groups all the parameters required to add a reader to a ChannelHandler.
9    * <p>
10   * All parameters where grouped in this class so that if something needs to be
11   * added or removed the impact is lessened. The class is immutable so that
12   * the ChannelHandler can cache it for reference.
13   *
14   * @author carcassi
15   */
16  public class ChannelHandlerReadSubscription {
17  
18      /**
19       * Creates the parameters for a new subscription.
20       * 
21       * @param valueCache the cache where to write the value
22       * @param exceptionWriteFunction the write function to dispatch exceptions
23       * @param connectionWriteFunction the connection write function to dispatch exceptions
24       */
25      public ChannelHandlerReadSubscription(ValueCache<?> valueCache, WriteFunction<Exception> exceptionWriteFunction, WriteFunction<Boolean> connectionWriteFunction) {
26          this.valueCache = valueCache;
27          this.exceptionWriteFunction = exceptionWriteFunction;
28          this.connectionWriteFunction = connectionWriteFunction;
29      }
30      
31      private final ValueCache<?> valueCache;
32      private final WriteFunction<Exception> exceptionWriteFunction;
33      private final WriteFunction<Boolean> connectionWriteFunction;
34  
35      /**
36       * The cache where to write the value.
37       * 
38       * @return never null
39       */
40      public ValueCache<?> getValueCache() {
41          return valueCache;
42      }
43  
44      /**
45       * The write function for exceptions.
46       * 
47       * @return never null
48       */
49      public WriteFunction<Exception> getExceptionWriteFunction() {
50          return exceptionWriteFunction;
51      }
52  
53      /**
54       * The write function for the connection flag.
55       * 
56       * @return never null
57       */
58      public WriteFunction<Boolean> getConnectionWriteFunction() {
59          return connectionWriteFunction;
60      }
61      
62      @Override
63      public int hashCode() {
64          int hash = 5;
65          hash = 67 * hash + (this.valueCache != null ? this.valueCache.hashCode() : 0);
66          hash = 67 * hash + (this.exceptionWriteFunction != null ? this.exceptionWriteFunction.hashCode() : 0);
67          hash = 67 * hash + (this.connectionWriteFunction != null ? this.connectionWriteFunction.hashCode() : 0);
68          return hash;
69      }
70  
71      @Override
72      public boolean equals(Object obj) {
73          if (obj == null) {
74              return false;
75          }
76          if (getClass() != obj.getClass()) {
77              return false;
78          }
79          final ChannelHandlerReadSubscription other = (ChannelHandlerReadSubscription) obj;
80          if (this.valueCache != other.valueCache && (this.valueCache == null || !this.valueCache.equals(other.valueCache))) {
81              return false;
82          }
83          if (this.exceptionWriteFunction != other.exceptionWriteFunction && (this.exceptionWriteFunction == null || !this.exceptionWriteFunction.equals(other.exceptionWriteFunction))) {
84              return false;
85          }
86          if (this.connectionWriteFunction != other.connectionWriteFunction && (this.connectionWriteFunction == null || !this.connectionWriteFunction.equals(other.connectionWriteFunction))) {
87              return false;
88          }
89          return true;
90      }
91      
92  }