]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/method/MethodType.java
Improved Bindings.getBinding(Class) caching for Datatype.class
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / method / MethodType.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  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.databoard.method;
13
14 import org.simantics.databoard.type.Datatype;
15
16 public class MethodType implements Comparable<MethodType> {
17         
18         // RecordType, one component for each argument
19         Datatype requestType;
20         // anything
21         Datatype responseType;
22         // UnionType
23         Datatype errorType;
24         
25         transient int hash; 
26         
27         /**
28          * 
29          * @param requestType
30          * @param responseType
31          * @param errorType must be union
32          */
33         public MethodType(Datatype requestType, Datatype responseType, Datatype errorType)
34         {
35                 this.requestType = requestType;
36                 this.responseType = responseType;
37                 this.errorType = errorType;
38                 hash = requestType.hashCode() + responseType.hashCode()*13 + errorType.hashCode()*23;
39         }
40         
41         public Datatype getRequestType()
42         {
43                 return requestType;
44         }
45         
46         public Datatype getResponseType()
47         {
48                 return responseType;
49         }
50         
51         public Datatype getErrorType()
52         {
53                 return errorType;
54         }
55         
56         @Override
57         public String toString() {
58                 return requestType.toSingleLineString()+" -> " + responseType.toSingleLineString()+ " throws " + errorType.toSingleLineString();
59         }
60         
61
62         @Override
63         public int hashCode() {
64                 return hash;
65         }
66         
67         @Override
68         public boolean equals(Object obj) {
69                 if (obj instanceof MethodType == false) return false;
70                 MethodType other = (MethodType) obj;
71                 return other.requestType.equals(requestType) && 
72                         other.responseType.equals(responseType) &&
73                         other.errorType.equals(errorType);
74         }
75
76         @Override
77         public int compareTo(MethodType o) {
78                 return 0;
79         }
80         
81 }
82