]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/type/FloatType.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / type / FloatType.java
1 /*******************************************************************************\r
2  *  Copyright (c) 2010 Association for Decentralized Information Management in\r
3  *  Industry THTH ry.\r
4  *  All rights reserved. This program and the accompanying materials\r
5  *  are made available under the terms of the Eclipse Public License v1.0\r
6  *  which accompanies this distribution, and is available at\r
7  *  http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  *  Contributors:\r
10  *      VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.databoard.type;
13
14 import java.util.Set;\r
15 \r
16 import org.simantics.databoard.util.IdentityPair;\r
17 import org.simantics.databoard.util.Limit;\r
18 import org.simantics.databoard.util.Range;\r
19
20 public class FloatType extends NumberType {
21             
22     public FloatType() {}
23     public FloatType(String unit) {\r
24         setUnit( unit );
25     }
26     public FloatType(String unit, Range range) {
27         setUnit( unit );\r
28         setRange(range);
29     }    
30     public FloatType(String unit, String range) {
31         setUnit( unit );\r
32         setRange(range);
33     }    
34     
35     public float minValue() {
36         Range range = getRange();\r
37         if (range==null) return -Float.MAX_VALUE;
38         Limit l = range.getLower();
39         float value = l.getValue().floatValue();
40         
41         // Won't work
42         if (l.isExclusive()) value+= Float.MIN_VALUE;
43         
44         return value;
45     }
46     
47     public float maxValue() {
48         Range range = getRange();\r
49         if (range==null) return Float.MAX_VALUE;
50         Limit l = range.getUpper();
51         float value = l.getValue().floatValue();
52         
53         // Won't work
54         if (l.isExclusive()) value-= Float.MIN_VALUE;
55         
56         return value;
57     }    
58        
59     @Override
60     protected boolean deepEquals(Object obj, Set<IdentityPair<Datatype, Datatype>> compareHistory) {\r
61                 if (this==obj) return true;\r
62                 if ( !hasEqualMetadata(obj) ) return false;\r
63                 return obj instanceof FloatType;
64     }
65
66     @Override
67     public int hashCode() {
68         return 0xaa55996 + metadataHashCode();
69     }  
70 \r
71     @Override
72         public void accept(Visitor1 v, Object obj) {
73             v.visit(this, obj);        
74         }
75
76         @Override
77         public <T> T accept(Visitor<T> v) {
78             return v.visit(this);
79         }       
80         
81 }