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