]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/type/FloatType.java
Added addFirst/After/Before + remove SCL functions for Ordered Sets
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / type / FloatType.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 FloatType extends NumberType {
21             
22     public FloatType() {}
23     public FloatType(String unit) {
24         setUnit( unit );
25     }
26     public FloatType(String unit, Range range) {
27         setUnit( unit );
28         setRange(range);
29     }    
30     public FloatType(String unit, String range) {
31         setUnit( unit );
32         setRange(range);
33     }    
34     
35     public float minValue() {
36         Range range = getRange();
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();
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) {
61                 if (this==obj) return true;
62                 if ( !hasEqualMetadata(obj) ) return false;
63                 return obj instanceof FloatType;
64     }
65
66     @Override
67     public int hashCode() {
68         return 0xaa55996 + metadataHashCode();
69     }  
70
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 }