]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/examples/org/simantics/databoard/example/DeepClone.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / examples / org / simantics / databoard / example / DeepClone.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 org.simantics.databoard.Bindings;
15 import org.simantics.databoard.adapter.AdaptException;
16 import org.simantics.databoard.binding.Binding;
17 import org.simantics.databoard.binding.error.BindingConstructionException;
18 import org.simantics.databoard.binding.error.BindingException;
19
20 public class DeepClone {
21         
22         public static void main(String[] args) throws BindingConstructionException, BindingException, AdaptException {
23
24                 // Binding can copy objects. All copies are deep. 
25                 // Mutable objects are duplicated, immutable are referenced.
26                 
27                 // For instance, in object array, the array is copied, but its
28                 // immutable literal instances (e.g. 1) is referenced.
29                 
30                 Object[] original = new Object[] { new Object(), 1, "X", 123.456 };
31                 Binding binding = Bindings.getBinding( original.getClass() );
32                 Object[] copy = (Object[]) binding.cloneUnchecked( original );
33
34                 // Print the objects
35                 System.out.println( "Original: "+binding.toString( original ) );
36                 System.out.println( "Clone   : "+binding.toString( copy     ) );
37                 
38         }
39
40 }