]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/type/LongType.java
Improved Bindings.getBinding(Class) caching for Datatype.class
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / type / LongType.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.type;
13
14 import java.util.Set;
15
16 import org.simantics.databoard.util.IdentityPair;
17 import org.simantics.databoard.util.Limit;
18 import org.simantics.databoard.util.Range;
19
20 public class LongType extends NumberType {
21             
22     public LongType() {}
23     public LongType(String unit) {
24         setUnit( unit );
25     }
26     public LongType(String unit, Range range) {
27         setUnit( unit );
28         setRange(range);
29     }    
30     public LongType(String unit, String range) {
31         setUnit( unit );
32         setRange(range);
33     }    
34     
35     public long minValue() {
36         Range range = getRange();
37         if (range==null) return Long.MIN_VALUE;
38         Limit l = range.getLower();
39         long value = l.getValue().longValue();
40         if (l.isExclusive()) value++;
41         return value;
42     }
43     
44     public long maxValue() {
45         Range range = getRange();
46         if (range==null) return Long.MAX_VALUE;
47         Limit l = range.getUpper();
48         long value = l.getValue().longValue();
49         if (l.isExclusive()) value--;
50         return value;
51     }    
52     
53         @Override
54         public void accept(Visitor1 v, Object obj) {
55             v.visit(this, obj);        
56         }
57
58         @Override
59         public <T> T accept(Visitor<T> v) {
60             return v.visit(this);
61         }       
62         
63     @Override
64     public int hashCode() {
65         return 0x3667654 + metadataHashCode();
66     }     
67
68     @Override
69     protected boolean deepEquals(Object obj, Set<IdentityPair<Datatype, Datatype>> compareHistory) {
70                 if ( this==obj ) return true;
71                 if ( !hasEqualMetadata(obj) ) return false;
72                 return obj instanceof LongType;
73     }
74
75 }