]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/type/BooleanType.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / type / BooleanType.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.accessor.error.ReferenceException;\r
17 import org.simantics.databoard.accessor.reference.ChildReference;\r
18 import org.simantics.databoard.util.IdentityPair;\r
19
20
21 public class BooleanType extends Datatype {
22         
23         public BooleanType() {}
24                 \r
25     @Override\r
26     public int getComponentCount() {\r
27         return 0;\r
28     }\r
29     \r
30     @Override\r
31     public Datatype getComponentType(int index) {\r
32         throw new IllegalArgumentException();\r
33     }\r
34     \r
35     @Override\r
36     public Datatype getComponentType(ChildReference path) {\r
37         if (path==null) return this;\r
38         throw new IllegalArgumentException();\r
39     }\r
40     
41         @Override
42         public void accept(Visitor1 v, Object obj) {
43             v.visit(this, obj);        
44         }
45
46         @Override
47         public <T> T accept(Visitor<T> v) {
48             return v.visit(this);
49         }
50
51         @Override
52         protected boolean deepEquals(Object obj,
53                         Set<IdentityPair<Datatype, Datatype>> compareHistory) {\r
54                 if (this==obj) return true;\r
55                 if ( !hasEqualMetadata(obj) ) return false;\r
56                 return obj instanceof BooleanType;
57         }
58                 
59         @Override\r
60         public int hashCode() {\r
61                 return metadataHashCode() ^ 0xaaee333;\r
62         }    \r
63 \r
64         @Override\r
65         public boolean equals(Object obj) {\r
66                 if ( this==obj ) return true;\r
67                 if ( !hasEqualMetadata(obj) ) return false;\r
68                 return obj instanceof BooleanType;\r
69         }\r
70 \r
71         @SuppressWarnings("unchecked")\r
72         @Override\r
73         public <T extends Datatype> T getChildType(ChildReference reference) throws ReferenceException {\r
74                 if (reference==null) return (T) this;\r
75                 throw new ReferenceException(reference.getClass()+" is not a subreference of BooleanType");     \r
76         }\r
77         \r
78 }