]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/type/VariantType.java
Added addFirst/After/Before + remove SCL functions for Ordered Sets
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / type / VariantType.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.accessor.error.ReferenceException;
17 import org.simantics.databoard.accessor.reference.ChildReference;
18 import org.simantics.databoard.util.IdentityPair;
19
20 public class VariantType extends Datatype {
21         
22         public VariantType() {          
23         }
24         
25     @Override
26     public int getComponentCount() {
27         return 0;
28     }
29     
30     @Override
31     public Datatype getComponentType(int index) {
32         throw new IllegalArgumentException();
33     }
34     
35     @Override
36     public Datatype getComponentType(ChildReference path) {
37         if (path==null) return this;
38         throw new IllegalArgumentException();
39     }
40         
41         @Override
42         protected boolean deepEquals(Object obj, Set<IdentityPair<Datatype, Datatype>> compareHistory) {
43                 if (this==obj) return true;
44                 if ( !hasEqualMetadata(obj) ) return false;
45                 return obj instanceof VariantType;              
46         }       
47         
48         @Override
49         public int hashCode() {
50                 return 192837465 + super.hashCode();
51         }
52                 
53     @Override
54     public <T> T accept(Visitor<T> v) {         
55         return v.visit(this);
56     }
57     
58     @Override
59     public void accept(Visitor1 v, Object obj) {
60             v.visit(this, obj);        
61     }
62     
63         @SuppressWarnings("unchecked")
64         @Override
65         public <T extends Datatype> T getChildType(ChildReference reference) throws ReferenceException {
66                 if (reference==null) return (T) this;           
67                 throw new ReferenceException("Cannot get variant type without instance");
68         }
69     
70
71 }
72