]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/BinaryRead.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / BinaryRead.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.common.request;
13
14
15
16 abstract public class BinaryRead<P1, P2, R> extends GenericReadBase<P1, R> {
17
18     final protected P1 parameter;
19     final protected P2 parameter2;
20     
21     private int hashCode;
22
23     @Override
24     public int hashCode() {
25         if(hashCode == 0) {
26                 final int h1 = parameter != null ? parameter.hashCode() : 0;
27                 final int h2 = parameter2 != null ? parameter2.hashCode() : 0;
28                 hashCode = getClass().hashCode() + 31*(h1 + 31 * h2);
29         }
30         return hashCode;
31     }
32
33     @Override
34     public boolean equals(Object object) {
35         if (this == object)
36             return true;
37         else if (object == null)
38             return false;
39         else if (getClass() != object.getClass())
40             return false;
41         BinaryRead<?, ?, ?> r = (BinaryRead<?, ?, ?>) object;
42         
43         if(hashCode() != r.hashCode()) return false;
44         
45         if(parameter != null) {
46             if(!parameter.equals(r.parameter)) return false;
47         } else if(r.parameter != null) return false;
48         if(parameter2 != null) {
49             if(!parameter2.equals(r.parameter2)) return false;
50         } else if(r.parameter2 != null) return false;
51         return true;
52         
53     }
54
55     public BinaryRead(P1 parameter1, P2 parameter2) {
56         this.parameter = parameter1;
57         this.parameter2 = parameter2;
58     }
59
60     @Override
61     public String toString() {
62         return getClass().getSimpleName() + "$" + parameter + "$" + parameter2; 
63     }
64     
65 }