]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/type/IntegerType.java
Added addFirst/After/Before + remove SCL functions for Ordered Sets
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / type / IntegerType.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 IntegerType extends NumberType {
21             
22     public IntegerType() {}
23     public IntegerType(String unit) {
24         setUnit( unit );
25     }
26
27     public IntegerType(String unit, String range) {
28         setUnit( unit );
29         setRange(range);
30     }
31     
32     public IntegerType(String unit, Range range) {
33         setUnit( unit );
34         setRange(range);
35     }
36     
37     public int minValue() {
38         Range range = getRange();
39         if (range==null) return Integer.MIN_VALUE;      
40         Limit l = range.getLower();
41         int value = l.getValue().intValue();
42         if (l.isExclusive()) value++;
43         return value;
44     }
45     
46     public int maxValue() {
47         Range range = getRange();
48         if (range==null) return Integer.MAX_VALUE;      
49         Limit l = range.getUpper();
50         int value = l.getValue().intValue();
51         if (l.isExclusive()) value--;
52         return value;
53     }
54     
55     @Override
56     protected boolean deepEquals(Object obj, Set<IdentityPair<Datatype, Datatype>> compareHistory) {
57                 if (this==obj) return true;
58                 if ( !hasEqualMetadata(obj) ) return false;
59                 return obj instanceof IntegerType;
60     }
61
62     @Override
63     public int hashCode() {
64         return 0xabcf553 + metadataHashCode();
65     }    
66
67         @Override
68         public void accept(Visitor1 v, Object obj) {
69             v.visit(this, obj);        
70         }
71
72         @Override
73         public <T> T accept(Visitor<T> v) {
74             return v.visit(this);
75         }       
76         
77 }