1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.example;
\r
14 import java.util.ArrayList;
\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
20 public class DeepCompare {
\r
22 public static void main(String[] args) throws BindingException {
\r
24 // Binding can compare any two instances. The compare function is deep.
\r
25 Binding binding = Bindings.getBindingUnchecked( int[].class );
\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
31 if ( binding.compare(array1, array2) == 0 ) {
\r
32 System.out.println( "array1 is equal to array2" );
\r
34 System.out.println( "array1 is not equal to array2" );
\r
37 if ( binding.compare(array1, array3) == 0 ) {
\r
38 System.out.println( "array1 is equal to array3" );
\r
40 System.out.println( "array1 is not equal to array3" );
\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
55 if ( Bindings.compare(binding, array1, binding2, array4) == 0 ) {
\r
56 System.out.println( "array1 is equal to array4" );
\r
58 System.out.println( "array1 is not equal to array4" );
\r