X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fexamples%2Forg%2Fsimantics%2Fdataboard%2Fexample%2FDeepCompare.java;fp=bundles%2Forg.simantics.databoard%2Fexamples%2Forg%2Fsimantics%2Fdataboard%2Fexample%2FDeepCompare.java;h=2d0393be01e197d0c470b273d820c0efe3b1e710;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 index 000000000..2d0393be0 --- /dev/null +++ b/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/DeepCompare.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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.example; + +import java.util.ArrayList; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.error.BindingException; + +public class DeepCompare { + + public static void main(String[] args) throws BindingException { + + // Binding can compare any two instances. The compare function is deep. + Binding binding = Bindings.getBindingUnchecked( int[].class ); + + int[] array1 = new int[] { 1, 2, 3 }; + int[] array2 = new int[] { 1, 2, 3 }; + int[] array3 = new int[] { 2, 3, 4 }; + + if ( binding.compare(array1, array2) == 0 ) { + System.out.println( "array1 is equal to array2" ); + } else { + System.out.println( "array1 is not equal to array2" ); + } + + if ( binding.compare(array1, array3) == 0 ) { + System.out.println( "array1 is equal to array3" ); + } else { + System.out.println( "array1 is not equal to array3" ); + } + + + + + + // Two bindings can compare instances of same datatype, even if they are of + // different classes + ArrayList array4 = new ArrayList(); + Binding binding2 = Bindings.getBindingUnchecked( ArrayList.class, Integer.class ); + array4.add( 1 ); + array4.add( 2 ); + array4.add( 3 ); + + if ( Bindings.compare(binding, array1, binding2, array4) == 0 ) { + System.out.println( "array1 is equal to array4" ); + } else { + System.out.println( "array1 is not equal to array4" ); + } + + } + +}