]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/examples/org/simantics/databoard/example/DeepCompare.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / examples / org / simantics / databoard / example / DeepCompare.java
diff --git a/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/DeepCompare.java b/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/DeepCompare.java
new file mode 100644 (file)
index 0000000..2d0393b
--- /dev/null
@@ -0,0 +1,63 @@
+/*******************************************************************************\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.example;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.binding.error.BindingException;\r
+\r
+public class DeepCompare {\r
+\r
+       public static void main(String[] args) throws BindingException {\r
+               \r
+               // Binding can compare any two instances. The compare function is deep.                 \r
+               Binding binding = Bindings.getBindingUnchecked( int[].class );\r
+               \r
+               int[] array1 = new int[] { 1, 2, 3 };\r
+               int[] array2 = new int[] { 1, 2, 3 };\r
+               int[] array3 = new int[] { 2, 3, 4 };\r
+               \r
+               if ( binding.compare(array1, array2) == 0 ) {\r
+                       System.out.println( "array1 is equal to array2" );\r
+               } else {\r
+                       System.out.println( "array1 is not equal to array2" );\r
+               }\r
+               \r
+               if ( binding.compare(array1, array3) == 0 ) {\r
+                       System.out.println( "array1 is equal to array3" );\r
+               } else {\r
+                       System.out.println( "array1 is not equal to array3" );\r
+               }\r
+               \r
+               \r
+               \r
+               \r
+               \r
+               // Two bindings can compare instances of same datatype, even if they are of\r
+               // different classes            \r
+               ArrayList<Integer> array4 = new ArrayList<Integer>();\r
+               Binding binding2 = Bindings.getBindingUnchecked( ArrayList.class, Integer.class );\r
+               array4.add( 1 );\r
+               array4.add( 2 );\r
+               array4.add( 3 );\r
+               \r
+               if ( Bindings.compare(binding, array1, binding2, array4) == 0 ) {\r
+                       System.out.println( "array1 is equal to array4" );\r
+               } else {\r
+                       System.out.println( "array1 is not equal to array4" );\r
+               }\r
+               \r
+       }\r
+       \r
+}\r