]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 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.example;\r
13 \r
14 import java.util.ArrayList;\r
15 \r
16 import org.simantics.databoard.Bindings;\r
17 import org.simantics.databoard.binding.Binding;\r
18 import org.simantics.databoard.binding.error.BindingException;\r
19 \r
20 public class DeepCompare {\r
21 \r
22         public static void main(String[] args) throws BindingException {\r
23                 \r
24                 // Binding can compare any two instances. The compare function is deep.                 \r
25                 Binding binding = Bindings.getBindingUnchecked( int[].class );\r
26                 \r
27                 int[] array1 = new int[] { 1, 2, 3 };\r
28                 int[] array2 = new int[] { 1, 2, 3 };\r
29                 int[] array3 = new int[] { 2, 3, 4 };\r
30                 \r
31                 if ( binding.compare(array1, array2) == 0 ) {\r
32                         System.out.println( "array1 is equal to array2" );\r
33                 } else {\r
34                         System.out.println( "array1 is not equal to array2" );\r
35                 }\r
36                 \r
37                 if ( binding.compare(array1, array3) == 0 ) {\r
38                         System.out.println( "array1 is equal to array3" );\r
39                 } else {\r
40                         System.out.println( "array1 is not equal to array3" );\r
41                 }\r
42                 \r
43                 \r
44                 \r
45                 \r
46                 \r
47                 // Two bindings can compare instances of same datatype, even if they are of\r
48                 // different classes            \r
49                 ArrayList<Integer> array4 = new ArrayList<Integer>();\r
50                 Binding binding2 = Bindings.getBindingUnchecked( ArrayList.class, Integer.class );\r
51                 array4.add( 1 );\r
52                 array4.add( 2 );\r
53                 array4.add( 3 );\r
54                 \r
55                 if ( Bindings.compare(binding, array1, binding2, array4) == 0 ) {\r
56                         System.out.println( "array1 is equal to array4" );\r
57                 } else {\r
58                         System.out.println( "array1 is not equal to array4" );\r
59                 }\r
60                 \r
61         }\r
62         \r
63 }\r