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