]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/classfactory/SignatureVisitor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / classfactory / SignatureVisitor.java
index 6c001889760510a5fbf09ffbed2a784094ee7c06..9aeaae595164061289151b2b20f1967b6e8f0c7d 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.databoard.binding.classfactory;\r
-\r
-import java.util.IdentityHashMap;\r
-\r
-import org.simantics.databoard.Datatypes;\r
-import org.simantics.databoard.type.ArrayType;\r
-import org.simantics.databoard.type.BooleanType;\r
-import org.simantics.databoard.type.ByteType;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.databoard.type.DoubleType;\r
-import org.simantics.databoard.type.FloatType;\r
-import org.simantics.databoard.type.IntegerType;\r
-import org.simantics.databoard.type.LongType;\r
-import org.simantics.databoard.type.MapType;\r
-import org.simantics.databoard.type.OptionalType;\r
-import org.simantics.databoard.type.RecordType;\r
-import org.simantics.databoard.type.StringType;\r
-import org.simantics.databoard.type.UnionType;\r
-import org.simantics.databoard.type.VariantType;\r
-\r
-/**\r
- * Signature Visitor builds a signature string from a datatype.\r
- * The argument is StringBuilder.\r
- * \r
- * Signature is construtructed with the following notation.\r
- * \r
- *   s                        StringType\r
- *   z                        BooleanType\r
- *   d                        DoubleType\r
- *   f                        FloatType\r
- *   i                        IntegerType\r
- *   b                        ByteType\r
- *   j                        LongType\r
- *   R                        Referable RecordType\r
- *   o*                       OptionalType, * denotes componentType\r
- *   a*                       ArrayType, * denotes componentType\r
- *   r**e                     RecordType, ** denotes fields\r
- *   u                        UnionType, * denotes components\r
- *   m**                      MapType, ** denotes keyType and valueType\r
- *   t                        Datatype\r
- *   \r
- * For example, The signature of UUID.class is "rjje" \r
- * \r
- * @author toni.kalajainen\r
- */\r
-public class SignatureVisitor implements Datatype.Visitor1 {\r
-       \r
-       public StringBuilder sb = new StringBuilder();\r
-       public int hashcode = 0xbcbcbca;\r
-       public IdentityHashMap<Datatype, Boolean> visited = new IdentityHashMap<Datatype, Boolean>();\r
-       \r
-       public static String toSignature(Datatype type)\r
-       {\r
-               SignatureVisitor sv = new SignatureVisitor();\r
-               type.accept( sv, null );\r
-               String sig = sv.sb.toString();\r
-               return sig;\r
-       }       \r
-\r
-       @Override\r
-       public void visit(ArrayType b, Object obj) {\r
-               sb.append('a');\r
-               b.componentType.accept(this, obj);\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(BooleanType b, Object obj) {\r
-               sb.append('z');\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(DoubleType b, Object obj) {\r
-               sb.append('d');\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(FloatType b, Object obj) {\r
-               sb.append('f');\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(IntegerType b, Object obj) {\r
-               sb.append('i');\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(ByteType b, Object obj) {\r
-               sb.append('b');\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(LongType b, Object obj) {\r
-               sb.append('j');\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(OptionalType b, Object obj) {\r
-               sb.append('o');\r
-               b.componentType.accept(this, sb);\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(RecordType b, Object obj) {\r
-               if ( wasVisited(b) ) {\r
-                       sb.append('R');\r
-                       return;\r
-               }\r
-               if ( b.isReferable() ) {\r
-                       sb.append('R');\r
-                       return;\r
-               }\r
-               \r
-               sb.append('r');\r
-               for (int i=0; i<b.getComponentCount(); i++) {\r
-                       b.getComponentType(i).accept(this, sb);\r
-               }\r
-               sb.append('e');\r
-\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-               for (int i=0; i<b.getComponentCount(); i++) {\r
-                       hashcode = 13*hashcode + b.getComponent(i).name.hashCode();\r
-               }\r
-       }\r
-\r
-       @Override\r
-       public void visit(StringType b, Object obj) {\r
-               sb.append('s');\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(UnionType b, Object obj) {\r
-               if ( b.equals( Datatypes.getDatatypeUnchecked(Datatype.class) )) {\r
-                       sb.append("t");\r
-                       return;\r
-               }\r
-               if ( wasVisited(b) ) {\r
-                       sb.append('U');\r
-                       return;\r
-               }\r
-               sb.append('u');\r
-               for (int i=0; i<b.getComponentCount(); i++) {\r
-                       b.getComponentType(i).accept(this, sb);\r
-               }\r
-               sb.append('e');\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(VariantType b, Object obj) {\r
-               sb.append('v');\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-\r
-       @Override\r
-       public void visit(MapType b, Object obj) {\r
-               if ( wasVisited(b) ) return;\r
-               sb.append('m');\r
-               b.keyType.accept(this, obj);\r
-               b.valueType.accept(this, obj);\r
-               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();\r
-       }\r
-       \r
-       /**\r
-        * Visit and return if was visited\r
-        * @param type\r
-        * @return\r
-        */\r
-       boolean wasVisited(Datatype type) {\r
-               Boolean result = visited.put(type, Boolean.TRUE);\r
-               return result == null ? false : result;\r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.databoard.binding.classfactory;
+
+import java.util.IdentityHashMap;
+
+import org.simantics.databoard.Datatypes;
+import org.simantics.databoard.type.ArrayType;
+import org.simantics.databoard.type.BooleanType;
+import org.simantics.databoard.type.ByteType;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.databoard.type.DoubleType;
+import org.simantics.databoard.type.FloatType;
+import org.simantics.databoard.type.IntegerType;
+import org.simantics.databoard.type.LongType;
+import org.simantics.databoard.type.MapType;
+import org.simantics.databoard.type.OptionalType;
+import org.simantics.databoard.type.RecordType;
+import org.simantics.databoard.type.StringType;
+import org.simantics.databoard.type.UnionType;
+import org.simantics.databoard.type.VariantType;
+
+/**
+ * Signature Visitor builds a signature string from a datatype.
+ * The argument is StringBuilder.
+ * 
+ * Signature is construtructed with the following notation.
+ * 
+ *   s                        StringType
+ *   z                        BooleanType
+ *   d                        DoubleType
+ *   f                        FloatType
+ *   i                        IntegerType
+ *   b                        ByteType
+ *   j                        LongType
+ *   R                        Referable RecordType
+ *   o*                       OptionalType, * denotes componentType
+ *   a*                       ArrayType, * denotes componentType
+ *   r**e                     RecordType, ** denotes fields
+ *   u                        UnionType, * denotes components
+ *   m**                      MapType, ** denotes keyType and valueType
+ *   t                        Datatype
+ *   
+ * For example, The signature of UUID.class is "rjje" 
+ * 
+ * @author toni.kalajainen
+ */
+public class SignatureVisitor implements Datatype.Visitor1 {
+       
+       public StringBuilder sb = new StringBuilder();
+       public int hashcode = 0xbcbcbca;
+       public IdentityHashMap<Datatype, Boolean> visited = new IdentityHashMap<Datatype, Boolean>();
+       
+       public static String toSignature(Datatype type)
+       {
+               SignatureVisitor sv = new SignatureVisitor();
+               type.accept( sv, null );
+               String sig = sv.sb.toString();
+               return sig;
+       }       
+
+       @Override
+       public void visit(ArrayType b, Object obj) {
+               sb.append('a');
+               b.componentType.accept(this, obj);
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(BooleanType b, Object obj) {
+               sb.append('z');
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(DoubleType b, Object obj) {
+               sb.append('d');
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(FloatType b, Object obj) {
+               sb.append('f');
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(IntegerType b, Object obj) {
+               sb.append('i');
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(ByteType b, Object obj) {
+               sb.append('b');
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(LongType b, Object obj) {
+               sb.append('j');
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(OptionalType b, Object obj) {
+               sb.append('o');
+               b.componentType.accept(this, sb);
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(RecordType b, Object obj) {
+               if ( wasVisited(b) ) {
+                       sb.append('R');
+                       return;
+               }
+               if ( b.isReferable() ) {
+                       sb.append('R');
+                       return;
+               }
+               
+               sb.append('r');
+               for (int i=0; i<b.getComponentCount(); i++) {
+                       b.getComponentType(i).accept(this, sb);
+               }
+               sb.append('e');
+
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+               for (int i=0; i<b.getComponentCount(); i++) {
+                       hashcode = 13*hashcode + b.getComponent(i).name.hashCode();
+               }
+       }
+
+       @Override
+       public void visit(StringType b, Object obj) {
+               sb.append('s');
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(UnionType b, Object obj) {
+               if ( b.equals( Datatypes.getDatatypeUnchecked(Datatype.class) )) {
+                       sb.append("t");
+                       return;
+               }
+               if ( wasVisited(b) ) {
+                       sb.append('U');
+                       return;
+               }
+               sb.append('u');
+               for (int i=0; i<b.getComponentCount(); i++) {
+                       b.getComponentType(i).accept(this, sb);
+               }
+               sb.append('e');
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(VariantType b, Object obj) {
+               sb.append('v');
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+
+       @Override
+       public void visit(MapType b, Object obj) {
+               if ( wasVisited(b) ) return;
+               sb.append('m');
+               b.keyType.accept(this, obj);
+               b.valueType.accept(this, obj);
+               hashcode = 13*hashcode + b.getClass().getName().hashCode() + 133*b.metadataHashCode();
+       }
+       
+       /**
+        * Visit and return if was visited
+        * @param type
+        * @return
+        */
+       boolean wasVisited(Datatype type) {
+               Boolean result = visited.put(type, Boolean.TRUE);
+               return result == null ? false : result;
+       }
+}